Skip to content

Commit

Permalink
chore(profiler): fix regression test for frame object garbage collect…
Browse files Browse the repository at this point in the history
…ion in Python 3.11 (#4937)

## Description
#4901 added a fix to properly decrement frametype objects in Python 3.11
in our stack collector, with a regression test. We found that this
regression test does not properly assert that frametype objects were all
garbage collected, which this test fixes.

Specifically, the previous change was looking for only frame objects
related to a function call `_foo()`. However, after reverting the fix
from #4901 this test still passed, because all frametype objects have
been garbage collected. This change makes a broader assertion instead
that all frametype objects have been garbage collected, which does
expectedly fail if the fix from #4901 is reverted.

<!-- 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.
- [ ] Change contains telemetry where appropriate (logs, metrics, etc.).
- [ ] Telemetry is meaningful, actionable and does not have the
potential to leak sensitive data.

Co-authored-by: Brett Langdon <[email protected]>
  • Loading branch information
Yun-Kim and brettlangdon authored Jan 19, 2023
1 parent f278483 commit 539f3f4
Showing 1 changed file with 1 addition and 4 deletions.
5 changes: 1 addition & 4 deletions tests/profiling/collector/test_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -761,7 +761,4 @@ def _foo():
_foo()

gc.collect() # Make sure we don't race with gc when we check frame objects
frametype_objs = [obj for obj in gc.get_objects() if isinstance(obj, FrameType)]
for obj in frametype_objs:
# Ensure that all frames relating to _foo() have been gc'd already
assert obj.f_code.co_name != "_foo"
assert sum(isinstance(_, FrameType) for _ in gc.get_objects()) == 0

0 comments on commit 539f3f4

Please sign in to comment.