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

[wasm] Re-try when browser's WBT fail with System.TimeoutException #104481

Merged
merged 1 commit into from
Jul 8, 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
41 changes: 30 additions & 11 deletions src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,43 @@ public async Task<string> StartServerAndGetUrlAsync(

public async Task<IBrowser> SpawnBrowserAsync(
string browserUrl,
bool headless = true
bool headless = true,
int timeout = 10000,
int maxRetries = 3
) {
var url = new Uri(browserUrl);
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
// codespaces: ignore certificate error -> Microsoft.Playwright.PlaywrightException : net::ERR_CERT_AUTHORITY_INVALID
string[] chromeArgs = new[] { $"--explicitly-allowed-ports={url.Port}", "--ignore-certificate-errors" };
_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
});
Browser.Disconnected += (sender, e) =>

int attempt = 0;
while (attempt < maxRetries)
{
Browser = null;
_testOutput.WriteLine("Browser has been disconnected");
};
return Browser;
try
{
Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions {
ExecutablePath = s_chromePath.Value,
Headless = headless,
Args = chromeArgs,
Timeout = timeout
});
Browser.Disconnected += (sender, e) =>
{
Browser = null;
_testOutput.WriteLine("Browser has been disconnected");
};
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");
return Browser!;
}

// FIXME: options
Expand Down