Skip to content

Commit 4b88074

Browse files
authored
Add a simplified version of ServerComponentRenderingTest.CanDispatchAsyncWorkToSyncContext (#21633)
ServerComponentRenderingTest.CanDispatchAsyncWorkToSyncContext is quarantined but since it's not running on Helix there isn't any history available for it. With all the moving parts in the server test, it's unclear if it's a product vs test setup issue. Authoring a more simplified test so we can track test history. Note that it's starting off as quarantined because there's no evidence that the product code isn't broken Fixes #19413
1 parent cb83d5d commit 4b88074

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/Components/Components/test/Rendering/RendererSynchronizationContextTest.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.Globalization;
77
using System.Threading;
88
using System.Threading.Tasks;
9+
using Microsoft.AspNetCore.Testing;
910
using Xunit;
1011

1112
namespace Microsoft.AspNetCore.Components.Rendering
@@ -763,5 +764,34 @@ public async Task InvokeAsync_FuncTaskT_CanReportCancellation()
763764
Assert.Equal(TaskStatus.Canceled, task.Status);
764765
await Assert.ThrowsAsync<TaskCanceledException>(async () => await task);
765766
}
767+
768+
[Fact]
769+
[QuarantinedTest]
770+
public async Task InvokeAsync_SyncWorkInAsyncTaskIsCompletedFirst()
771+
{
772+
// Simplified version of ServerComponentRenderingTest.CanDispatchAsyncWorkToSyncContext
773+
var expected = "First Second Third Fourth Fifth";
774+
var context = new RendererSynchronizationContext();
775+
string actual;
776+
777+
// Act
778+
await Task.Yield();
779+
actual = "First";
780+
781+
var invokeTask = context.InvokeAsync(async () =>
782+
{
783+
// When the sync context is idle, queued work items start synchronously
784+
actual += " Second";
785+
await Task.Delay(250);
786+
actual += " Fourth";
787+
});
788+
789+
actual += " Third";
790+
await invokeTask;
791+
actual += " Fifth";
792+
793+
// Assert
794+
Assert.Equal(expected, actual);
795+
}
766796
}
767797
}

0 commit comments

Comments
 (0)