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

[tests] introduce AssertionExtensions.WaitForGC() #16237

Merged
merged 1 commit into from Jul 19, 2023

Conversation

jonathanpeppers
Copy link
Member

I've found the most reliable way to make DeviceTests run the GC for all platforms is:

Assert.NotNull(pageReference);
await AssertionExtensions.Wait(() =>
{
    GC.Collect();
    GC.WaitForPendingFinalizers();
    return !pageReference.IsAlive;
}, timeout: 5000);

Let's standardize on this, so we can instead do:

await AssertionExtensions.WaitForGC(pageReference);

And if you have multiple:

await AssertionExtensions.WaitForGC(pageReference, handlerReference);

The helper method also checks if the params WeakReference[] is empty, or any WeakReference are null. I simplified various tests with this change.

I've found the most reliable way to make DeviceTests
run the GC for all platforms is:

    Assert.NotNull(pageReference);
    await AssertionExtensions.Wait(() =>
    {
        GC.Collect();
        GC.WaitForPendingFinalizers();
        return !pageReference.IsAlive;
    }, timeout: 5000);

Let's standardize on this, so we can instead do:

    await AssertionExtensions.WaitForGC(pageReference);

And if you have multiple:

    await AssertionExtensions.WaitForGC(pageReference, handlerReference);

The helper method also checks if the `params WeakReference[]` is empty,
or any `WeakReference` are null. I simplified various tests with this
change.
@jonathanpeppers jonathanpeppers marked this pull request as ready for review July 19, 2023 21:42
@rmarinho rmarinho enabled auto-merge (squash) July 19, 2023 21:51
@rmarinho rmarinho merged commit 9ab3346 into dotnet:main Jul 19, 2023
36 checks passed
@samhouts samhouts added the area/testing Unit tests, device tests label Jul 20, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 8, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/testing Unit tests, device tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants