Skip to content

Commit 76fdab0

Browse files
committed
Suppress Do not use blocking task operations in test method
1 parent aba77d0 commit 76fdab0

File tree

12 files changed

+54
-0
lines changed

12 files changed

+54
-0
lines changed

src/Components/Components/test/NavigationManagerTest.cs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,9 @@ public void LocationChangingHandlers_CanContinueTheNavigationSynchronously_WhenO
223223

224224
// Assert
225225
Assert.True(navigation1.IsCompletedSuccessfully);
226+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
226227
Assert.True(navigation1.Result);
228+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
227229

228230
static ValueTask HandleLocationChanging(LocationChangingContext context)
229231
{
@@ -250,7 +252,9 @@ public void LocationChangingHandlers_CanContinueTheNavigationSynchronously_WhenM
250252

251253
// Assert
252254
Assert.True(navigation1.IsCompletedSuccessfully);
255+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
253256
Assert.True(navigation1.Result);
257+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
254258
Assert.Equal(initialHandlerCount, completedHandlerCount);
255259

256260
ValueTask HandleLocationChanging(LocationChangingContext context)
@@ -276,7 +280,9 @@ public void LocationChangingHandlers_CanContinueTheNavigationAsynchronously_When
276280
Assert.False(navigation1.IsCompleted);
277281
tcs.SetResult();
278282
Assert.True(navigation1.IsCompletedSuccessfully);
283+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
279284
Assert.True(navigation1.Result);
285+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
280286

281287
async ValueTask HandleLocationChanging(LocationChangingContext context)
282288
{
@@ -328,7 +334,9 @@ public void LocationChangingHandlers_CanCancelTheNavigationSynchronously_WhenOne
328334

329335
// Assert
330336
Assert.True(navigation1.IsCompletedSuccessfully);
337+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
331338
Assert.False(navigation1.Result);
339+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
332340

333341
static ValueTask HandleLocationChanging(LocationChangingContext context)
334342
{
@@ -357,7 +365,9 @@ public void LocationChangingHandlers_CanCancelTheNavigationSynchronously_WhenMul
357365

358366
// Assert
359367
Assert.True(navigation1.IsCompletedSuccessfully);
368+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
360369
Assert.False(navigation1.Result);
370+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
361371
Assert.Equal(expectedInvokedHandlerCount, invokedHandlerCount);
362372

363373
ValueTask HandleLocationChanging_AllowNavigation(LocationChangingContext context)
@@ -391,7 +401,9 @@ public void LocationChangingHandlers_CanCancelTheNavigationSynchronously_BeforeR
391401

392402
// Assert
393403
Assert.True(navigation1.IsCompletedSuccessfully);
404+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
394405
Assert.False(navigation1.Result);
406+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
395407
Assert.True(currentContext.DidPreventNavigation);
396408
Assert.True(currentContext.CancellationToken.IsCancellationRequested);
397409
Assert.False(isHandlerCompleted);
@@ -428,7 +440,9 @@ public void LocationChangingHandlers_CanCancelTheNavigationSynchronously_BeforeR
428440

429441
// Assert
430442
Assert.True(navigation1.IsCompletedSuccessfully);
443+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
431444
Assert.False(navigation1.Result);
445+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
432446
Assert.True(currentContext.DidPreventNavigation);
433447
Assert.True(currentContext.CancellationToken.IsCancellationRequested);
434448
Assert.False(isFirstHandlerCompleted);
@@ -503,7 +517,9 @@ public async Task LocationChangingHandlers_CanCancelTheNavigationAsynchronously_
503517

504518
// Assert
505519
Assert.True(navigation1.IsCompletedSuccessfully);
520+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
506521
Assert.False(navigation1.Result);
522+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
507523
Assert.Equal(blockNavigationHandlerCount, canceledBlockNavigationHandlerCount);
508524

509525
async ValueTask HandleLocationChanging_BlockNavigation(LocationChangingContext context)
@@ -556,11 +572,13 @@ public async Task LocationChangingHandlers_AreCanceledBySuccessiveNavigations_Wh
556572
await tcs.Task.WaitAsync(Timeout);
557573

558574
// Assert
575+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
559576
Assert.True(navigation1.IsCompletedSuccessfully);
560577
Assert.False(navigation1.Result);
561578

562579
Assert.True(navigation2.IsCompletedSuccessfully);
563580
Assert.True(navigation2.Result);
581+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
564582

565583
async ValueTask HandleLocationChanging(LocationChangingContext context)
566584
{
@@ -615,6 +633,7 @@ public async Task LocationChangingHandlers_AreCanceledBySuccessiveNavigations_Wh
615633
await tcs.Task.WaitAsync(Timeout);
616634

617635
// Assert
636+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
618637
Assert.True(navigation1.IsCompletedSuccessfully);
619638
Assert.False(navigation1.Result);
620639

@@ -623,6 +642,7 @@ public async Task LocationChangingHandlers_AreCanceledBySuccessiveNavigations_Wh
623642

624643
Assert.True(navigation3.IsCompletedSuccessfully);
625644
Assert.True(navigation3.Result);
645+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
626646

627647
Assert.Equal(expectedCanceledHandlerCount, canceledHandlerCount);
628648
Assert.Equal(0, completedHandlerCount);

src/Components/Server/test/Circuits/RemoteRendererTest.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,9 @@ public async Task ProcessBufferedRenderBatches_WritesRenders()
183183

184184
// Assert
185185
Assert.Equal(new long[] { 2, 3, 4 }, renderIds);
186+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
186187
Assert.True(task.Wait(3000), "One or more render batches weren't acknowledged");
188+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
187189

188190
await task;
189191
}

src/DataProtection/DataProtection/test/Microsoft.AspNetCore.DataProtection.Tests/KeyManagement/KeyRingProviderTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -709,8 +709,10 @@ public void GetCurrentKeyRing_NoExistingKeyRing_HoldsAllThreadsUntilKeyRingCreat
709709
Assert.True(mreBackgroundThreadHasCalledGetCurrentKeyRing.Wait(testTimeout), "Test timed out.");
710710
mreForegroundThreadIsCallingGetCurrentKeyRing.Set();
711711
var foregroundRetVal = keyRingProvider.GetCurrentKeyRingCore(now);
712+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
712713
backgroundGetKeyRingTask.Wait(testTimeout);
713714
var backgroundRetVal = backgroundGetKeyRingTask.GetAwaiter().GetResult();
715+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
714716

715717
// Assert - underlying provider only should have been called once
716718
Assert.Same(expectedKeyRing, foregroundRetVal);

src/Hosting/TestHost/test/ClientHandlerTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,7 +392,9 @@ public async Task BlockingMiddlewareShouldNotBlockClient()
392392
var httpClient = new HttpClient(handler);
393393
Task<HttpResponseMessage> task = httpClient.GetAsync("https://example.com/");
394394
Assert.False(task.IsCompleted);
395+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
395396
Assert.False(task.Wait(50));
397+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
396398
block.Set();
397399
HttpResponseMessage response = await task;
398400
}

src/Hosting/TestHost/test/HttpContextBuilderTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,9 @@ public async Task BlockingMiddlewareShouldNotBlockClient()
107107
var task = server.SendAsync(c => { });
108108

109109
Assert.False(task.IsCompleted);
110+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
110111
Assert.False(task.Wait(50));
112+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
111113
block.Set();
112114
var context = await task;
113115
}

src/JSInterop/Microsoft.JSInterop/test/Infrastructure/DotNetDispatcherTest.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,9 @@ public void EndInvokeJS_WithSuccessValue()
273273

274274
// Assert
275275
Assert.True(task.IsCompletedSuccessfully);
276+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
276277
var result = task.Result;
278+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
277279
Assert.Equal(testDTO.StringVal, result.StringVal);
278280
Assert.Equal(testDTO.IntVal, result.IntVal);
279281
}
@@ -407,7 +409,9 @@ public void EndInvokeJS_Works()
407409

