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]
|
||||
[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)]
|
||||
|
|
@ -43,12 +39,11 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
{
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
@ -58,7 +53,6 @@ namespace Microsoft.AspNetCore.SignalR.Client.Tests
|
|||
{
|
||||
while (await _timer)
|
||||
{
|
||||
_count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue