def test_has_no_completed_task(): all_actions = [ WaitForExternalEventAction("C"), WaitForExternalEventAction("A"), WaitForExternalEventAction("B") ] task1 = Task(is_completed=False, is_faulted=False, action=all_actions[0], timestamp=date(2000, 1, 1)) task2 = Task(is_completed=False, is_faulted=False, action=all_actions[1], timestamp=date(2000, 2, 1)) task3 = Task(is_completed=False, is_faulted=False, action=all_actions[2], timestamp=date(2000, 1, 1)) tasks = [task1, task2, task3] returned_taskset = task_any(tasks) expected_taskset = TaskSet(is_completed=False, actions=all_actions, result=None) assert_taskset_equal(expected_taskset, returned_taskset)
def test_all_faulted_task_should_fail(): all_actions = [ WaitForExternalEventAction("C"), WaitForExternalEventAction("A"), WaitForExternalEventAction("B") ] task1 = Task(is_completed=False, is_faulted=True, action=all_actions[0], timestamp=date(2000, 1, 1), exc=Exception("test failure")) task2 = Task(is_completed=False, is_faulted=True, action=all_actions[1], timestamp=date(2000, 2, 1), exc=Exception("test failure")) task3 = Task(is_completed=False, is_faulted=True, action=all_actions[2], timestamp=date(2000, 1, 1), exc=Exception("test failure")) tasks = [task1, task2, task3] returned_taskset = task_any(tasks) error_messages = [Exception("test failure") for _ in range(3)] expected_exception = Exception( f"All tasks have failed, errors messages in all tasks:{error_messages}" ) expected_taskset = TaskSet(is_completed=True, actions=all_actions, result=None, is_faulted=True, exception=expected_exception) assert_taskset_equal(expected_taskset, returned_taskset)
def test_event_not_raised_return_incompleted_task(): context_builder = ContextBuilder('test_simple_function') expected_action = WaitForExternalEventAction("A") returned_task = wait_for_external_event_task( context_builder.history_events, "A") expected_task = Task(is_completed=False, is_faulted=False, action=expected_action) assert_tasks_equal(expected_task, returned_task)
def test_taskset_and_tasks_as_args(): all_actions = [ WaitForExternalEventAction("C"), WaitForExternalEventAction("A"), WaitForExternalEventAction("B") ] task1 = Task(is_completed=False, is_faulted=True, action=all_actions[0], timestamp=date(2000, 1, 1)) task2 = TaskSet(is_completed=True, is_faulted=False, actions=[all_actions[1], all_actions[2]], \ result=[None, None], timestamp=date(2000,1,1)) tasks = [task1, task2] returned_taskset = task_any(tasks) expected_taskset = TaskSet(is_completed=True, actions=all_actions, result=task2, timestamp=date(2000, 1, 1)) assert_taskset_equal(expected_taskset, returned_taskset)
def test_event_raised_return_completed_task(): timestamp = datetime.now() json_input = '{"test":"somecontent"}' expected_action = WaitForExternalEventAction("A") context_builder = ContextBuilder('test_simple_function') context_builder.add_event_raised_event(name="A", input_=json_input, timestamp=timestamp, id_=1) returned_task = wait_for_external_event_task( context_builder.history_events, "A") expected_task = Task(is_completed=True, is_faulted=False, action=expected_action, result=json.loads(json_input), timestamp=timestamp.replace(tzinfo=tzutc()), id_=1) assert_tasks_equal(expected_task, returned_task)