408410
// Assert
409411
Assert.True(task.IsCompletedSuccessfully);
412+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
410413
Assert.Equal(7, task.Result.IntVal);
414+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
411415
}
412416

413417
[Fact]
@@ -419,7 +423,9 @@ public void EndInvokeJS_WithArrayValue()
419423
DotNetDispatcher.EndInvokeJS(jsRuntime, $"[{jsRuntime.LastInvocationAsyncHandle}, true, [1, 2, 3]]");
420424

421425
Assert.True(task.IsCompletedSuccessfully);
426+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
422427
Assert.Equal(new[] { 1, 2, 3 }, task.Result);
428+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
423429
}
424430

425431
[Fact]
@@ -431,7 +437,9 @@ public void EndInvokeJS_WithNullValue()
431437
DotNetDispatcher.EndInvokeJS(jsRuntime, $"[{jsRuntime.LastInvocationAsyncHandle}, true, null]");
432438

433439
Assert.True(task.IsCompletedSuccessfully);
440+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
434441
Assert.Null(task.Result);
442+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
435443
}
436444

437445
[Fact]

src/JSInterop/Microsoft.JSInterop/test/JSRuntimeTest.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,9 @@ public void CanCompleteAsyncCallsAsSuccess()
121121
ref reader);
122122
Assert.False(unrelatedTask.IsCompleted);
123123
Assert.True(task.IsCompleted);
124+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
124125
Assert.Equal("my result", task.Result);
126+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
125127
}
126128

