Skip to content

Commit

Permalink
[wasm][test-browser] Add another case for retrying chromedriver launch
Browse files Browse the repository at this point in the history
In some test runs, launching chromedriver failed
with (dotnet/runtime#44862):

```
Connection refused Connection refused
Connection refused Connection refused
[00:03:37] crit: OpenQA.Selenium.WebDriverException: Cannot start the driver service on http://localhost:37245/
                    at OpenQA.Selenium.DriverService.Start()
                    at OpenQA.Selenium.Remote.DriverServiceCommandExecutor.Execute(Command commandToExecute)
                    at OpenQA.Selenium.Remote.RemoteWebDriver.Execute(String driverCommandToExecute, Dictionary`2 parameters)
                    at OpenQA.Selenium.Remote.RemoteWebDriver.StartSession(ICapabilities desiredCapabilities)
                    at OpenQA.Selenium.Remote.RemoteWebDriver..ctor(ICommandExecutor commandExecutor, ICapabilities desiredCapabilities)
                    at OpenQA.Selenium.Chromium.ChromiumDriver..ctor(ChromiumDriverService service, ChromiumOptions options, TimeSpan commandTimeout)
                    at OpenQA.Selenium.Chrome.ChromeDriver..ctor(ChromeDriverService service, ChromeOptions options, TimeSpan commandTimeout)
                    at Microsoft.DotNet.XHarness.CLI.Commands.Wasm.WasmTestBrowserCommand.GetChromeDriver(ILogger logger) in /_/src/Microsoft.DotNet.XHarness.CLI/Commands/WASM/Browser/WasmTestBrowserCommand.cs:line 110
                    at Microsoft.DotNet.XHarness.CLI.Commands.Wasm.WasmTestBrowserCommand.InvokeInternal(ILogger logger) in /_/src/Microsoft.DotNet.XHarness.CLI/Commands/WASM/Browser/WasmTestBrowserCommand.cs:line 53
                    at Microsoft.DotNet.XHarness.Common.CLI.Commands.XHarnessCommand.Invoke(IEnumerable`1 arguments) in /_/src/Microsoft.DotNet.XHarness.Common/CLI/Commands/XHarnessCommand.cs:line 120
XHarness exit code: 71
```

As a way to handle this, we'll retry if the exception message contains
the string `"Cannot start the driver service"`.
  • Loading branch information
radical committed Nov 20, 2020
1 parent 8a4b8b3 commit 79aad37
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using OpenQA.Selenium.Chrome;
using SeleniumLogLevel = OpenQA.Selenium.LogLevel;
using OpenQA.Selenium;
using System.Linq;

namespace Microsoft.DotNet.XHarness.CLI.Commands.Wasm
{
Expand Down Expand Up @@ -101,6 +102,12 @@ protected override async Task<ExitCode> InvokeInternal(ILogger logger)
//
// So -> use a larger timeout!

string[] err_snippets = new []
{
"exited abnormally",
"Cannot start the driver service"
};

int max_retries = 3;
int retry_num = 0;
while(true)
Expand All @@ -109,11 +116,11 @@ protected override async Task<ExitCode> InvokeInternal(ILogger logger)
{
return (driverService, new ChromeDriver(driverService, options, _arguments.Timeout));
}
catch (WebDriverException wde) when (wde.Message.Contains("exited abnormally") && retry_num < max_retries - 1)
catch (WebDriverException wde) when (err_snippets.Any(s => wde.Message.Contains(s)) && retry_num < max_retries - 1)
{
// chrome can sometimes crash on startup when launching from chromedriver.
// As a *workaround*, let's retry that a few times
// Error seen:
// Example error seen:
// [12:41:07] crit: OpenQA.Selenium.WebDriverException: unknown error: Chrome failed to start: exited abnormally.
// (chrome not reachable)

Expand Down

0 comments on commit 79aad37

Please sign in to comment.