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

[browser] Increase timeout and clean up after failed attempts of launching browser when testing #107865

Closed
wants to merge 34 commits into from
Closed
Changes from 4 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
a6d7f7a
Increase timeout + clean up before next attempt.
ilonatommy Sep 16, 2024
180fe0e
Prepare for cleanup to fail.
ilonatommy Sep 16, 2024
50b077a
Log more than just the message.
ilonatommy Sep 16, 2024
87fe62b
Update src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
lewing Sep 16, 2024
197fe7d
Check if other chrome instances are running and forcefully close them.
ilonatommy Sep 17, 2024
9093136
Missing namespace
ilonatommy Sep 17, 2024
e8d3636
Merge branch 'main' into fix-107771
ilonatommy Sep 19, 2024
e7798a5
Merge branch 'main' into fix-107771
ilonatommy Sep 19, 2024
7c540c7
Merge branch 'main' into fix-107771
lewing Sep 21, 2024
9608d0c
Merge branch 'main' into fix-107771
ilonatommy Sep 23, 2024
d837c9f
Don't terminate if tests run in parallel.
ilonatommy Sep 23, 2024
a817b0c
Merge branch 'main' into fix-107771
ilonatommy Sep 26, 2024
91077dd
Elevate Playwright logs.
ilonatommy Sep 26, 2024
1b2b569
Merge error.
ilonatommy Sep 26, 2024
236b693
Merge branch 'main' into fix-107771
ilonatommy Sep 27, 2024
4d1dd6f
Bump playwright, previous was > 2 years old.
ilonatommy Sep 30, 2024
a26687d
Switch off debugging to restore failure observability.
ilonatommy Sep 30, 2024
6221f7e
Merge branch 'main' into fix-107771
ilonatommy Sep 30, 2024
414e7cd
Too new version, changing to the nearest available.
ilonatommy Sep 30, 2024
80cc9bf
Acoid "Permission denied" on node on CI.
ilonatommy Sep 30, 2024
76170dd
Fix condition for detecting unix.
ilonatommy Sep 30, 2024
312b537
Fix the syntax for OR.
ilonatommy Sep 30, 2024
fe3d5cb
Debug Agent.OS
ilonatommy Sep 30, 2024
40e18ea
More debugging
ilonatommy Oct 1, 2024
ea9853e
Azure condition is evaluated correctly, move it to bash that works fine.
ilonatommy Oct 1, 2024
415773b
Wrong path
ilonatommy Oct 1, 2024
25e088d
Fix the reason for failure: 'linux' changed to 'linux-x64'
ilonatommy Oct 1, 2024
54ccd98
Dump env variables.
ilonatommy Oct 1, 2024
4cec530
Go back to default timeout + give up on our own chrome.
ilonatommy Oct 1, 2024
5988c90
Nullable
ilonatommy Oct 1, 2024
2289c01
Trying to fix default chromium on linux
ilonatommy Oct 2, 2024
1fa0a83
Merge branch 'main' into fix-107771
ilonatommy Oct 2, 2024
ab4bcc6
Merge branch 'main' into fix-107771
ilonatommy Oct 2, 2024
0de13d2
Merge branch 'main' into fix-107771
ilonatommy Oct 3, 2024
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
31 changes: 24 additions & 7 deletions src/mono/wasm/Wasm.Build.Tests/BrowserRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,10 @@ public async Task<string> StartServerAndGetUrlAsync(
public async Task<IBrowser> SpawnBrowserAsync(
string browserUrl,
bool headless = true,
int timeout = 10000,
int timeout = 15000,
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)}");
Expand All @@ -117,6 +116,7 @@ public async Task<IBrowser> SpawnBrowserAsync(
{
try
{
Playwright = await Microsoft.Playwright.Playwright.CreateAsync();
Browser = await Playwright.Chromium.LaunchAsync(new BrowserTypeLaunchOptions {
ExecutablePath = s_chromePath.Value,
Headless = headless,
Expand All @@ -128,17 +128,34 @@ public async Task<IBrowser> SpawnBrowserAsync(
Browser = null;
_testOutput.WriteLine("Browser has been disconnected");
};
break;
return Browser!;
}
catch (System.TimeoutException ex)
{
attempt++;
_testOutput.WriteLine($"Attempt {attempt} failed with TimeoutException: {ex.Message}");
_testOutput.WriteLine($"Attempt {attempt} failed with TimeoutException: {ex}");

try
{
// Cleanup before retrying
if (Browser != null)
{
await Browser.CloseAsync();
Browser = null;
}
if (Playwright != null)
{
Playwright.Dispose();
Playwright = null;
}
}
catch(Exception cleanupException)
{
_testOutput.WriteLine($"Attempt to clean up failed with {cleanupException}");
}
}
}
if (attempt == maxRetries)
throw new Exception($"Failed to launch browser after {maxRetries} attempts");
return Browser!;
throw new Exception($"Failed to launch browser after {maxRetries} attempts");
}

// FIXME: options
Expand Down
Loading