fix crash handler test failures (#12932)

This commit is contained in:
dave caruso
2024-07-30 16:52:59 -07:00
committed by GitHub
parent 848ad19d9e
commit ebc7045ca4
2 changed files with 16 additions and 2 deletions

View File

@@ -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,
};

View File

@@ -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") {