Skip to content

Commit

Permalink
fix crash handler test failures (#12932)
Browse files Browse the repository at this point in the history
  • Loading branch information
paperclover authored Jul 30, 2024
1 parent 848ad19 commit ebc7045
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
6 changes: 5 additions & 1 deletion src/crash_handler.zig
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down
12 changes: 11 additions & 1 deletion test/cli/run/run-crash-handler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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");
},
});
Expand All @@ -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);
});
Expand All @@ -41,13 +48,15 @@ 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({
port: 0,
fetch(request, server) {
expect(request.url).toEndWith("/ack");
sent = true;
resolve_handler.resolve();
return new Response("OK");
},
});
Expand All @@ -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") {
Expand Down

0 comments on commit ebc7045

Please sign in to comment.