Skip to content
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

[ci] Fix Playwright test times out/fails because target closed #100074

Merged
merged 15 commits into from
Mar 28, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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 @@ -16,7 +16,6 @@ public record BlazorRunOptions
bool CheckCounter = true,
Dictionary<string, string>? ServerEnvironment = null,
Func<IPage, Task>? Test = null,
Action<IPage>? OnPageLoaded = null,
Action<IPage, IConsoleMessage>? OnConsoleMessage = null,
Action<string>? OnServerMessage = null,
Action<string>? OnErrorMessage = null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ public async Task BlazorRunTest(string runArgs,
var page = await runner.RunAsync(
runCommand,
runArgs,
onPageLoaded: runOptions.OnPageLoaded,
onConsoleMessage: OnConsoleMessage,
onServerMessage: runOptions.OnServerMessage,
onError: OnErrorMessage,
Expand Down
6 changes: 1 addition & 5 deletions src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,20 @@ public async Task<IPage> RunAsync(
string args,
bool headless = true,
Action<IPage, IConsoleMessage>? onConsoleMessage = null,
Action<IPage>? onPageLoaded = null,
Action<string>? onServerMessage = null,
Action<string>? onError = null,
Func<string, string>? modifyBrowserUrl = null)
{
var urlString = await StartServerAndGetUrlAsync(cmd, args, onServerMessage);
var browser = await SpawnBrowserAsync(urlString, headless);
var context = await browser.NewContextAsync();
return await RunAsync(context, urlString, headless, onPageLoaded, onConsoleMessage, onError, modifyBrowserUrl);
return await RunAsync(context, urlString, headless, onConsoleMessage, onError, modifyBrowserUrl);
}

public async Task<IPage> RunAsync(
IBrowserContext context,
string browserUrl,
bool headless = true,
Action<IPage>? onPageLoaded = null,
Action<IPage, IConsoleMessage>? onConsoleMessage = null,
Action<string>? onError = null,
Func<string, string>? modifyBrowserUrl = null,
Expand All @@ -150,8 +148,6 @@ public async Task<IPage> RunAsync(
browserUrl = modifyBrowserUrl(browserUrl);

IPage page = await context.NewPageAsync();
if (onPageLoaded is not null)
page.Load += (_, _) => onPageLoaded(page);

if (onConsoleMessage is not null)
page.Console += (_, msg) => onConsoleMessage(page, msg);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,6 @@ private async Task<RunResult> RunSdkStyleApp(RunOptions options, BlazorRunHost h
CheckCounter: false,
Config: options.Configuration,
ServerEnvironment: options.ServerEnvironment,
OnPageLoaded: options.OnPageLoaded,
OnConsoleMessage: OnConsoleMessage,
OnServerMessage: OnServerMessage,
BrowserPath: options.BrowserPath,
Expand Down Expand Up @@ -170,7 +169,6 @@ protected record RunOptions(
string? TestScenario = null,
Dictionary<string, string> BrowserQueryString = null,
Dictionary<string, string> ServerEnvironment = null,
Action<IPage> OnPageLoaded = null,
Action<IPage, IConsoleMessage> OnConsoleMessage = null,
Action<string> OnServerMessage = null,
int? ExpectedExitCode = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,23 @@ public async Task SignalRPassMessages(string config, string transport)
ServerEnvironment: new Dictionary<string, string> { ["ASPNETCORE_ENVIRONMENT"] = "Development" },
BrowserPath: "/chat",
BrowserQueryString: new Dictionary<string, string> { ["transport"] = transport, ["message"] = "ping" },
OnPageLoaded: async page => await page.ClickAsync("button#connectButton"),
OnServerMessage: (msg) => { serverOutput.Add(msg); },
OnServerMessage: (msg) => serverOutput.Add(msg),
OnConsoleMessage: async (page, msg) =>
{
consoleOutput.Add(msg.Text);
if (msg.Text.Contains("TestOutput ->"))
_testOutput.WriteLine(msg.Text);

// prevent timeouts with [Long Running Test] on error
if (msg.Text.Contains("[ERROR]"))
throw new Exception($"{_testOutput}\n{msg.Text}");
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved

if (msg.Text.Contains("Finished GetQueryParameters"))
{
await Task.Delay(500); // make sure OnAfterRender returned
await page.ClickAsync("button#connectButton");
}

if (msg.Text.Contains("SignalR connected"))
await page.ClickAsync("button#subscribeButton");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,23 @@
private List<string> chatMessages = new List<string>();
private string wrongQueryError = "Query string with parameters 'message' and 'transport' are required";

// remove when https://github.com/dotnet/runtime/issues/96546 is fixed
// log that rendering is about to start in case we hit the issue before OnAfterRender is called
protected override bool ShouldRender()
{
bool shouldRender = base.ShouldRender();
Helper.TestOutputWriteLine($"ShouldRender = {shouldRender}");
return shouldRender;
}

protected override void OnAfterRender(bool firstRender)
{
if (firstRender)
{
Helper.TestOutputWriteLine($"OnAfterRender on CurrentManagedThreadId={Environment.CurrentManagedThreadId}");
GetQueryParameters();
}
base.OnAfterRender(firstRender);

Helper.TestOutputWriteLine($"OnAfterRender on CurrentManagedThreadId={Environment.CurrentManagedThreadId}");
GetQueryParameters();
}

private void GetQueryParameters()
Expand All @@ -49,7 +60,7 @@
}
transport = Helper.GetValue(parameters, "transport");
message = $"{transport} {Helper.GetValue(parameters, "message")}" ;
Helper.TestOutputWriteLine($"GetQueryParameters on CurrentManagedThreadId={Environment.CurrentManagedThreadId} finished");
Helper.TestOutputWriteLine($"Finished GetQueryParameters on CurrentManagedThreadId={Environment.CurrentManagedThreadId}.");
}

private async Task Connect()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
builder.RootComponents.Add<App>("#app");
builder.RootComponents.Add<HeadOutlet>("head::after");
builder.Services.AddScoped(sp => new HttpClient { BaseAddress = new Uri(builder.HostEnvironment.BaseAddress) });
builder.Logging.SetMinimumLevel(LogLevel.Debug);
ilonatommy marked this conversation as resolved.
Show resolved Hide resolved

await builder.Build().RunAsync().ConfigureAwait(false);