Skip to content

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

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

Merged
merged 2 commits into from
Jun 12, 2025

Conversation

PureWeen
Copy link
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 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
Contributor

@Copilot 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 Work that we can't release without 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
p/0 Work that we can't release without
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

3 participants