class TestWithRabbit(common.SimulationTest): timeout = 20 @defer.inlineCallbacks def setUp(self): # run rabbitmq yield self.run_rabbit() # get connection faking the web team listening self.server = messaging.Messaging('127.0.0.1', self.rabbit.get_config()['port']) self.web = StubAgent() self.connection = yield self.server.new_channel(self.web) pb = self.connection.bind(self.web.get_agent_id(), 'exchange') yield pb.wait_created() # setup our agent yield common.SimulationTest.setUp(self) @defer.inlineCallbacks def prolog(self): setup = format_block(""" spawn_agency('feat.agents.base.amqp.interface.IAMQPClientFactory') agency = _ agency.disable_protocol('setup-monitoring', 'Task') descriptor_factory('test-agent') agency.start_agent(_, host='127.0.0.1', port=%(port)s, \ exchange=%(exchange)s, \ exchange_type=%(type)s) """) % dict(port=self.rabbit.get_config()['port'], exchange="'exchange'", type="'direct'") yield self.process(setup) self.agent = list(self.driver.iter_agents())[0] @defer.inlineCallbacks def tearDown(self): yield self.agent.terminate() yield self.wait_for_idle(10) yield self.server.disconnect() yield self.rabbit.terminate() yield common.SimulationTest.tearDown(self) @defer.inlineCallbacks def testWebGetsMessage(self): cb = self.cb_after(None, self.web, 'on_message') yield self.agent.get_agent().push_msg(message.BaseMessage(), self.web.get_agent_id()) yield cb self.assertIsInstance(self.web.messages[0], message.BaseMessage) @defer.inlineCallbacks def run_rabbit(self): try: self.rabbit = rabbitmq.Process(self) except DependencyError as e: raise SkipTest(str(e)) yield self.rabbit.restart()
def testCreatingBindingsOnReadyConnection(self): ''' Checks that creating personal binding after the connection has been initialized works the same as during initialization time. ''' agent = StubAgent() self.agents = [agent] channel = self.messaging.new_channel(agent, agent.get_agent_id()) yield channel.initiate() # wait for connection to be established client = yield channel._client.factory.add_connection_made_cb() self.assertIsInstance(client, net.MessagingClient) binding = channel.bind(agent.get_shard_id(), agent.get_agent_id()) yield binding.wait_created() d = self.cb_after(None, agent, 'on_message') channel.post(self._agent(0), m('something')) yield d self.assertEqual(1, len(agent.messages))