Skip to content
Merged
Changes from 1 commit
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
2e3e331
[release/7.0-rc2] Use determinism instead of timing in cancellation t…
github-actions[bot] Sep 15, 2022
393e1ab
Bump Intellisense RC2 package version again (#75698)
carlossanlop Sep 15, 2022
f0eb5ce
Implement an AppContext compatibility switch re-enabling reflection f…
eiriktsarpalis Sep 16, 2022
fdca698
[release/7.0-rc2] Handle a null szPname field (#75716)
github-actions[bot] Sep 16, 2022
6cf6e48
[wasm] Use newer helix images with updated v8 (#75726)
github-actions[bot] Sep 16, 2022
e0a65e0
Fix edge cases of getting attribute data from syntax (#75728)
github-actions[bot] Sep 16, 2022
e869f44
[release/7.0-rc2] Fix wasm template README (#75766)
github-actions[bot] Sep 16, 2022
b9d050a
Fix Configuration.Binder for collection properties with no setters (#…
github-actions[bot] Sep 16, 2022
5634242
[release/7.0-rc2] Ensure Max/Min for floating-point on x86/x64 are no…
github-actions[bot] Sep 16, 2022
b23dc07
[release/7.0-rc2] Update dependencies from dotnet/emsdk (#75707)
dotnet-maestro[bot] Sep 19, 2022
27396a2
Do not request type layout for RuntimeDetermined types (#75789)
github-actions[bot] Sep 19, 2022
ec82570
Bump 7.0 intellisense package version (WinForms docs update) (#75786)
carlossanlop Sep 19, 2022
39fce88
fix behavior of JMC (#75833)
github-actions[bot] Sep 19, 2022
a66c066
hide interop delegates from intelisense (#75825)
github-actions[bot] Sep 19, 2022
3056135
* fix missing managed stack trace on managed exceptions marshaled to …
pavelsavara Sep 19, 2022
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
Next Next commit
[release/7.0-rc2] Use determinism instead of timing in cancellation t…
…ests (#75655)

* Use determinism instead of timing in cancellation tests

* Add an explanatory comment to the test.

* Spell "canceling" with only one L.

Co-authored-by: Jeremy Barton <[email protected]>
  • Loading branch information
github-actions[bot] and bartonjs authored Sep 15, 2022
commit 2e3e3317406c835101acd33a683d23030c0b2e87
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,27 @@ public async Task VerifyComputeHashAsync(int size)
[ActiveIssue("https://github.com/dotnet/runtime/issues/37669", TestPlatforms.Browser)]
public async Task ComputeHashAsync_SupportsCancellation()
{
using (CancellationTokenSource cancellationSource = new CancellationTokenSource(100))
using (PositionValueStream stream = new SlowPositionValueStream(10000))
using (CancellationTokenSource cancellationSource = new CancellationTokenSource())
using (PositionValueStream stream = new SelfCancelingStream(10000, cancellationSource))
using (HashAlgorithm hash = new SummingTestHashAlgorithm())
{
// The stream has a length longer than ComputeHashAsync's read buffer,
// so ReadAsync will get called multiple times.
// The first call succeeds, but moves the cancellation source to canceled,
// and the second call then fails with an OperationCanceledException, canceling the
// whole operation.
await Assert.ThrowsAnyAsync<OperationCanceledException>(
() => hash.ComputeHashAsync(stream, cancellationSource.Token));

Assert.True(cancellationSource.IsCancellationRequested);
}
}

[Fact]
public void ComputeHashAsync_Disposed()
{
using (PositionValueStream stream = new SlowPositionValueStream(10000))
using (CancellationTokenSource cancellationSource = new CancellationTokenSource())
using (PositionValueStream stream = new SelfCancelingStream(10000, cancellationSource))
using (HashAlgorithm hash = new SummingTestHashAlgorithm())
{
hash.Dispose();
Expand All @@ -85,6 +93,10 @@ public void ComputeHashAsync_Disposed()
// Not returning or awaiting the Task, it never got created.
hash.ComputeHashAsync(stream);
});

// If SelfCancelingStream.Read (or ReadAsync) was called it will trip cancellation,
// so use that as a signal for whether or not the stream was ever read from.
Assert.False(cancellationSource.IsCancellationRequested, "Stream.Read was invoked");
}
}

Expand Down Expand Up @@ -123,15 +135,19 @@ protected override void HashCore(byte[] array, int ibStart, int cbSize)
// implementations by verifying the right value is produced.
}

private class SlowPositionValueStream : PositionValueStream
private class SelfCancelingStream : PositionValueStream
{
public SlowPositionValueStream(int totalCount) : base(totalCount)
private readonly CancellationTokenSource _cancellationSource;

public SelfCancelingStream(int totalCount, CancellationTokenSource cancellationSource)
: base(totalCount)
{
_cancellationSource = cancellationSource;
}

public override int Read(byte[] buffer, int offset, int count)
{
System.Threading.Thread.Sleep(1000);
_cancellationSource.Cancel(throwOnFirstException: true);
return base.Read(buffer, offset, count);
}
}
Expand Down