Deflake TimeAwaitable finalizer test (#21523)
This commit is contained in:
parent
d6409371ae
commit
c9cdc4891a
|
|
@ -14,20 +14,16 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
{
|
{
|
||||||
[Fact]
|
[Fact]
|
||||||
[QuarantinedTest]
|
[QuarantinedTest]
|
||||||
public void FinalizerRunsIfTimerAwaitableReferencesObject()
|
public async Task FinalizerRunsIfTimerAwaitableReferencesObject()
|
||||||
{
|
{
|
||||||
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
|
var tcs = new TaskCompletionSource<object>(TaskCreationOptions.RunContinuationsAsynchronously);
|
||||||
UseTimerAwaitableAndUnref(tcs);
|
UseTimerAwaitableAndUnref(tcs);
|
||||||
|
|
||||||
// Make sure it *really* cleans up
|
GC.Collect();
|
||||||
for (int i = 0; i < 5 && !tcs.Task.IsCompleted; i++)
|
GC.WaitForPendingFinalizers();
|
||||||
{
|
|
||||||
GC.Collect();
|
|
||||||
GC.WaitForPendingFinalizers();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure the finalizer runs
|
// Make sure the finalizer runs
|
||||||
Assert.True(tcs.Task.IsCompleted);
|
await tcs.Task.OrTimeout();
|
||||||
}
|
}
|
||||||
|
|
||||||
[MethodImpl(MethodImplOptions.NoInlining)]
|
[MethodImpl(MethodImplOptions.NoInlining)]
|
||||||
|
|
@ -43,12 +39,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
{
|
{
|
||||||
private readonly TimerAwaitable _timer;
|
private readonly TimerAwaitable _timer;
|
||||||
private readonly TaskCompletionSource<object> _tcs;
|
private readonly TaskCompletionSource<object> _tcs;
|
||||||
private int _count;
|
|
||||||
|
|
||||||
public ObjectWithTimerAwaitable(TaskCompletionSource<object> tcs)
|
public ObjectWithTimerAwaitable(TaskCompletionSource<object> tcs)
|
||||||
{
|
{
|
||||||
_tcs = tcs;
|
_tcs = tcs;
|
||||||
_timer = new TimerAwaitable(TimeSpan.Zero, TimeSpan.FromSeconds(1));
|
_timer = new TimerAwaitable(TimeSpan.FromSeconds(30), TimeSpan.FromSeconds(1));
|
||||||
_timer.Start();
|
_timer.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -58,7 +53,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
||||||
{
|
{
|
||||||
while (await _timer)
|
while (await _timer)
|
||||||
{
|
{
|
||||||
_count++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue