This commit is contained in:
Perry McManis 2022-08-09 08:51:47 -04:00
Родитель cf8e5f91aa
Коммит 58c5a27a82
1 изменённых файлов: 10 добавлений и 3 удалений

Просмотреть файл

@ -162,13 +162,20 @@ def test_measure():
)
with metric.measure():
time.sleep(0.1)
iteration_guard = 10**8 # this guard should be
# about 100 times as long as the loop
iterations = 0
end_time = time.perf_counter() + 0.1
while time.perf_counter() < end_time:
if iterations > iteration_guard:
raise Exception("Loop to accrue time exceeded guard")
iterations += 1
snapshot = metric.test_get_value()
# more than 0.1s = 100ms = 10^8 nanoseconds
# less than 0.2s = 200ms = 2*10^8 nanoseconds
assert 10**8 < snapshot.sum
assert 2 * 10**8 > snapshot.sum
assert snapshot.sum > 10**8, "Measured value below minimum time"
assert snapshot.sum < 2 * 10**8, "Measured value above maximum time"
def test_measure_exception():