Esempio n. 1
0
 def test_setting_nofile_limit_os_fail(self, mock_setrlimit, *unused_mocks):
     """Assert that setting a rlimit greater than allow is handled well."""
     mock_setrlimit.side_effect = resource.error('No files for you')
     hub_command = HubCommand()
     hub_command.log = mock.Mock()
     hub_command.set_rlimit_nofiles(limit=1844674407370)
     hub_command.log.warning.assert_called_once()
Esempio n. 2
0
 def setUp(self):
     self.config = load_config()
     self.config['name'] = local_name
     self.config['mute'] = True
     self.config['persistent_store'] = mock.Mock()
     self.replay_context = ReplayContext(**self.config)
     self.replay_thread = ReplayThread(self.replay_context)
     self.context = zmq.Context()
Esempio n. 3
0
 def setUp(self):
     self.config = load_config()
     self.config['name'] = local_name
     self.config['persistent_store'] = mock.Mock()
     self.replay_context = ReplayContext(**self.config)
     self.request_context = zmq.Context()
     self.request_socket = self.request_context.socket(zmq.REQ)
     self.request_socket.connect(
         self.config['replay_endpoints'][local_name])
Esempio n. 4
0
 def test_get_replay_wrong_query(self):
     # We don't actually test with a wrong query, we just throw back an
     # error from the store.
     self.config['persistent_store'].get = mock.Mock(
         side_effect=[ValueError("this is an error")])
     self.replay_thread.start()
     list(
         get_replay(local_name, {"seq_ids": [1, 2]}, self.config,
                    self.context))
Esempio n. 5
0
def test_init_invalid_endpoint():
    try:
        config = load_config()
        config['name'] = local_name
        config['persistent_store'] = mock.Mock()
        tmp = zmq.Context()
        placeholder = tmp.socket(zmq.REP)
        placeholder.bind('tcp://*:{0}'.format(
            config["replay_endpoints"][local_name].rsplit(':')[-1]))
        ReplayContext(**config)
    finally:
        placeholder.close()
Esempio n. 6
0
    def test_get_error(self):
        # Setup the store to return what we ask.
        answer = ValueError('No luck!')
        self.config['persistent_store'].get = mock.Mock(side_effect=[answer])
        # Doesn't matter what we send as long as it is legit JSON,
        # since the store is mocked
        self.request_socket.send(u'{"id": 1}'.encode('utf-8'))
        self.replay_context._req_rep_cycle()

        rep = self.request_socket.recv_multipart()
        print(rep)

        assert len(rep) == 1 and "error: 'No luck!'" == rep[0].decode('utf-8')
Esempio n. 7
0
    def test_get_replay(self):
        # Setup the store to return what we ask.
        answer = [{'foo': 'bar'}]
        self.config['persistent_store'].get = mock.Mock(side_effect=[answer])
        # Doesn't matter what we send as long as it is legit JSON,
        # since the store is mocked
        self.request_socket.send(u'{"id": 1}'.encode('utf-8'))
        self.replay_context._req_rep_cycle()

        rep = self.request_socket.recv_multipart()
        print(rep)
        print(answer)

        assert len(answer) == len(rep)
        for r, a in zip(rep, answer):
            self.assertDictEqual(json.loads(r.decode('utf-8')), a)
Esempio n. 8
0
 def test_get_replay(self):
     # As before, the correctness of the query doesn't matter much
     # since it is taken care of on the server side.
     orig_msg = {
         "i": 2,
         "seq_id": 3,
         "topic": "org.foo.bar",
         "msg_id": "33333333-3333-3333-3333-333333333333",
         "timestamp": 20,
         "msg": {
             "foo": "foo"
         }
     }
     self.config['persistent_store'].get = mock.Mock(
         side_effect=[[orig_msg]])
     self.replay_thread.start()
     msgs = list(
         get_replay(local_name, {"seq_id": 3}, self.config, self.context))
     assert len(msgs) == 1
     self.assertDictEqual(msgs[0], orig_msg)
Esempio n. 9
0
    def test_send_message(self):
        """send_message is deprecated

        It tests
        - deprecation warning showing up appropriately
        - that we call publish method behind the scene
        """
        fake_topic = "org.fedoraproject.prod.compose.rawhide.complete"
        fake_msg = "{'arch'': 's390', 'branch': 'rawhide', 'log': 'done'}"
        self.ctx.publish = mock.Mock(spec_set=FedMsgContext.publish)
        with warnings.catch_warnings(record=True) as w:
            warnings.simplefilter("always")
            self.ctx.send_message(topic=fake_topic, msg=fake_msg)
            assert len(w) == 1
            assert str(w[0].message) == ".send_message is deprecated."
            assert self.ctx.publish.called
            topic, msg, modname = self.ctx.publish.call_args[0]
            assert topic == fake_topic
            assert msg == fake_msg
            assert modname is None
Esempio n. 10
0
def test_init_missing_endpoint():
    """ Try to initialize the context with a nonexistant service name. """
    config = load_config()
    config['persistent_store'] = mock.Mock()
    config['name'] = "failboat"
    ReplayContext(**config)