mirror of
https://github.com/oven-sh/bun
synced 2026-02-09 10:28:47 +00:00
Test napi_add_finalizer in main thread instead of worker
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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",
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user