Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Try to fix a time-sensitive test, enable some tests on Mono based on #…
  • Loading branch information
Koundinya Veluri committed Mar 3, 2022
commit 7c0d7d513470d7fe74abaaa6745d1807ad47aa51
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