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:
Mike Salvatore 2022-02-23 07:38:26 -05:00
parent 3fee7dec90
commit 1e12a55240
1 changed files with 1 additions and 1 deletions

View File

@ -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():