Skip to content

Commit

Permalink
fix order of magnitude measuring error 🤦
Browse files Browse the repository at this point in the history
  • Loading branch information
bloodearnest committed Nov 9, 2022
1 parent 2379371 commit e1dcf50
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
2 changes: 1 addition & 1 deletion jobrunner/record_stats.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ def record_tick_trace(last_run):
Not that this will emit number of active jobs + 1 events every call, so we
don't want to call it on too tight a loop.
"""
now = int(time.time() * 10e9)
now = time.time_ns()

if last_run is None:
return now
Expand Down
11 changes: 5 additions & 6 deletions tests/test_record_stats.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import time

from jobrunner import record_stats
from jobrunner.models import State, StatusCode
from tests.conftest import get_trace
from tests.factories import job_factory


def test_record_tick_trace(db):
def test_record_tick_trace(db, freezer):

jobs = []
jobs.append(job_factory(status_code=StatusCode.CREATED))
Expand All @@ -21,16 +19,17 @@ def test_record_tick_trace(db):
last_run1 = record_stats.record_tick_trace(None)
assert len(get_trace()) == 0

time.sleep(0.1)
freezer.tick(10)

last_run2 = record_stats.record_tick_trace(last_run1)
assert last_run2 > last_run1
assert last_run2 == last_run1 + 10 * 1e9

spans = get_trace()

root = spans[-1]
assert root.name == "TICK"
assert root.start_time == last_run1
assert root.end_time >= last_run2
assert root.end_time == last_run2

for job, span in zip(jobs, spans):
assert span.name == job.status_code.name
Expand Down

0 comments on commit e1dcf50

Please sign in to comment.