From ebc7045ca4d99789aff2e9daabbeadd308655ee2 Mon Sep 17 00:00:00 2001 From: dave caruso Date: Tue, 30 Jul 2024 16:52:59 -0700 Subject: [PATCH] fix crash handler test failures (#12932) --- src/crash_handler.zig | 6 +++++- test/cli/run/run-crash-handler.test.ts | 12 +++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/src/crash_handler.zig b/src/crash_handler.zig index 26e714efcfd119..937df618debd01 100644 --- a/src/crash_handler.zig +++ b/src/crash_handler.zig @@ -993,7 +993,11 @@ const StackLine = struct { .address = @intCast(addr - base_address), .object = if (!std.mem.eql(u16, name, image_path)) name: { - const basename = name[std.mem.lastIndexOfAny(u16, name, &[_]u16{ '\\', '/' }) orelse 0 ..]; + const basename = name[if (std.mem.lastIndexOfAny(u16, name, &[_]u16{ '\\', '/' })) |i| + // skip the last slash + i + 1 + else + 0..]; break :name bun.strings.convertUTF16toUTF8InBuffer(name_bytes, basename) catch null; } else null, }; diff --git a/test/cli/run/run-crash-handler.test.ts b/test/cli/run/run-crash-handler.test.ts index 4923c6f06d4d0c..3baf18539fa735 100644 --- a/test/cli/run/run-crash-handler.test.ts +++ b/test/cli/run/run-crash-handler.test.ts @@ -13,11 +13,13 @@ test.if(process.platform === "darwin")("macOS has the assumed image offset", () test("raise ignoring panic handler does not trigger the panic handler", async () => { let sent = false; + const resolve_handler = Promise.withResolvers(); using server = Bun.serve({ port: 0, fetch(request, server) { sent = true; + resolve_handler.resolve(); return new Response("OK"); }, }); @@ -33,6 +35,11 @@ test("raise ignoring panic handler does not trigger the panic handler", async () ]), }); + await proc.exited; + + /// Wait two seconds for a slow http request, or continue immediatly once the request is heard. + await Promise.race([resolve_handler.promise, Bun.sleep(2000)]); + expect(proc.exited).resolves.not.toBe(0); expect(sent).toBe(false); }); @@ -41,6 +48,7 @@ describe("automatic crash reporter", () => { for (const approach of ["panic", "segfault", "outOfMemory"]) { test(`${approach} should report`, async () => { let sent = false; + const resolve_handler = Promise.withResolvers(); // Self host the crash report backend. using server = Bun.serve({ @@ -48,6 +56,7 @@ describe("automatic crash reporter", () => { fetch(request, server) { expect(request.url).toEndWith("/ack"); sent = true; + resolve_handler.resolve(); return new Response("OK"); }, }); @@ -67,9 +76,10 @@ describe("automatic crash reporter", () => { }); const exitCode = await proc.exited; const stderr = await Bun.readableStreamToText(proc.stderr); - console.log(stderr); + await resolve_handler.promise; + expect(exitCode).not.toBe(0); expect(stderr).toContain(server.url.toString()); if (approach !== "outOfMemory") {