Skip to content

Commit

Permalink
Try to fix a time-sensitive test, enable some tests on Mono based on d…
Browse files Browse the repository at this point in the history
  • Loading branch information
kouvel committed Feb 13, 2022
1 parent a82bbdb commit 237ed83
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
1 change: 0 additions & 1 deletion src/libraries/System.IO.Pipes/tests/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,4 @@

using Xunit;

[assembly: ActiveIssue("https://github.com/dotnet/runtime/issues/34582", TestPlatforms.Windows, TargetFrameworkMonikers.Netcoreapp, TestRuntimes.Mono)]
[assembly: SkipOnPlatform(TestPlatforms.Browser, "System.IO.Pipes is not supported on Browser")]
18 changes: 16 additions & 2 deletions src/libraries/System.IO/tests/StreamReader/StreamReaderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,24 @@ public async Task ReadToEndAsync_WithCancellation()
File.WriteAllLines(path, Enumerable.Repeat("A very large file used for testing StreamReader cancellation. 0123456789012345678901234567890123456789.", 1_000_000));

using StreamReader reader = File.OpenText(path);
using CancellationTokenSource cts = new (TimeSpan.FromMilliseconds(50));
using CancellationTokenSource cts = new ();
var token = cts.Token;

var ex = await Assert.ThrowsAnyAsync<OperationCanceledException>(async () => await reader.ReadToEndAsync(token));
var ex = await Assert.ThrowsAnyAsync<OperationCanceledException>(async () =>
{
Task<string> readToEndTask = reader.ReadToEndAsync(token);
// This is a time-sensitive test where the cancellation needs to happen before the async read completes.
// A sleep may be too long a delay, so spin-wait for a very short duration before canceling.
SpinWait spinner = default;
while (!spinner.NextSpinWillYield)
{
spinner.SpinOnce(sleep1Threshold: -1);
}
cts.Cancel();
await readToEndTask;
});
Assert.Equal(token, ex.CancellationToken);
}

Expand Down

0 comments on commit 237ed83

Please sign in to comment.