Skip to content

Commit 35da2c4

Browse files
committed
Suppress cancellation warnings in tests
Add targeted `ReSharper disable once MethodSupportsCancellation` suppressions in test cases that intentionally omit cancellation tokens. The surrounding comments explain that passing tokens here can cancel scheduling or short-circuit shutdown waits, causing flaky `TaskCanceledException` behavior on CI.
1 parent 854fa91 commit 35da2c4

4 files changed

Lines changed: 11 additions & 0 deletions

File tree

src/DiffEngine.Tests/InlineApplierTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ public async Task ContentIsNeverObservedHalfWritten()
214214
// `await reader` throwing TaskCanceledException - which is what made this fail on CI,
215215
// on all three OSes, while passing on any machine with a spare core. The loop already
216216
// exits on the token, which is the only cancellation this ever wanted
217+
// ReSharper disable once MethodSupportsCancellation
217218
var reader = Task.Run(
218219
() =>
219220
{

src/DiffEngine.Tests/PendingFilesFallbackTests.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public async Task ADeadPiperFallsThroughToTheQueueOwner()
5555
await cancel.CancelAsync();
5656
try
5757
{
58+
// No token: the line above already cancelled it, so passing it here would
59+
// return before the listener had unwound rather than waiting for it to. The
60+
// timeout is what bounds the drain
61+
// ReSharper disable once MethodSupportsCancellation
5862
await listening.WaitAsync(TimeSpan.FromSeconds(5));
5963
}
6064
catch (Exception exception)

src/DiffEngine.Tests/ViewerProtocolTests.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -683,6 +683,7 @@ public async Task ASlowExchangeDoesNotBlockTheNext()
683683
// No token on Task.Run: it cancels the scheduling rather than the delegate, so a pool
684684
// that had not picked this up before the cancel in the finally would leave the task
685685
// Canceled and the await below throwing. TrySend is blocking and takes no token anyway
686+
// ReSharper disable once MethodSupportsCancellation
686687
var accepting = Task.Run(() =>
687688
ViewerClient.TrySend(new(ViewerVerb.Accept, "key"), out var slow, server.Port, hold)
688689
? slow

src/DiffEngineTray.Tests/SettingsWriteTests.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ public async Task The_file_is_never_observed_missing()
2323
var missing = 0;
2424
var looks = 0;
2525
var unreadable = new ConcurrentBag<string>();
26+
// No token on Task.Run. It cancels the scheduling rather than the delegate, so a pool
27+
// that had not yet picked this up when the cancel lands leaves the task Canceled and
28+
// `await reader` throwing. The loop already exits on the token, which is the only
29+
// cancellation this ever wanted
30+
// ReSharper disable once MethodSupportsCancellation
2631
var reader = Task.Run(
2732
() =>
2833
{

0 commit comments

Comments
 (0)