Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Restore clean Thread class after applying Profiling thread extensions #1206

Merged
merged 1 commit into from
Oct 20, 2020

Conversation

delner
Copy link
Contributor

@delner delner commented Oct 15, 2020

After adding a type check in #1200, it became clear that profiling tests would leave the Thread in an unclean state. Specifically, Thread would be replaced with a duplicate of the original class. Although this was functionally similar to the original Thread class object, the object_id is different, and this was causing Thread.current.class == Thread to evaluate as false.

In this pull request, we want to leave the Thread constant in a pristine state after a profiling test is complete, so that subsequent tests are consistent and dependable. To do this, we leverage stub_const to temporarily replace the Thread constant with a copy of Thread and restore it after the test.

There's also a specific case where we must profiling on the main Thread object. This main thread object is an instance of the original Thread class, not our stubbed copy of the Thread class, which means in our test suite, we cannot update this object without altering the original Thread class (something we cannot do if we want to preserve pristine state.) Instead in these tests, we must fork then patch the main thread inside the fork, to allow profiling on the main thread to be tested without altering the original Thread class.

@delner delner added core Involves Datadog core libraries dev/refactor Involves refactoring existing components labels Oct 15, 2020
@delner delner requested review from jd, marcotc, brettlangdon and a team October 15, 2020 22:25
@delner delner self-assigned this Oct 15, 2020
@delner delner force-pushed the refactor/profiling_thread_patching branch from 13a81e8 to a4abdb7 Compare October 16, 2020 19:19
@delner delner merged commit f07b062 into feature/profiling Oct 20, 2020
@delner delner deleted the refactor/profiling_thread_patching branch October 20, 2020 21:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Involves Datadog core libraries dev/refactor Involves refactoring existing components
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants