Skip to content
Merged
Show file tree
Hide file tree
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
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public async Task StartBrowserAndProxyAsync(HttpContext context,
// 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,
Expand Down
25 changes: 21 additions & 4 deletions src/mono/wasm/debugger/DebuggerTestSuite/DebuggerTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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));
Expand All @@ -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()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 9 additions & 3 deletions src/mono/wasm/debugger/DebuggerTestSuite/Inspector.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)));
Expand All @@ -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)
{
Expand All @@ -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")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It feels a little odd to pass an empty string just to ignore it unless it is chrome and is there ever a case where we'd try to navigate to "" on chrome?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if I understood the question.
Before this change we startup the chrome passing the url that it should navigate. And on my tests I saw that sometimes it was timing out the debugger.enable command. So I decided to first startup the chrome navigating to about:blank then send the Debugger.enabled and then when we receive the answer we send the Page.navigate to the wasm page.
On firefox we don't need to navigate to the page because we are still starting the browser passing the wasm page as parameter.

await Client.SendCommand("Page.navigate", JObject.FromObject(new { url = urlToInspect }), _cancellationTokenSource.Token);
init_cmds.RemoveAt(cmdIdx);
}

Expand Down