127129
[Fact]
@@ -140,7 +142,9 @@ public void CanCompleteAsyncCallsWithComplexType()
140142
/* succeeded: */ true,
141143
ref reader);
142144
Assert.True(task.IsCompleted);
145+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
143146
var poco = task.Result;
147+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
144148
Debug.Assert(poco != null);
145149
Assert.Equal(10, poco.Id);
146150
Assert.Equal("Test", poco.Name);
@@ -163,7 +167,9 @@ public void CanCompleteAsyncCallsWithComplexTypeUsingPropertyCasing()
163167
/* succeeded: */ true,
164168
ref reader);
165169
Assert.True(task.IsCompleted);
170+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
166171
var poco = task.Result;
172+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
167173
Debug.Assert(poco != null);
168174
Assert.Equal(10, poco.Id);
169175
Assert.Equal("Test", poco.Name);

src/Middleware/ConcurrencyLimiter/test/PolicyTests/QueuePolicyTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ public void DoesNotWaitIfQueueFull()
4040
{
4141
using var s = TestUtils.CreateQueuePolicy(2, 1);
4242

43+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
4344
var t1 = s.TryEnterAsync();
4445
Assert.True(t1.IsCompleted);
4546
Assert.True(t1.Result);
@@ -54,6 +55,7 @@ public void DoesNotWaitIfQueueFull()
5455
var t4 = s.TryEnterAsync();
5556
Assert.True(t4.IsCompleted);
5657
Assert.False(t4.Result);
58+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
5759
}
5860

5961
[Fact]

src/Mvc/Mvc.Razor.RuntimeCompilation/test/RuntimeViewCompilerTest.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,8 +638,10 @@ public async Task GetOrAdd_AllowsConcurrentCompilationOfMultipleRazorPages()
638638
// Assert
639639
Assert.True(compilingOne);
640640
Assert.True(compilingTwo);
641+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
641642
Assert.Same(result1, task1.Result);
642643
Assert.Same(result2, task2.Result);
644+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
643645
}
644646

645647
[Fact]
@@ -678,9 +680,11 @@ public async Task CompileAsync_DoesNotCreateMultipleCompilationResults_ForConcur
678680
await Task.WhenAll(task1, task2);
679681

680682
// Assert
683+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
681684
var result1 = task1.Result;
682685
var result2 = task2.Result;
683686
Assert.Same(result1, result2);
687+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
684688
}
685689

686690
[Fact]

src/Servers/Kestrel/Core/test/BufferWriterTests.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,10 @@ public void BufferWriterCountsBytesCommitted()
197197
writer.Commit();
198198
Assert.Equal(13, writer.BytesCommitted);
199199

200+
#pragma warning disable xUnit1031 // Do not use blocking task operations in test method
200201
Pipe.Writer.FlushAsync().GetAwaiter().GetResult();
201202
var readResult = Pipe.Reader.ReadAsync().GetAwaiter().GetResult();
203+
#pragma warning restore xUnit1031 // Do not use blocking task operations in test method
202204

203205
// Consuming the buffer does not change BytesCommitted
204206
Assert.Equal(13, readResult.Buffer.Length);

0 commit comments

Comments
 (0)