From b86f3be51006e395c644026cb31fc98acb57b0a8 Mon Sep 17 00:00:00 2001 From: Jan Bouwhuis Date: Fri, 3 Nov 2023 02:00:34 +0100 Subject: [PATCH] Optmize timing excecutor timeout test (#103276) --- tests/util/test_executor.py | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/tests/util/test_executor.py b/tests/util/test_executor.py index 763efa494e7..076864c65c4 100644 --- a/tests/util/test_executor.py +++ b/tests/util/test_executor.py @@ -77,19 +77,17 @@ async def test_executor_shutdown_does_not_log_shutdown_on_first_attempt( async def test_overall_timeout_reached(caplog: pytest.LogCaptureFixture) -> None: """Test that shutdown moves on when the overall timeout is reached.""" - iexecutor = InterruptibleThreadPoolExecutor() - def _loop_sleep_in_executor(): time.sleep(1) - for _ in range(6): - iexecutor.submit(_loop_sleep_in_executor) - - start = time.monotonic() with patch.object(executor, "EXECUTOR_SHUTDOWN_TIMEOUT", 0.5): + iexecutor = InterruptibleThreadPoolExecutor() + for _ in range(6): + iexecutor.submit(_loop_sleep_in_executor) + start = time.monotonic() iexecutor.shutdown() - finish = time.monotonic() + finish = time.monotonic() - assert finish - start < 1.2 + assert finish - start < 1.3 iexecutor.shutdown()