diff --git a/metadata-ingestion/tests/unit/utilities/test_perf_timer.py b/metadata-ingestion/tests/unit/utilities/test_perf_timer.py index 6129b3e37d8bc..1de76a32fb708 100644 --- a/metadata-ingestion/tests/unit/utilities/test_perf_timer.py +++ b/metadata-ingestion/tests/unit/utilities/test_perf_timer.py @@ -10,37 +10,39 @@ def test_perf_timer_simple(): with PerfTimer() as timer: - time.sleep(1) - assert approx(timer.elapsed_seconds()) == 1 + time.sleep(0.4) + assert approx(timer.elapsed_seconds()) == 0.4 - assert approx(timer.elapsed_seconds()) == 1 + assert approx(timer.elapsed_seconds()) == 0.4 def test_perf_timer_paused_timer(): with PerfTimer() as current_timer: - time.sleep(1) - assert approx(current_timer.elapsed_seconds()) == 1 + time.sleep(0.5) + assert approx(current_timer.elapsed_seconds()) == 0.5 with current_timer.pause(): - time.sleep(2) - assert approx(current_timer.elapsed_seconds()) == 1 - assert approx(current_timer.elapsed_seconds()) == 1 - time.sleep(1) + time.sleep(0.3) + assert approx(current_timer.elapsed_seconds()) == 0.5 + assert approx(current_timer.elapsed_seconds()) == 0.5 + time.sleep(0.2) - assert approx(current_timer.elapsed_seconds()) == 2 + assert approx(current_timer.elapsed_seconds()) == 0.7 def test_generator_with_paused_timer(): + n = 4 + def generator_function(): with PerfTimer() as inner_timer: time.sleep(1) - for i in range(10): + for i in range(n): time.sleep(0.2) with inner_timer.pause(): time.sleep(0.2) yield i - assert approx(inner_timer.elapsed_seconds()) == 1 + 0.2 * 10 + assert approx(inner_timer.elapsed_seconds()) == 1 + 0.2 * n with PerfTimer() as outer_timer: seq = generator_function() list([i for i in seq]) - assert approx(outer_timer.elapsed_seconds()) == 1 + 0.2 * 10 + 0.2 * 10 + assert approx(outer_timer.elapsed_seconds()) == 1 + 0.2 * n + 0.2 * n