forked from p34709852/monkey
UT: Use time.per_counter_ns() in test_request_cache()
The time.time() function on windows does not provide adequate resolution for test_request_cache(). For comparison, the time.get_clock_info() function shows the resolution of the clock. Linux: >>> import time >>> time.get_clock_info("time") namespace( adjustable=True, implementation='clock_gettime(CLOCK_REALTIME)', monotonic=False, resolution=1e-09 ) >>> time.get_clock_info("perf_counter") namespace( adjustable=False, implementation='clock_gettime(CLOCK_MONOTONIC)', monotonic=True, resolution=1e-09 ) Windows: >>> time.get_clock_info("time") namespace( adjustable=True, implementation='GetSystemTimeAsFileTime()', monotonic=False, resolution=0.015625 ) >>> time.get_clock_info("perf_counter") namespace( adjustable=False, implementation='QueryPerformanceCounter()', monotonic=True, resolution=1e-07 ) As shown above, the "perf_counter" clock on Windows if over 5 orders of magnitude more precise than the "time" clock. This lack of precision caused the test to fail on Windows, as the entire test often ran in less than 0.015625 seconds.
This commit is contained in:
parent
3fee7dec90
commit
1e12a55240
|
@ -58,7 +58,7 @@ def mock_timer(monkeypatch):
|
|||
|
||||
|
||||
def test_request_cache(mock_timer):
|
||||
mock_request = MagicMock(side_effect=lambda: time.time())
|
||||
mock_request = MagicMock(side_effect=lambda: time.perf_counter_ns())
|
||||
|
||||
@request_cache(10)
|
||||
def make_request():
|
||||
|
|
Loading…
Reference in New Issue