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
This commit is contained in:
parent
cb83d5d155
commit
4b88074e30
|
|
@ -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<TaskCanceledException>(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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue