Example #1
0
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)
Example #2
0
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)
Example #3
0
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)