def test_is_queue_eventually_not_empty__returns_true_after_multiple_attempts_with_eventually_not_empty_threading_queue( mocker, ): q = queue.Queue() mocked_empty = mocker.patch.object(q, "empty", autospec=True, side_effect=[True, True, True, False]) assert is_queue_eventually_not_empty(q) is True assert mocked_empty.call_count == 4
def test_is_queue_eventually_not_empty__returns_true_with_not_empty_threading_queue__after_just_one_call( mocker, ): q = queue.Queue() q.put("bob") spied_empty = mocker.spy(q, "empty") time.sleep(0.1) # just to be safe make sure thread is definitely populated assert is_queue_eventually_not_empty(q) is True assert spied_empty.call_count == 1
def test_is_queue_eventually_not_empty__returns_false_with_empty_threading_queue( mocker, ): q = queue.Queue() spied_empty = mocker.spy(q, "empty") assert ( is_queue_eventually_not_empty(q, timeout_seconds=SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE * 3) is False ) assert spied_empty.call_count > 2
def test_is_queue_eventually_not_empty__returns_false_with_empty_threading_queue__after_kwarg_timeout_is_met( mocker, ): q = queue.Queue() spied_empty = mocker.spy(q, "empty") 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, ], ) assert is_queue_eventually_not_empty(q, timeout_seconds=0.25) is False assert spied_empty.call_count == 3
def side_effect(*args, **kwargs): assert is_queue_eventually_not_empty(error_queue) is True return False
def test_is_queue_eventually_not_empty__returns_true_with_not_empty_multiprocessing_queue(): q = multiprocessing.Queue() q.put("bill") time.sleep(0.1) # just to be safe make sure thread is definitely populated assert is_queue_eventually_not_empty(q) is True