Skip to content

[Blazor] Improve the reliability of 'JSInteropThrowsInUserCode' #15219

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
Oct 21, 2019
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
23 changes: 17 additions & 6 deletions src/Components/test/E2ETest/ServerExecutionTests/IgnitorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -75,11 +75,6 @@ async Task IAsyncLifetime.InitializeAsync()

async Task IAsyncLifetime.DisposeAsync()
{
if (TestSink != null)
{
TestSink.MessageLogged -= TestSink_MessageLogged;
}

await DisposeAsync();
}

Expand All @@ -90,14 +85,30 @@ protected virtual Task InitializeAsync()

protected virtual Task DisposeAsync()
{
if (TestSink != null)
{
TestSink.MessageLogged -= TestSink_MessageLogged;
}

return Task.CompletedTask;
}

private void TestSink_MessageLogged(WriteContext context)
{
var log = new LogMessage(context.LogLevel, context.EventId, context.Message, context.Exception);
Logs.Enqueue(log);
Output.WriteLine(log.ToString());
try
{
// This might produce an InvalidOperationException when the logger tries to log a message after
// the test has completed but before the handler has been removed.
// ---> System.InvalidOperationException: There is no currently active test.
// For that reason, we capture the exception here and silence it, as the message is captured inside the Logs
// variable anyway.
Output.WriteLine(log.ToString());
}
catch (Exception)
{
}
}

[DebuggerDisplay("{LogLevel.ToString(),nq} - {Message ?? \"null\",nq} - {Exception?.Message,nq}")]
Expand Down