Skip to content

Commit

Permalink
[wasm][debugger] Fix some flaky tests (#64652)
Browse files Browse the repository at this point in the history
  • Loading branch information
radical committed Feb 2, 2022
1 parent 012711f commit 3a77a6d
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 57 deletions.
48 changes: 1 addition & 47 deletions src/mono/wasm/debugger/DebuggerTestSuite/ArrayTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -551,14 +551,12 @@ public async Task InspectValueTypeArrayLocalsInAsyncInstanceStructMethod(bool us
label: "this#0");
}

#if false // https://github.com/dotnet/runtime/issues/63560
[Fact]
public async Task InvalidArrayId() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.Container", "PlaceholderMethod", 1, "PlaceholderMethod",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.ArrayTestsClass:ObjectArrayMembers'); }, 1);",
wait_for_event_fn: async (pause_location) =>
{
int frame_idx = 1;
var frame_locals = await GetProperties(pause_location["callFrames"][frame_idx]["callFrameId"].Value<string>());
var c_obj = GetAndAssertObjectWithName(frame_locals, "c");
Expand All @@ -568,56 +566,12 @@ public async Task InspectValueTypeArrayLocalsInAsyncInstanceStructMethod(bool us
// Invalid format
await GetProperties("dotnet:array:4123", expect_ok: false);
// Invalid object id
await GetProperties("dotnet:array:{ \"arrayId\": 234980 }", expect_ok: false);
// Trying to access object as an array
if (!DotnetObjectId.TryParse(c_obj_id, out var id) || id.Scheme != "object")
Assert.True(false, "Unexpected object id format. Maybe this test is out of sync with the object id format in dotnet.cjs.lib.js?");
if (!int.TryParse(id.Value, out var idNum))
Assert.True(false, "Expected a numeric value part of the object id: {c_obj_id}");
await GetProperties($"dotnet:array:{{\"arrayId\":{idNum}}}", expect_ok: false);
});

[Fact]
public async Task InvalidValueTypeArrayIndex() => await CheckInspectLocalsAtBreakpointSite(
"DebuggerTests.Container", "PlaceholderMethod", 1, "PlaceholderMethod",
"window.setTimeout(function() { invoke_static_method ('[debugger-test] DebuggerTests.ArrayTestsClass:ObjectArrayMembers'); }, 1);",
locals_fn: async (locals) =>
{
var this_obj = GetAndAssertObjectWithName(locals, "this");
var c_obj = GetAndAssertObjectWithName(await GetProperties(this_obj["value"]["objectId"].Value<string>()), "c");
var c_obj_id = c_obj["value"]?["objectId"]?.Value<string>();
Assert.NotNull(c_obj_id);
var c_props = await GetProperties(c_obj_id);
var pf_arr = GetAndAssertObjectWithName(c_props, "PointsField");
var pf_arr_elems = await GetProperties(pf_arr["value"]["objectId"].Value<string>());
if (!DotnetObjectId.TryParse(pf_arr_elems[0]["value"]?["objectId"]?.Value<string>(), out var id))
Assert.True(false, "Couldn't parse objectId for PointsFields' elements");
AssertEqual("valuetype", id.Scheme, "Expected a valuetype id");
var id_args = id.ValueAsJson;
Assert.True(id_args["arrayId"] != null, "ObjectId format for array seems to have changed. Expected to find 'arrayId' in the value. Update this test");
Assert.True(id_args != null, "Expected to get a json as the value part of {id}");
// Try one valid query, to confirm that the id format hasn't changed!
id_args["arrayIdx"] = 0;
await GetProperties($"dotnet:valuetype:{id_args.ToString(Newtonsoft.Json.Formatting.None)}", expect_ok: true);
id_args["arrayIdx"] = 12399;
await GetProperties($"dotnet:valuetype:{id_args.ToString(Newtonsoft.Json.Formatting.None)}", expect_ok: false);
id_args["arrayIdx"] = -1;
await GetProperties($"dotnet:valuetype:{id_args.ToString(Newtonsoft.Json.Formatting.None)}", expect_ok: false);
id_args["arrayIdx"] = "qwe";
await GetProperties($"dotnet:valuetype:{id_args.ToString(Newtonsoft.Json.Formatting.None)}", expect_ok: false);
await GetProperties($"dotnet:array:{id.Value}", expect_ok: false);
});
#endif

[Fact]
public async Task InvalidAccessors() => await CheckInspectLocalsAtBreakpointSite(
Expand Down
11 changes: 1 addition & 10 deletions src/mono/wasm/debugger/DebuggerTestSuite/HarnessTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,14 @@ public async Task TimedOutWaitingForInvalidBreakpoint()
public async Task ExceptionThrown()
{
var ae = await Assert.ThrowsAsync<ArgumentException>(
async () => await EvaluateAndCheck("window.setTimeout(function() { non_existant_fn(); }, 1);", null, -1, -1, null));
async () => await EvaluateAndCheck("window.setTimeout(function() { non_existant_fn(); }, 3000);", null, -1, -1, null));
Assert.Contains("non_existant_fn is not defined", ae.Message);
}

[Fact]
public async Task BrowserCrash() => await Assert.ThrowsAsync<WebSocketException>(async () =>
await SendCommandAndCheck(null, "Browser.crash", null, -1, -1, null));

[Fact]
public async Task BrowserClose()
{
ArgumentException ae = await Assert.ThrowsAsync<ArgumentException>(async () =>
await SendCommandAndCheck(null, "Browser.close", null, -1, -1, null));
Assert.Contains("Inspector.detached", ae.Message);
Assert.Contains("target_close", ae.Message);
}

[Fact]
public async Task InspectorWaitForAfterMessageAlreadyReceived()
{
Expand Down

0 comments on commit 3a77a6d

Please sign in to comment.