Skip to content

Commit c6dbd64

Browse files
test(debugging): reduce flakiness in status logger [backport 1.16] (#6745)
Backport c46b216 from #6627 to 1.16. We remove some flakiness around probe status message testing by adding a wait logic to the mocked probe status logger. ## Checklist - [x] Change(s) are motivated and described in the PR description. - [x] Testing strategy is described if automated tests are not included in the PR. - [x] Risk is outlined (performance impact, potential for breakage, maintainability, etc). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] [Library release note guidelines](https://ddtrace.readthedocs.io/en/stable/releasenotes.html) are followed. If no release note is required, add label `changelog/no-changelog`. - [x] Documentation is included (in-code, generated user docs, [public corp docs](https://github.com/DataDog/documentation/)). - [x] Backport labels are set (if [applicable](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting)) ## Reviewer Checklist - [x] Title is accurate. - [x] No unnecessary changes are introduced. - [x] Description motivates each change. - [x] Avoids breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [x] Testing strategy adequately addresses listed risk(s). - [x] Change is maintainable (easy to change, telemetry, documentation). - [x] Release note makes sense to a user of the library. - [x] Reviewer has explicitly acknowledged and discussed the performance implications of this PR as reported in the benchmarks PR comment. - [x] Backport labels are set in a manner that is consistent with the [release branch maintenance policy](https://ddtrace.readthedocs.io/en/latest/contributing.html#backporting) Co-authored-by: Gabriele N. Tornetta <[email protected]>
1 parent 4ff0d4e commit c6dbd64

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

tests/debugging/mocking.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,19 @@ def __init__(self, service, encoder):
7171
super(MockProbeStatusLogger, self).__init__(service, encoder)
7272
self.queue = []
7373

74+
def clear(self):
75+
self.queue[:] = []
76+
77+
def wait(self, cond, timeout=1.0):
78+
end = monotonic() + timeout
79+
80+
while monotonic() < end:
81+
if cond(self.queue):
82+
return True
83+
sleep(0.01)
84+
85+
raise PayloadWaitTimeout()
86+
7487

7588
class TestSignalCollector(SignalCollector):
7689
def __init__(self, *args, **kwargs):

tests/debugging/test_debugger.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ def request(self, *args, **kwargs):
693693
RemoteConfigClient.request = request
694694
assert remoteconfig_poller.status == ServiceStatus.STOPPED
695695
try:
696-
with rcm_endpoint(), debugger(diagnostics_interval=0.3, enabled=True) as d:
696+
with rcm_endpoint(), debugger(diagnostics_interval=0.0, enabled=True) as d:
697697
d.add_probes(
698698
create_snapshot_line_probe(
699699
version=1,
@@ -713,7 +713,8 @@ def request(self, *args, **kwargs):
713713
),
714714
)
715715

716-
queue = d.probe_status_logger.queue
716+
logger = d.probe_status_logger
717+
queue = logger.queue
717718

718719
def count_status(queue):
719720
return Counter(_["debugger"]["diagnostics"]["status"] for _ in queue)
@@ -725,16 +726,14 @@ def versions(queue, status):
725726
if _["debugger"]["diagnostics"]["status"] == status
726727
]
727728

728-
sleep(0.1)
729-
assert count_status(queue) == {"INSTALLED": 2, "RECEIVED": 1}
729+
logger.wait(lambda q: count_status(q) == {"INSTALLED": 2, "RECEIVED": 1})
730730
assert versions(queue, "INSTALLED") == [1, 2]
731731
assert versions(queue, "RECEIVED") == [1]
732732

733-
queue[:] = []
734-
sleep(0.5)
733+
logger.clear()
735734
remoteconfig_poller._client.request()
736-
sleep(0.1)
737-
assert count_status(queue) == {"INSTALLED": 1}
735+
736+
logger.wait(lambda q: count_status(q) == {"INSTALLED": 1})
738737
assert versions(queue, "INSTALLED") == [2]
739738

740739
finally:

0 commit comments

Comments
 (0)