From 4b88074e308c9ddf6ba6f513c30942f4aa7d3ccf Mon Sep 17 00:00:00 2001 From: Pranav K Date: Mon, 11 May 2020 12:54:01 -0700 Subject: [PATCH] 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 https://github.com/dotnet/aspnetcore/issues/19413 --- .../RendererSynchronizationContextTest.cs | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Components/Components/test/Rendering/RendererSynchronizationContextTest.cs b/src/Components/Components/test/Rendering/RendererSynchronizationContextTest.cs index c92a585bd6..77544baa77 100644 --- a/src/Components/Components/test/Rendering/RendererSynchronizationContextTest.cs +++ b/src/Components/Components/test/Rendering/RendererSynchronizationContextTest.cs @@ -6,6 +6,7 @@ using System.Diagnostics; using System.Globalization; using System.Threading; using System.Threading.Tasks; +using Microsoft.AspNetCore.Testing; using Xunit; namespace Microsoft.AspNetCore.Components.Rendering @@ -763,5 +764,34 @@ namespace Microsoft.AspNetCore.Components.Rendering Assert.Equal(TaskStatus.Canceled, task.Status); await Assert.ThrowsAsync(async () => await task); } + + [Fact] + [QuarantinedTest] + public async Task InvokeAsync_SyncWorkInAsyncTaskIsCompletedFirst() + { + // Simplified version of ServerComponentRenderingTest.CanDispatchAsyncWorkToSyncContext + var expected = "First Second Third Fourth Fifth"; + var context = new RendererSynchronizationContext(); + string actual; + + // Act + await Task.Yield(); + actual = "First"; + + var invokeTask = context.InvokeAsync(async () => + { + // When the sync context is idle, queued work items start synchronously + actual += " Second"; + await Task.Delay(250); + actual += " Fourth"; + }); + + actual += " Third"; + await invokeTask; + actual += " Fifth"; + + // Assert + Assert.Equal(expected, actual); + } } }