Skip to content

Deflake TimeAwaitable finalizer test #21523

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 3 commits into from
May 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,16 @@ public class TimerAwaitableTests
{
[Fact]
[QuarantinedTest]
public void FinalizerRunsIfTimerAwaitableReferencesObject()
public async Task FinalizerRunsIfTimerAwaitableReferencesObject()
{
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
UseTimerAwaitableAndUnref(tcs);

// Make sure it *really* cleans up
for (int i = 0; i < 5 && !tcs.Task.IsCompleted; i++)
{
GC.Collect();
GC.WaitForPendingFinalizers();
}
GC.Collect();
GC.WaitForPendingFinalizers();

// Make sure the finalizer runs
Assert.True(tcs.Task.IsCompleted);
await tcs.Task.OrTimeout();
}

[MethodImpl(MethodImplOptions.NoInlining)]
Expand All @@ -43,12 +39,11 @@ public class ObjectWithTimerAwaitable
{
private readonly TimerAwaitable _timer;
private readonly TaskCompletionSource<object> _tcs;
private int _count;

public ObjectWithTimerAwaitable(TaskCompletionSource<object> tcs)
{
_tcs = tcs;
_timer = new TimerAwaitable(TimeSpan.Zero, TimeSpan.FromSeconds(1));
_timer = new TimerAwaitable(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1));
_timer.Start();
}

Expand All @@ -58,7 +53,6 @@ public async Task Start()
{
while (await _timer)
{
_count++;
}
}
}
Expand Down