Skip to content

Commit

Permalink
tests(debugging): make RCM data flow synchronous (DataDog#6839)
Browse files Browse the repository at this point in the history
We ensure that a worker thread is not spawned so that we can reliably
trigger the RCM data flow manually in tests and remove any potential
race conditions with a background worker thread.

## 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

- [ ] Title is accurate.
- [ ] No unnecessary changes are introduced.
- [ ] Description motivates each change.
- [ ] Avoids breaking
[API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces)
changes unless absolutely necessary.
- [ ] Testing strategy adequately addresses listed risk(s).
- [ ] Change is maintainable (easy to change, telemetry, documentation).
- [ ] Release note makes sense to a user of the library.
- [ ] Reviewer has explicitly acknowledged and discussed the performance
implications of this PR as reported in the benchmarks PR comment.
- [ ] 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)
- [ ] If this PR touches code that signs or publishes builds or
packages, or handles credentials of any kind, I've requested a review
from `@DataDog/security-design-and-guidance`.
- [ ] This PR doesn't touch any of that.
  • Loading branch information
P403n1x87 authored Sep 13, 2023
1 parent bb8f196 commit 154c151
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions tests/debugging/probe/test_remoteconfig.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ def remove_probes(self, *probe_ids):
pass


class SyncProbeRCAdapter(ProbeRCAdapter):
def __init__(self, *args, **kwargs):
super(SyncProbeRCAdapter, self).__init__(*args, **kwargs)
# Prevent the worker thread from starting. We call methods manually.
self._subscriber.is_running = True


def config_metadata(config_id=None):
if config_id is None:
config_id = uuid4()
Expand Down Expand Up @@ -126,7 +133,7 @@ def callback(e, ps, *args, **kwargs):
]
)

adapter = ProbeRCAdapter(None, callback, status_logger=None)
adapter = SyncProbeRCAdapter(None, callback, status_logger=None)
remoteconfig_poller.register("TEST", adapter, skip_enabled=True)
adapter.append_and_publish({"test": random.randint(0, 11111111)}, "", config_metadata())
remoteconfig_poller._poll_data()
Expand All @@ -143,7 +150,7 @@ def cb(e, ps):
old_interval = di_config.diagnostics_interval
di_config.diagnostics_interval = 0.5
try:
adapter = ProbeRCAdapter(None, cb, status_logger=None)
adapter = SyncProbeRCAdapter(None, cb, status_logger=None)
# Wait to allow the next call to the adapter to generate a status event
remoteconfig_poller.register("TEST", adapter, skip_enabled=True)
adapter.append_and_publish(
Expand Down Expand Up @@ -190,7 +197,7 @@ def cb(e, ps):
old_interval = di_config.diagnostics_interval
di_config.diagnostics_interval = float("inf")
try:
adapter = ProbeRCAdapter(None, cb, status_logger=None)
adapter = SyncProbeRCAdapter(None, cb, status_logger=None)
remoteconfig_poller.register("TEST", adapter, skip_enabled=True)
adapter.append(
{
Expand Down Expand Up @@ -295,7 +302,7 @@ def callback(e, ps, *args, **kwargs):
old_interval = di_config.diagnostics_interval
di_config.diagnostics_interval = float("inf")
try:
adapter = ProbeRCAdapter(None, callback, status_logger=None)
adapter = SyncProbeRCAdapter(None, callback, status_logger=None)
remoteconfig_poller.register("TEST2", adapter, skip_enabled=True)
adapter.append_and_publish({"test": 2}, "", metadata)
remoteconfig_poller._poll_data()
Expand Down Expand Up @@ -347,7 +354,7 @@ def cb(e, ps):
old_interval = di_config.diagnostics_interval
di_config.diagnostics_interval = float("inf")
try:
adapter = ProbeRCAdapter(None, cb, status_logger=mock.Mock())
adapter = SyncProbeRCAdapter(None, cb, status_logger=mock.Mock())
# Wait to allow the next call to the adapter to generate a status event
remoteconfig_poller.register("TEST", adapter, skip_enabled=True)
adapter.append_and_publish(
Expand Down Expand Up @@ -540,7 +547,7 @@ def cb(e, ps):
old_interval = di_config.diagnostics_interval
di_config.diagnostics_interval = float("inf")
try:
adapter = ProbeRCAdapter(None, cb, None)
adapter = SyncProbeRCAdapter(None, cb, None)
# Wait to allow the next call to the adapter to generate a status event
remoteconfig_poller.register("TEST", adapter, skip_enabled=True)

Expand Down Expand Up @@ -589,7 +596,7 @@ def cb(e, ps):
di_config.diagnostics_interval = float("inf")
try:
status_logger = mock.Mock()
adapter = ProbeRCAdapter(None, cb, status_logger=status_logger)
adapter = SyncProbeRCAdapter(None, cb, status_logger=status_logger)
# Wait to allow the next call to the adapter to generate a status event
remoteconfig_poller.register("TEST", adapter, skip_enabled=True)

Expand Down

0 comments on commit 154c151

Please sign in to comment.