Skip to content

Add a simplified version of ServerComponentRenderingTest.CanDispatchAsyncWorkToSyncContext #21633

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 11, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Testing;
using Xunit;

namespace Microsoft.AspNetCore.Components.Rendering
Expand Down Expand Up @@ -763,5 +764,34 @@ public async Task InvokeAsync_FuncTaskT_CanReportCancellation()
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);
}
}
}