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

[release/8.0-staging][browser] Fix WBT timeout (30000ms exceeded) #104947

Merged
merged 2 commits into from
Jul 16, 2024
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
34 changes: 26 additions & 8 deletions src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,9 @@ public async Task<IPage> RunAsync(
bool headless = true,
Action<IConsoleMessage>? onConsoleMessage = null,
Action<string>? onError = null,
Func<string, string>? modifyBrowserUrl = null)
Func<string, string>? modifyBrowserUrl = null,
int timeout = 10000,
int maxRetries = 3)
{
TaskCompletionSource<string> urlAvailable = new();
Action<string?> outputHandler = msg =>
Expand Down Expand Up @@ -89,17 +91,33 @@ public async Task<IPage> RunAsync(
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}" };
_testOutput.WriteLine($"Launching chrome ('{s_chromePath.Value}') via playwright with args = {string.Join(',', chromeArgs)}");
Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions{
ExecutablePath = s_chromePath.Value,
Headless = headless,
Args = chromeArgs
});

int attempt = 0;
while (attempt < maxRetries)
{
try
{
Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions{
ExecutablePath = s_chromePath.Value,
Headless = headless,
Args = chromeArgs,
Timeout = timeout
});
break;
}
catch (System.TimeoutException ex)
{
attempt++;
_testOutput.WriteLine($"Attempt {attempt} failed with TimeoutException: {ex.Message}");
}
}
if (attempt == maxRetries)
throw new Exception($"Failed to launch browser after {maxRetries} attempts");

string browserUrl = urlAvailable.Task.Result;
if (modifyBrowserUrl != null)
browserUrl = modifyBrowserUrl(browserUrl);

IPage page = await Browser.NewPageAsync();
IPage page = await Browser!.NewPageAsync();
if (onConsoleMessage is not null)
page.Console += (_, msg) => onConsoleMessage(msg);

Expand Down
Loading