Skip to content

Commit 5586e87

Browse files
authored
Attempt to fix test_urls_excluded_from_sampling (#158)
`test_urls_excluded_from_sampling` keeps failing on PR, causing annoying delays. I suspect that the problem is a race condition - we are exporting a span then grabbing it, and I believe that the delay between export and being "grabbable" is causing the test to fail (typically with `1 != 2`). As an attempted fix, I'm adding some retry logic that will attempt to grab for a full second. By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent ea32126 commit 5586e87

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

aws-opentelemetry-distro/tests/amazon/opentelemetry/distro/sampler/test_aws_xray_sampling_client.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import json
44
import logging
55
import os
6+
import time
67
from importlib import reload
78
from logging import getLogger
89
from unittest import TestCase
@@ -186,7 +187,11 @@ def test_urls_excluded_from_sampling(self):
186187
except requests.exceptions.RequestException:
187188
pass
188189

190+
timeout = time.time() + 1
189191
span_list = memory_exporter.get_finished_spans()
192+
while len(span_list) != 1 and timeout > time.time():
193+
span_list = memory_exporter.get_finished_spans()
194+
time.sleep(0.1)
190195
self.assertEqual(1, len(span_list))
191196
span_http_url = span_list[0].attributes.get("http.url")
192197
self.assertEqual(span_http_url, "http://this_is_a_fake_url:3849/GetSamplingRules")
@@ -196,7 +201,11 @@ def test_urls_excluded_from_sampling(self):
196201
except requests.exceptions.RequestException:
197202
pass
198203

204+
timeout = time.time() + 1
199205
span_list = memory_exporter.get_finished_spans()
206+
while len(span_list) != 2 and timeout > time.time():
207+
span_list = memory_exporter.get_finished_spans()
208+
time.sleep(0.1)
200209
self.assertEqual(2, len(span_list))
201210
span_http_url = span_list[1].attributes.get("http.url")
202211
self.assertEqual(span_http_url, "http://this_is_a_fake_url:3849/SamplingTargets")

0 commit comments

Comments
 (0)