Test napi_add_finalizer in main thread instead of worker

This commit is contained in:
Ben Grant
2025-03-27 16:02:04 -07:00
parent 3d2a34a94c
commit af7b98953c
2 changed files with 10 additions and 18 deletions

View File

@@ -619,21 +619,12 @@ nativeTests.test_get_value_string = () => {
}
};
nativeTests.test_worker_throw_with_finalizer = () => {
const { promise, resolve, reject } = Promise.withResolvers();
const worker = new Worker(
/* js */ `
import { createRequire } from "node:module";
const require = createRequire(import.meta.url);
const { add_finalizer_to_object } = require("./build/Debug/napitests.node");
let object = {};
add_finalizer_to_object(object);
`,
{ eval: true },
);
worker.on("exit", resolve);
worker.on("error", reject);
return promise;
// Should be run with
// BUN_DESTRUCT_VM_ON_EXIT=1 -- makes us tear down the JSC::VM while exiting, so that finalizers run
// BUN_JSC_useGC=0 -- ensures the object's finalizer will be called at exit not during normal GC
nativeTests.test_finalizer_called_during_destruction = () => {
let object = {};
nativeTests.add_finalizer_to_object(object);
};
module.exports = nativeTests;

View File

@@ -1,6 +1,6 @@
import { spawnSync } from "bun";
import { beforeAll, describe, expect, it } from "bun:test";
import { bunEnv, bunExe, tempDirWithFiles } from "harness";
import { bunEnv, bunExe, isBroken, tempDirWithFiles } from "harness";
import { join } from "path";
describe("napi", () => {
@@ -455,8 +455,9 @@ describe("napi", () => {
});
describe("napi_add_finalizer", () => {
it("does not crash if the finalizer is called during VM shutdown", () => {
checkSameOutput("test_worker_throw_with_finalizer", [], {
it.todoIf(isBroken)("does not crash if the finalizer is called during VM shutdown", () => {
checkSameOutput("test_finalizer_called_during_destruction", [], {
BUN_DESTRUCT_VM_ON_EXIT: "1",
BUN_JSC_useGC: "0",
});
});