Skip to content

Commit 610d348

Browse files
Yun-KimZStriker19
andauthored
chore(debugger): reduce debugger test flakiness [backport #4528 to 1.6] (#4864)
## Description Taken from: P403n1x87@ed5b716 This is required to reduce flakiness in one of the debugger tests: test_debugger_probe_new_delete[probe0-<lambda>] Example failure: https://app.circleci.com/pipelines/github/DataDog/dd-trace-py/23627/workflows/79199172-b4ef-43b3-a69e-371660cb1b68/jobs/1604074 ## Checklist - [x] Add additional sections for `feat` and `fix` pull requests. - [x] [Library documentation](https://github.com/DataDog/dd-trace-py/tree/1.x/docs) and/or [Datadog's documentation site](https://github.com/DataDog/documentation/) is updated. Link to doc PR in description. ## Reviewer Checklist - [x] Title is accurate. - [x] Description motivates each change. - [x] No unnecessary changes were introduced in this PR. - [x] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [x] Release note has been added for fixes and features, or else `changelog/no-changelog` label added. - [x] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. ## Description <!-- Briefly describe the change and why it was required. --> <!-- If this is a breaking change, explain why it is necessary. Breaking changes must append `!` after the type/scope. See https://ddtrace.readthedocs.io/en/stable/contributing.html for more details. --> ## Checklist - [ ] Followed the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines) when writing a release note. - [ ] Add additional sections for `feat` and `fix` pull requests. - [ ] [Library documentation](https://github.com/DataDog/dd-trace-py/tree/1.x/docs) and/or [Datadog's documentation site](https://github.com/DataDog/documentation/) is updated. Link to doc PR in description. <!-- Copy and paste the relevant snippet based on the type of pull request --> <!-- START feat --> ## Motivation <!-- Expand on why the change is required, include relevant context for reviewers --> ## Design <!-- Include benefits from the change as well as possible drawbacks and trade-offs --> ## Testing strategy <!-- Describe the automated tests and/or the steps for manual testing. <!-- END feat --> <!-- START fix --> ## Relevant issue(s) <!-- Link the pull request to any issues related to the fix. Use keywords for links to automate closing the issues once the pull request is merged. --> ## Testing strategy <!-- Describe any added regression tests and/or the manual testing performed. --> <!-- END fix --> ## Reviewer Checklist - [ ] Title is accurate. - [ ] Description motivates each change. - [ ] No unnecessary changes were introduced in this PR. - [ ] Avoid breaking [API](https://ddtrace.readthedocs.io/en/stable/versioning.html#interfaces) changes unless absolutely necessary. - [ ] Tests provided or description of manual testing performed is included in the code or PR. - [ ] Release note has been added and follows the [library release note guidelines](https://ddtrace.readthedocs.io/en/stable/contributing.html#Release-Note-Guidelines), or else `changelog/no-changelog` label added. - [ ] All relevant GitHub issues are correctly linked. - [ ] Backports are identified and tagged with Mergifyio. Co-authored-by: Zachary Groves <[email protected]>
1 parent d22dda5 commit 610d348

File tree

1 file changed

+16
-1
lines changed

1 file changed

+16
-1
lines changed

ddtrace/internal/module.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class ModuleWatchdog(dict):
211211
def __init__(self):
212212
# type: () -> None
213213
self._hook_map = defaultdict(list) # type: DefaultDict[str, List[ModuleHookType]]
214-
self._origin_map = {origin(module): module for module in sys.modules.values()}
214+
self._om = None # type: Optional[Dict[str, ModuleType]]
215215
self._modules = sys.modules # type: Union[dict, ModuleWatchdog]
216216
self._finding = set() # type: Set[str]
217217

@@ -223,6 +223,21 @@ def __setitem__(self, name, module):
223223
# type: (str, ModuleType) -> None
224224
self._modules.__setitem__(name, module)
225225

226+
@property
227+
def _origin_map(self):
228+
# type: () -> Dict[str, ModuleType]
229+
if self._om is None:
230+
try:
231+
self._om = {origin(module): module for module in sys.modules.values()}
232+
except RuntimeError:
233+
# The state of sys.modules might have been mutated by another
234+
# thread. We try to build the full mapping at the next occasion.
235+
# For now we take the more expensive route of building a list of
236+
# the current values, which might be incomplete.
237+
return {origin(module): module for module in list(sys.modules.values())}
238+
239+
return self._om
240+
226241
def _add_to_meta_path(self):
227242
# type: () -> None
228243
sys.meta_path.insert(0, self) # type: ignore[arg-type]

0 commit comments

Comments
 (0)