Skip to content

Commit a06ba12

Browse files
authored
use duration argument instead of time.sleep in tests (#622)
this avoids flakiness in tests due to high CPU usage on the test instance
1 parent 09c3129 commit a06ba12

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

tests/client/client_tests.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,10 @@ def test_transaction_max_spans_dynamic(elasticapm_client):
555555
@pytest.mark.parametrize("elasticapm_client", [{"span_frames_min_duration": 20}], indirect=True)
556556
def test_transaction_span_frames_min_duration(elasticapm_client):
557557
elasticapm_client.begin_transaction("test_type")
558-
with elasticapm.capture_span("noframes"):
559-
time.sleep(0.001)
560-
with elasticapm.capture_span("frames"):
561-
time.sleep(0.040)
558+
with elasticapm.capture_span("noframes", duration=0.001):
559+
pass
560+
with elasticapm.capture_span("frames", duration=0.04):
561+
pass
562562
elasticapm_client.end_transaction("test")
563563

564564
spans = elasticapm_client.events[SPAN]
@@ -576,8 +576,8 @@ def test_transaction_span_frames_min_duration_no_limit(elasticapm_client):
576576
elasticapm_client.begin_transaction("test_type")
577577
with elasticapm.capture_span("frames"):
578578
pass
579-
with elasticapm.capture_span("frames"):
580-
time.sleep(0.040)
579+
with elasticapm.capture_span("frames", duration=0.04):
580+
pass
581581
elasticapm_client.end_transaction("test")
582582

583583
spans = elasticapm_client.events[SPAN]

tests/instrumentation/transactions_store_tests.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,11 +187,11 @@ def test_leaf_tracing(tracer):
187187
with capture_span("child1-leaf", "custom", leaf=True):
188188

189189
# These two spans should not show up
190-
with capture_span("ignored-child1", "custom", leaf=True):
191-
time.sleep(0.01)
190+
with capture_span("ignored-child1", "custom", leaf=True, duration=0.01):
191+
pass
192192

193-
with capture_span("ignored-child2", "custom", leaf=False):
194-
time.sleep(0.01)
193+
with capture_span("ignored-child2", "custom", leaf=False, duration=0.01):
194+
pass
195195

196196
tracer.end_transaction(None, "transaction")
197197

0 commit comments

Comments
 (0)