def test_execute_async(self): """Make sure this actor starts all processes in parallel!""" check_order = [] actor_1 = { 'actor': 'kingpin.actors.test.test_group.TestActorPopulate', 'desc': 'test', 'options': { 'object': ['fake'], 'value': 1 } } actor_2 = { 'actor': 'kingpin.actors.test.test_group.TestActorPopulate', 'desc': 'test', 'options': { 'object': ['fake'], 'value': 2 } } actor = group.Async('Unit Test Action', {'acts': [actor_1, actor_2]}) # The options above were copied by value # This test requires same object to be modified so we set it directly actor._actions[0]._options['object'] = check_order actor._actions[1]._options['object'] = check_order yield actor.execute() # if the actions above were executed sequentially then the resulting # list would be [1,1,2,2] and here we know it's hopping between actors self.assertEquals(check_order, [1, 2, 1, 2])
def test_run_actions_with_one_act(self): # Call the executor and test it out actor = group.Async('Unit Test Action', {'acts': [dict(self.actor_returns)]}) res = yield actor._run_actions() self.assertEquals(res, None)
def test_get_exc_type_with_both(self): exc_list = [ exceptions.RecoverableActorFailure(), exceptions.UnrecoverableActorFailure(), exceptions.RecoverableActorFailure() ] actor = group.Async('Unit Test Action', {'acts': []}) ret = actor._get_exc_type(exc_list) self.assertEquals(ret, exceptions.UnrecoverableActorFailure)
def test_run_actions_with_two_acts_one_fails_with_both(self): # Call the executor and test it out actor = group.Async( 'Unit Test Action', { 'acts': [ dict(self.actor_returns), dict(self.actor_raises_recoverable_exception), dict(self.actor_raises_unrecoverable_exception) ] }) with self.assertRaises(exceptions.UnrecoverableActorFailure): yield actor._run_actions()
def test_run_actions_with_two_acts_one_fails_unrecoverable(self): # Call the executor and test it out self.actor_returns['options']['value'] = '123' actor = group.Async( 'Unit Test Action', { 'acts': [ dict(self.actor_raises_unrecoverable_exception), dict(self.actor_returns), ] }) with self.assertRaises(exceptions.UnrecoverableActorFailure): yield actor._run_actions() # If the second actor does not get executed this value would be None self.assertEquals(TestActor.last_value, '123')
def test_execute_concurrent(self): sleeper = { 'actor': 'misc.Sleep', 'desc': 'Sleep', 'options': { 'sleep': 0.1 } } actor = group.Async('Unit Test Action', { 'concurrency': 2, 'acts': [sleeper, sleeper, sleeper, sleeper] }) start = time.time() yield actor.execute() stop = time.time() exe_time = stop - start self.assertTrue(0.2 < exe_time < 0.4)
def test_run_actions_with_no_acts(self): # Call the executor and test it out actor = group.Async('Unit Test Action', {'acts': []}) res = yield actor._run_actions() self.assertEqual(res, None)