Skip to content

Commit

Permalink
Fix flakyness of DnsGetHostAddresses_PostCancelledToken_Throws (#70044)
Browse files Browse the repository at this point in the history
* Fix flakyness of DnsGetHostAddresses_PostCancelledToken_Throws

* fixup! Fix flakyness of DnsGetHostAddresses_PostCancelledToken_Throws
  • Loading branch information
rzikm authored Jun 1, 2022
1 parent 9d7a7e7 commit a466063
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,17 @@ public async Task DnsGetHostAddresses_PostCancelledToken_Throws()
using var cts = new CancellationTokenSource();

Task task = Dns.GetHostAddressesAsync(TestSettings.UncachedHost, cts.Token);

// This test might flake if the cancellation token takes too long to trigger:
// It's a race between the DNS server getting back to us and the cancellation processing.
cts.Cancel();

OperationCanceledException oce = await Assert.ThrowsAnyAsync<OperationCanceledException>(() => task);
Assert.Equal(cts.Token, oce.CancellationToken);
// This test is nondeterministic, the cancellation may take too long to trigger:
// It's a race between the DNS server getting back to us and the cancellation processing.
// since the host does not exist, both cases throw an exception.
Exception ex = await Assert.ThrowsAnyAsync<Exception>(() => task);
if (ex is OperationCanceledException oce)
{
// canceled in time
Assert.Equal(cts.Token, oce.CancellationToken);
}
}

// This is a regression test for https://github.com/dotnet/runtime/issues/63552
Expand Down

0 comments on commit a466063

Please sign in to comment.