未验证 提交 5130ba98 编写于 作者: T Thays Grazia 提交者: GitHub

[wasm][debugger] Retry after timeout on debugger tests on CI (#84080)

* retrying if timeout OpenSessionAsync.
* Update src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs
Co-authored-by: NLarry Ewing <lewing@microsoft.com>

---------
Co-authored-by: NLarry Ewing <lewing@microsoft.com>
上级 f70f26f6
......@@ -34,7 +34,7 @@ public async Task InvalidInitCommands()
await Ready();
var ae = await Assert.ThrowsAsync<ArgumentException>(async () => await insp.OpenSessionAsync(fn, TestTimeout));
var ae = await Assert.ThrowsAsync<ArgumentException>(async () => await insp.OpenSessionAsync(fn, "", TestTimeout));
Assert.Contains(bad_cmd_name, ae.Message);
}
}
......
......@@ -56,7 +56,7 @@ public ChromeProvider(string id, ILogger logger) : base(id, logger)
// for WIndows setting --lang arg is enough
if (!OperatingSystem.IsWindows())
Environment.SetEnvironmentVariable("LANGUAGE", locale);
ProcessStartInfo psi = GetProcessStartInfo(s_browserPath.Value, GetInitParms(remoteDebuggingPort, locale), targetUrl);
ProcessStartInfo psi = GetProcessStartInfo(s_browserPath.Value, GetInitParms(remoteDebuggingPort, locale), "about:blank");
line = await LaunchHostAsync(
psi,
context,
......
......@@ -64,8 +64,9 @@ public static WasmHost RunningOn
static string s_debuggerTestAppPath;
static int s_idCounter = -1;
public int Id { get; init; }
public int Id { get; set; }
public string driver;
public static string DebuggerTestAppPath
{
get
......@@ -130,7 +131,7 @@ static DebuggerTestBase()
Directory.Delete(TempPath, recursive: true);
}
public DebuggerTestBase(ITestOutputHelper testOutput, string locale, string driver = "debugger-driver.html")
public DebuggerTestBase(ITestOutputHelper testOutput, string locale, string _driver = "debugger-driver.html")
{
_env = new TestEnvironment(testOutput);
_testOutput = testOutput;
......@@ -141,12 +142,14 @@ public DebuggerTestBase(ITestOutputHelper testOutput, string locale, string driv
insp = new Inspector(Id, _testOutput);
cli = insp.Client;
driver = _driver;
scripts = SubscribeToScripts(insp);
startTask = TestHarnessProxy.Start(DebuggerTestAppPath, driver, UrlToRemoteDebugging(), testOutput, locale);
}
public virtual async Task InitializeAsync()
{
bool retry = true;
Func<InspectorClient, CancellationToken, List<(string, Task<Result>)>> fn = (client, token) =>
{
Func<string, JObject, (string, Task<Result>)> getInitCmdFn = (cmd, args) => (cmd, client.SendCommand(cmd, args, token));
......@@ -164,7 +167,21 @@ public virtual async Task InitializeAsync()
};
await Ready();
await insp.OpenSessionAsync(fn, TestTimeout);
try {
await insp.OpenSessionAsync(fn, $"http://{TestHarnessProxy.Endpoint.Authority}/{driver}", TestTimeout);
}
catch (TaskCanceledException exc) //if timed out for some reason let's try again
{
if (!retry)
throw exc;
retry = false;
_testOutput.WriteLine($"Let's retry: {exc.ToString()}");
Id = Interlocked.Increment(ref s_idCounter);
insp = new Inspector(Id, _testOutput);
cli = insp.Client;
scripts = SubscribeToScripts(insp);
await insp.OpenSessionAsync(fn, $"http://{TestHarnessProxy.Endpoint.Authority}/{driver}", TestTimeout);
}
}
public virtual async Task DisposeAsync()
......
......@@ -39,7 +39,7 @@ public override async Task InitializeAsync()
};
await Ready();
await insp.OpenSessionAsync(fn, TestTimeout);
await insp.OpenSessionAsync(fn, "", TestTimeout);
}
internal override Dictionary<string, string> SubscribeToScripts(Inspector insp)
......
......@@ -29,7 +29,7 @@ class Inspector
ConcurrentQueue<(string, JObject)> nextNotifications = new (); //in a multithreaded runtime we can receive more than one pause at same time
public const string PAUSE = "pause";
public const string APP_READY = "app-ready";
public CancellationToken Token { get; }
public CancellationToken Token { get; set; }
public InspectorClient Client { get; }
public DebuggerProxyBase? Proxy { get; }
public bool DetectAndFailOnAssertions { get; set; } = true;
......@@ -351,13 +351,12 @@ public async Task LaunchBrowser(DateTime start, TimeSpan span)
});
}
public async Task OpenSessionAsync(Func<InspectorClient, CancellationToken, List<(string, Task<Result>)>> getInitCmds, TimeSpan span)
public async Task OpenSessionAsync(Func<InspectorClient, CancellationToken, List<(string, Task<Result>)>> getInitCmds, string urlToInspect, TimeSpan span)
{
var start = DateTime.Now;
try
{
await LaunchBrowser(start, span);
var init_cmds = getInitCmds(Client, _cancellationTokenSource.Token);
Task<Result> readyTask = Task.Run(async () => Result.FromJson(await WaitFor(APP_READY)));
......@@ -373,7 +372,10 @@ public async Task OpenSessionAsync(Func<InspectorClient, CancellationToken, List
string cmd_name = init_cmds[cmdIdx].Item1;
if (_isFailingWithException is not null)
{
_logger.LogError($"_isFailingWithException. {_isFailingWithException}.");
throw _isFailingWithException;
}
if (completedTask.IsCanceled)
{
......@@ -388,11 +390,15 @@ public async Task OpenSessionAsync(Func<InspectorClient, CancellationToken, List
_logger.LogError($"Command {cmd_name} failed with {completedTask.Exception}. Remaining commands: {RemainingCommandsToString(cmd_name, init_cmds)}.");
throw completedTask.Exception!;
}
await Client.ProcessCommand(completedTask.Result, _cancellationTokenSource.Token);
Result res = completedTask.Result;
if (!res.IsOk)
throw new ArgumentException($"Command {cmd_name} failed with: {res.Error}. Remaining commands: {RemainingCommandsToString(cmd_name, init_cmds)}");
if (DebuggerTestBase.RunningOnChrome && cmd_name == "Debugger.enable")
await Client.SendCommand("Page.navigate", JObject.FromObject(new { url = urlToInspect }), _cancellationTokenSource.Token);
init_cmds.RemoveAt(cmdIdx);
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册