Esempio n. 1
0
    def test_connection_publish(self):
        flexmock(self.mock_connect).should_receive("close").twice()
        flexmock(self.mock_connect).should_receive("connect").twice()
        flexmock(self.mock_connect).should_receive("ensure_connection").twice()
        flexmock(self.mock_connect).should_receive("channel").twice()
        flexmock(self.mock_consumer).should_receive("consume").once()

        _lock = gevent.lock.Semaphore()
        _lock.acquire()
        def _drain_events():
            gevent.sleep(1000)
            return

        req_id = []
        def _publish(args):
            req_id.append(args['request-id'])
            if _lock.locked():
                _lock.release()
                raise Exception()
            return

        flexmock(self.mock_connect).should_receive("drain_events").replace_with(_drain_events).once()
        flexmock(self.mock_producer).should_receive("publish").replace_with(_publish).twice()
        servers = "a.a.a.a"
        kc = VncServerKombuClient(self.db_client_mgr, servers, self.port,
                                  self.username, self.password, self.vhost, 0,
                                  'x.x.x.x', False)
        gevent.sleep(0)
        kc.dbe_publish('CREATE', 'virtual_network', ['vn1'], {})
        _lock.wait()

        # check if message is not missed out by publish error
        self.assertEqual(len(req_id), 2)
        self.assertEqual(len(set(req_id)), 1)
    def test_connection_publish(self):
        flexmock(self.mock_connect).should_receive("close").twice()
        flexmock(self.mock_connect).should_receive("connect").twice()
        flexmock(self.mock_connect).should_receive("ensure_connection").twice()
        flexmock(self.mock_connect).should_receive("channel").twice()
        flexmock(self.db_client_mgr).should_receive("wait_for_resync_done"). \
            with_args().once()
        flexmock(self.mock_consumer).should_receive("consume").once()

        _lock = gevent.lock.Semaphore()
        _lock.acquire()

        def _drain_events():
            gevent.sleep(1000)
            return

        req_id = []

        def _publish(args):
            req_id.append(args['request-id'])
            if _lock.locked():
                _lock.release()
                raise Exception()
            return

        flexmock(self.mock_connect).should_receive(
            "drain_events").replace_with(_drain_events).once()
        flexmock(self.mock_producer).should_receive("publish").replace_with(
            _publish).twice()
        servers = "a.a.a.a"
        kc = VncServerKombuClient(self.db_client_mgr, servers, self.port,
                                  self.username, self.password, self.vhost, 0,
                                  False)
        gevent.sleep(0)
        kc.dbe_publish('CREATE', 'virtual_network', ['vn1'], {})
        _lock.wait()

        # check if message is not missed out by publish error
        self.assertEqual(len(req_id), 2)
        self.assertEqual(len(set(req_id)), 1)