def test_stop_in_the_middle(self): ''' test_generator_actors.test_stop_in_the_middle ''' test_name = 'test_generator_actors.test_stop_in_the_middle' logger = file_logger(test_name, filename='logs/%s.log' % test_name) actor = TestActor() actor.start() self.assertEqual(actor.processing, True) for _ in range(5): actor.run_once() actor.stop() result = [] while True: try: result.append(actor.inbox.get()) except EmptyInboxException: break self.assertGreater(len(result), 1) self.assertEqual(actor.run_once(), False) self.assertEqual(actor.processing, False) self.assertEqual(actor.waiting, False)
def test_run(self): ''' test_generator_actors.test_run ''' test_name = 'test_generator_actors.test_run' logger = file_logger(test_name, filename='logs/%s.log' % test_name) actor = TestActor() actor.start() self.assertEqual(actor.processing, True) actor.run() result = [] while True: try: result.append(actor.inbox.get()) except EmptyInboxException: break self.assertEqual(len(result), 10) self.assertEqual(actor.run_once(), False) self.assertEqual(actor.processing, False) self.assertEqual(actor.waiting, False)
def test_generator_and_greenlet(self): ''' test_actors_zoo.test_generator_and_greenlet ''' test_name = 'test_actors_zoo.test_generator_and_greenlet' logger = file_logger(test_name, filename='logs/%s.log' % test_name) parent = ActorGe(name='parent') parent.add_child(ActorGe(name='child-actor-ge-1')) parent.add_child(ActorGr(name='child-actor-gr-2')) parent.add_child(ActorGe(name='child-actor-ge-3')) parent.add_child(ActorGe(name='child-actor-ge-4')) parent.add_child(ActorGr(name='child-actor-gr-5')) parent.start() parent.run() parent.stop() result = [] while True: try: result.append(parent.inbox.get()) except EmptyInboxException: break self.assertEqual(len(result), 50)
def test_send_msg_between_threaded_actors(self): ''' test_threaded_actors.test_send_msg_between_threaded_actors ''' test_name = 'test_threaded_actors.test_send_msg_between_threaded_actors' logger = file_logger(test_name, filename='logs/%s.log' % test_name) parent = TestActor() parent.add_child(ThreadedSenderActor(name='Sender')) parent.add_child(ThreadedReceiverActor(name='Receiver')) parent.start() parent.run() parent.stop() self.assertEqual( [actor.message for actor in parent.find(actor_name='Receiver')], ['message from sender'] )