Skip to content

Add retries to all tests related to checking for weak references#29957

Merged
PureWeen merged 2 commits intomainfrom
fix_flakey_collects
Jun 12, 2025
Merged

Add retries to all tests related to checking for weak references#29957
PureWeen merged 2 commits intomainfrom
fix_flakey_collects

Conversation

@PureWeen
Copy link
Copy Markdown
Member

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.

Copilot AI review requested due to automatic review settings June 12, 2025 12:24
@PureWeen PureWeen requested a review from a team as a code owner June 12, 2025 12:24
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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(); with await 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-generic WeakReference.

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

@PureWeen PureWeen added this to the .NET 9 SR9 milestone Jun 12, 2025
@PureWeen PureWeen added the p/0 Current heighest priority issues that we are targeting for a release. label Jun 12, 2025
@github-project-automation github-project-automation bot moved this from Todo to Approved in MAUI SDK Ongoing Jun 12, 2025
@PureWeen PureWeen merged commit acdb6f2 into main Jun 12, 2025
126 of 130 checks passed
@PureWeen PureWeen deleted the fix_flakey_collects branch June 12, 2025 17:41
@github-project-automation github-project-automation bot moved this from Approved to Done in MAUI SDK Ongoing Jun 12, 2025
rmarinho pushed a commit that referenced this pull request Jun 24, 2025
)

* Add retries to all tests related to checking for weak references

* - BindingUnsubscribesForDeadTarget cleanup
@github-actions github-actions bot locked and limited conversation to collaborators Jul 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

p/0 Current heighest priority issues that we are targeting for a release.

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

4 participants