Ejemplo n.º 1
0
def test_InfiniteProcess__pause_and_resume_work_while_running():
    test_queue = SimpleMultiprocessingQueue()
    error_queue = multiprocessing.Queue()
    p = InfiniteProcessThatPopulatesQueue(test_queue, error_queue)
    p.start()
    seconds_to_sleep_while_queue_populating = 2  # Eli (12/14/20): in GitHub Windows containers, 0.05 seconds was too short, so just bumping up to 1 second # Tanner (1/31/21): bumping to 2 seconds after another CI issue
    time.sleep(
        seconds_to_sleep_while_queue_populating)  # let the queue populate
    p.pause()
    items_in_queue_at_pause = []
    while test_queue.empty() is False:
        items_in_queue_at_pause.append(test_queue.get())
        time.sleep(
            SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE
        )  # don't relentlessly poll the queue # Eli (2/10/21): There was an odd hanging that occurred once during CI in a windows container...possibly due to relentlessly checking empty/get of the queue(?) https://github.com/CuriBio/stdlib-utils/pull/87/checks?check_run_id=1856410303

    assert len(items_in_queue_at_pause) > 0
    last_item_in_queue_at_pause = items_in_queue_at_pause[-1]

    time.sleep(seconds_to_sleep_while_queue_populating
               )  # give the queue time to populate if pause was unsuccessful
    assert test_queue.empty() is True

    p.resume()
    time.sleep(seconds_to_sleep_while_queue_populating
               )  # give the queue time to populate
    hard_stop_results = p.hard_stop()
    p.join()

    assert len(hard_stop_results["fatal_error_reporter"]) == 0

    items_in_queue_at_stop = []
    while test_queue.empty() is False:
        items_in_queue_at_stop.append(test_queue.get())
        time.sleep(
            SECONDS_TO_SLEEP_BETWEEN_CHECKING_QUEUE_SIZE
        )  # don't relentlessly poll the queue # Eli (2/10/21): There was an odd hanging that occurred once during CI in a windows container...possibly due to relentlessly checking empty/get of the queue(?) https://github.com/CuriBio/stdlib-utils/pull/87/checks?check_run_id=1856410303

    assert len(items_in_queue_at_stop) > 0
    assert items_in_queue_at_stop[0] - 1 == last_item_in_queue_at_pause
Ejemplo n.º 2
0
def test_InfiniteProcess__queue_is_populated_with_error_occuring_during_run__and_stop_is_called(
    mocker, ):
    expected_error = ValueError("test message")
    error_queue = SimpleMultiprocessingQueue()
    p = InfiniteProcessThatRaisesError(error_queue)
    mocker.patch("builtins.print",
                 autospec=True)  # don't print the error message to stdout
    spied_stop = mocker.spy(p, "stop")

    p.run()
    assert error_queue.empty() is False
    assert spied_stop.call_count == 1
    actual_error, _ = error_queue.get()
    assert isinstance(actual_error, type(expected_error))
    assert str(actual_error) == str(expected_error)
Ejemplo n.º 3
0
def test_InfiniteProcess__queue_is_populated_with_error_occuring_during_live_spawned_run(
    mocker, ):
    # spied_print_exception = mocker.spy(
    #     parallelism_framework, "print_exception"
    # )  # Eli (3/13/20) can't figure out why this isn't working (call count never gets to 1), so just asserting about print instead
    mocker.patch("builtins.print",
                 autospec=True)  # don't print the error message to stdout
    expected_error = ValueError("test message")
    error_queue = SimpleMultiprocessingQueue()
    p = InfiniteProcessThatRaisesError(error_queue)
    p.start()
    p.join()
    assert error_queue.empty() is False
    actual_error, actual_stack_trace = error_queue.get()
    # assert spied_print_exception.call_count == 1
    # assert mocked_print.call_count==1

    assert isinstance(actual_error, type(expected_error))
    assert str(actual_error) == str(expected_error)
    assert p.exitcode == 0  # When errors are handled, the error code is 0
    # assert actual_error == expected_error # Eli (12/24/19): for some reason this asserting doesn't pass...not sure why....so testing class type and str instead
    assert 'raise ValueError("test message")' in actual_stack_trace