Esempio n. 1
0
def test_is_queue_eventually_empty__returns_true_after_multiple_attempts_with_eventually_empty_threading_queue(
    mocker,
):
    q = queue.Queue()
    mocked_empty = mocker.patch.object(q, "empty", autospec=True, side_effect=[False, False, False, True])
    assert is_queue_eventually_empty(q) is True
    assert mocked_empty.call_count == 4
Esempio n. 2
0
def test_is_queue_eventually_empty__returns_true_with_empty_multiprocessing_queue__after_just_one_call(
    mocker,
):
    q = multiprocessing.Queue()
    spied_empty = mocker.spy(q, "empty")
    assert is_queue_eventually_empty(q) is True
    assert spied_empty.call_count == 1
Esempio n. 3
0
def test_is_queue_eventually_empty__returns_false_with_not_empty_threading_queue(
    mocker,
):
    q = queue.Queue()
    mocked_empty = mocker.patch.object(q, "empty", autospec=True, return_value=False)
    assert (
        is_queue_eventually_empty(q, timeout_seconds=SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE * 6)
        is False
    )
    assert mocked_empty.call_count > 5
Esempio n. 4
0
def test_InfiniteLoopingParallelismMixIn__hard_stop__waits_for_teardown_complete_event_to_drain_error_queue(
    mocker, ):
    expected_error = "dummy_error"

    p = generic_infinite_looper()
    error_queue = p.get_fatal_error_reporter()
    error_queue.put(expected_error)

    def side_effect(*args, **kwargs):
        assert is_queue_eventually_not_empty(error_queue) is True
        return True

    mocker.patch.object(p,
                        "is_teardown_complete",
                        autospec=True,
                        side_effect=side_effect)

    actual = p.hard_stop()
    assert actual["fatal_error_reporter"] == [expected_error]
    assert is_queue_eventually_empty(error_queue) is True
Esempio n. 5
0
def test_is_queue_eventually_empty__returns_false_with_not_empty_threading_queue__after_kwarg_timeout_is_met(
    mocker,
):
    q = queue.Queue()
    mocked_empty = mocker.patch.object(q, "empty", autospec=True, return_value=False)
    mocker.patch.object(
        queue_utils,
        "process_time",
        autospec=True,
        side_effect=[
            0,
            0.1,
            0.15 - SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE * 1,
            0.2 - SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE * 2,
            0.3 - SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE * 3,
            0.35 - SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE * 4,
            0.4 - SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE * 5,
        ],
    )
    assert is_queue_eventually_empty(q, timeout_seconds=0.36) is False
    assert mocked_empty.call_count == 5
Esempio n. 6
0
def test_is_queue_eventually_empty__returns_true_with_empty_threading_queue():
    q = queue.Queue()
    assert is_queue_eventually_empty(q) is True