Restore clean Thread class after applying Profiling thread extensions #1206
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 originalThread
class object, theobject_id
is different, and this was causingThread.current.class == Thread
to evaluate asfalse
.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 leveragestub_const
to temporarily replace theThread
constant with a copy ofThread
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 originalThread
class, not our stubbed copy of theThread
class, which means in our test suite, we cannot update this object without altering the originalThread
class (something we cannot do if we want to preserve pristine state.) Instead in these tests, we mustfork
then patch the main thread inside the fork, to allow profiling on the main thread to be tested without altering the originalThread
class.