Add retries to all tests related to checking for weak references#29957
Merged
Add retries to all tests related to checking for weak references#29957
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the reliability of tests that check for weak reference collection by replacing direct GC calls with retry-enabled helpers.
- Replaces
await Task.Yield(); GC.Collect(); GC.WaitForPendingFinalizers();withawait TestHelpers.Collect()in most tests. - Introduces
TestHelpers.WaitForCollect()to await object collection and uses it in assertions. - Updates
TestHelpers.Collect()to perform multiple forced collections and adjusts test code to use non-genericWeakReference.
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| src/Controls/tests/Core.UnitTests/WindowsTests.cs | Replaced manual GC calls with TestHelpers.Collect() |
| src/Controls/tests/Core.UnitTests/WeakEventProxyTests.cs | Swapped GC calls for TestHelpers.Collect() and WaitForCollect() |
| src/Controls/tests/Core.UnitTests/VisualElementTests.cs | Applied TestHelpers.Collect() and WaitForCollect() in GC scenarios |
| src/Controls/tests/Core.UnitTests/TypedBindingUnitTests.cs | Replaced GC loops; uses WaitForCollect() but missing assertions |
| src/Controls/tests/Core.UnitTests/TestHelpers.cs | Expanded Collect() for multi-pass GC and added WaitForCollect() |
| src/Controls/tests/Core.UnitTests/SetterSpecificityListTests.cs | Switched from WeakReference<T> to WeakReference and added WaitForCollect() |
| src/Controls/tests/Core.UnitTests/BindingUnitTests.cs | Updated GC assertions to use WaitForCollect() |
| src/Controls/tests/Core.UnitTests/BindableLayoutTests.cs | Consolidated multi-step GC into WaitForCollect() calls |
rmarinho
approved these changes
Jun 12, 2025
mattleibow
approved these changes
Jun 12, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Description of Change
While working on #29837 a number of the tests related to checking for weak references were failing intermittently. This PR adds retries to all tests related to checking for weak references to ensure that the tests are more reliable. With these changes I wasn't able to get it to fail locally.