Skip to content

Commit 5130ba9

Browse files
thaystglewing
andauthored
[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: Larry Ewing <[email protected]> --------- Co-authored-by: Larry Ewing <[email protected]>
1 parent f70f26f commit 5130ba9

File tree

5 files changed

+33
-10
lines changed

5 files changed

+33
-10
lines changed

src/mono/wasm/debugger/DebuggerTestSuite/BadHarnessInitTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public async Task InvalidInitCommands()
3434

3535
await Ready();
3636

37-
var ae = await Assert.ThrowsAsync<ArgumentException>(async () => await insp.OpenSessionAsync(fn, TestTimeout));
37+
var ae = await Assert.ThrowsAsync<ArgumentException>(async () => await insp.OpenSessionAsync(fn, "", TestTimeout));
3838
Assert.Contains(bad_cmd_name, ae.Message);
3939
}
4040
}

src/mono/wasm/debugger/DebuggerTestSuite/ChromeProvider.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public async Task StartBrowserAndProxyAsync(HttpContext context,
5656
// for WIndows setting --lang arg is enough
5757
if (!OperatingSystem.IsWindows())
5858
Environment.SetEnvironmentVariable("LANGUAGE", locale);
59-
ProcessStartInfo psi = GetProcessStartInfo(s_browserPath.Value, GetInitParms(remoteDebuggingPort, locale), targetUrl);
59+
ProcessStartInfo psi = GetProcessStartInfo(s_browserPath.Value, GetInitParms(remoteDebuggingPort, locale), "about:blank");
6060
line = await LaunchHostAsync(
6161
psi,
6262
context,

src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,8 +64,9 @@ public static WasmHost RunningOn
6464
static string s_debuggerTestAppPath;
6565
static int s_idCounter = -1;
6666

67-
public int Id { get; init; }
68-
67+
public int Id { get; set; }
68+
public string driver;
69+
6970
public static string DebuggerTestAppPath
7071
{
7172
get
@@ -130,7 +131,7 @@ static DebuggerTestBase()
130131
Directory.Delete(TempPath, recursive: true);
131132
}
132133

133-
public DebuggerTestBase(ITestOutputHelper testOutput, string locale, string driver = "debugger-driver.html")
134+
public DebuggerTestBase(ITestOutputHelper testOutput, string locale, string _driver = "debugger-driver.html")
134135
{
135136
_env = new TestEnvironment(testOutput);
136137
_testOutput = testOutput;
@@ -141,12 +142,14 @@ public DebuggerTestBase(ITestOutputHelper testOutput, string locale, string driv
141142

142143
insp = new Inspector(Id, _testOutput);
143144
cli = insp.Client;
145+
driver = _driver;
144146
scripts = SubscribeToScripts(insp);
145147
startTask = TestHarnessProxy.Start(DebuggerTestAppPath, driver, UrlToRemoteDebugging(), testOutput, locale);
146148
}
147149

148150
public virtual async Task InitializeAsync()
149151
{
152+
bool retry = true;
150153
Func<InspectorClient, CancellationToken, List<(string, Task<Result>)>> fn = (client, token) =>
151154
{
152155
Func<string, JObject, (string, Task<Result>)> getInitCmdFn = (cmd, args) => (cmd, client.SendCommand(cmd, args, token));
@@ -164,7 +167,21 @@ public virtual async Task InitializeAsync()
164167
};
165168

166169
await Ready();
167-
await insp.OpenSessionAsync(fn, TestTimeout);
170+
try {
171+
await insp.OpenSessionAsync(fn, $"http://{TestHarnessProxy.Endpoint.Authority}/{driver}", TestTimeout);
172+
}
173+
catch (TaskCanceledException exc) //if timed out for some reason let's try again
174+
{
175+
if (!retry)
176+
throw exc;
177+
retry = false;
178+
_testOutput.WriteLine($"Let's retry: {exc.ToString()}");
179+
Id = Interlocked.Increment(ref s_idCounter);
180+
insp = new Inspector(Id, _testOutput);
181+
cli = insp.Client;
182+
scripts = SubscribeToScripts(insp);
183+
await insp.OpenSessionAsync(fn, $"http://{TestHarnessProxy.Endpoint.Authority}/{driver}", TestTimeout);
184+
}
168185
}
169186

170187
public virtual async Task DisposeAsync()

src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestFirefox.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public override async Task InitializeAsync()
3939
};
4040

4141
await Ready();
42-
await insp.OpenSessionAsync(fn, TestTimeout);
42+
await insp.OpenSessionAsync(fn, "", TestTimeout);
4343
}
4444

4545
internal override Dictionary<string, string> SubscribeToScripts(Inspector insp)

src/mono/wasm/debugger/DebuggerTestSuite/Inspector.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class Inspector
2929
ConcurrentQueue<(string, JObject)> nextNotifications = new (); //in a multithreaded runtime we can receive more than one pause at same time
3030
public const string PAUSE = "pause";
3131
public const string APP_READY = "app-ready";
32-
public CancellationToken Token { get; }
32+
public CancellationToken Token { get; set; }
3333
public InspectorClient Client { get; }
3434
public DebuggerProxyBase? Proxy { get; }
3535
public bool DetectAndFailOnAssertions { get; set; } = true;
@@ -351,13 +351,12 @@ public async Task LaunchBrowser(DateTime start, TimeSpan span)
351351
});
352352
}
353353

354-
public async Task OpenSessionAsync(Func<InspectorClient, CancellationToken, List<(string, Task<Result>)>> getInitCmds, TimeSpan span)
354+
public async Task OpenSessionAsync(Func<InspectorClient, CancellationToken, List<(string, Task<Result>)>> getInitCmds, string urlToInspect, TimeSpan span)
355355
{
356356
var start = DateTime.Now;
357357
try
358358
{
359359
await LaunchBrowser(start, span);
360-
361360
var init_cmds = getInitCmds(Client, _cancellationTokenSource.Token);
362361

363362
Task<Result> readyTask = Task.Run(async () => Result.FromJson(await WaitFor(APP_READY)));
@@ -373,7 +372,10 @@ public async Task OpenSessionAsync(Func<InspectorClient, CancellationToken, List
373372
string cmd_name = init_cmds[cmdIdx].Item1;
374373

375374
if (_isFailingWithException is not null)
375+
{
376+
_logger.LogError($"_isFailingWithException. {_isFailingWithException}.");
376377
throw _isFailingWithException;
378+
}
377379

378380
if (completedTask.IsCanceled)
379381
{
@@ -388,11 +390,15 @@ public async Task OpenSessionAsync(Func<InspectorClient, CancellationToken, List
388390
_logger.LogError($"Command {cmd_name} failed with {completedTask.Exception}. Remaining commands: {RemainingCommandsToString(cmd_name, init_cmds)}.");
389391
throw completedTask.Exception!;
390392
}
393+
391394
await Client.ProcessCommand(completedTask.Result, _cancellationTokenSource.Token);
392395
Result res = completedTask.Result;
396+
393397
if (!res.IsOk)
394398
throw new ArgumentException($"Command {cmd_name} failed with: {res.Error}. Remaining commands: {RemainingCommandsToString(cmd_name, init_cmds)}");
395399

400+
if (DebuggerTestBase.RunningOnChrome && cmd_name == "Debugger.enable")
401+
await Client.SendCommand("Page.navigate", JObject.FromObject(new { url = urlToInspect }), _cancellationTokenSource.Token);
396402
init_cmds.RemoveAt(cmdIdx);
397403
}
398404

0 commit comments

Comments
 (0)