Skip to content

Commit

Permalink
test: Made the test_sync_timer test faster by using time_machine (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
edgarrmondragon authored Mar 4, 2024
1 parent 5d43b42 commit 4126ccf
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions tests/core/test_metrics.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from __future__ import annotations

import logging
import time

import pytest
import time_machine

from singer_sdk import metrics

Expand Down Expand Up @@ -79,13 +79,16 @@ def test_record_counter(caplog: pytest.LogCaptureFixture):

def test_sync_timer(caplog: pytest.LogCaptureFixture):
caplog.set_level(logging.INFO, logger=metrics.METRICS_LOGGER_NAME)
with metrics.sync_timer("test_stream", custom_tag="pytest") as timer:
start_time = timer.start_time
for _ in range(1000):
time.sleep(0.001)
end_time = time.time()
traveler = time_machine.travel(0, tick=False)
traveler.start()

assert len(caplog.records) == 1
with metrics.sync_timer("test_stream", custom_tag="pytest"):
traveler.stop()

traveler = time_machine.travel(10, tick=False)
traveler.start()

traveler.stop()

record = caplog.records[0]
assert record.levelname == "INFO"
Expand All @@ -100,4 +103,4 @@ def test_sync_timer(caplog: pytest.LogCaptureFixture):
"custom_tag": "pytest",
}

assert pytest.approx(point.value, rel=0.001) == end_time - start_time
assert pytest.approx(point.value, rel=0.001) == 10.0

0 comments on commit 4126ccf

Please sign in to comment.