-
-
Notifications
You must be signed in to change notification settings - Fork 719
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
370f456
commit 1ff857e
Showing
3 changed files
with
28 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,20 @@ | ||
import time | ||
|
||
import pytest | ||
|
||
from distributed import metrics | ||
|
||
|
||
def test_wall_clock(): | ||
@pytest.mark.parametrize("name", ["time", "monotonic"]) | ||
def test_wall_clock(name): | ||
for i in range(3): | ||
time.sleep(0.01) | ||
t = time.time() | ||
samples = [metrics.time() for j in range(50)] | ||
t = getattr(time, name)() | ||
samples = [getattr(metrics, name)() for _ in range(100)] | ||
# Resolution | ||
deltas = [samples[j + 1] - samples[j] for j in range(len(samples) - 1)] | ||
deltas = [sj - si for si, sj in zip(samples[:-1], samples[1:])] | ||
assert min(deltas) >= 0.0, deltas | ||
assert max(deltas) <= 1.0, deltas | ||
assert any(lambda d: 0.0 < d < 0.0001 for d in deltas), deltas | ||
# Close to time.time() | ||
assert max(deltas) <= 0.001, deltas | ||
assert any(0.0 < d < 0.0001 for d in deltas), deltas | ||
# Close to time.time() / time.monotonic() | ||
assert t - 0.5 < samples[0] < t + 0.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters