Skip to content

Commit

Permalink
test: require gc definition in GC tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aminya committed Jun 15, 2024
1 parent 3095787 commit 0d7c94a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ jobs:
timeout_minutes: 5
max_attempts: 1
command: |
pnpm run clean
pnpm run test.skip_gc_tests
pnpm run test
continue-on-error: true

- name: Test Electron (Main)
Expand All @@ -173,7 +172,6 @@ jobs:
command: |
sudo apt-get install xvfb
pnpm install -g electron@latest
pnpm run clean
xvfb-run --auto-servernum pnpm run test.electron.main
continue-on-error: true

Expand All @@ -184,6 +182,5 @@ jobs:
timeout_minutes: 5
max_attempts: 1
command: |
pnpm run clean
pnpm run test
continue-on-error: true
1 change: 1 addition & 0 deletions .mocharc.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
module.exports = {
require: ["ts-node/register", "rocha"],
spec: ["test/unit/*-test.ts", "test/unit/compat/*-test.{ts,js}"],
"expose-gc": true,
"v8-expose-gc": true,
"experimental-worker": true,
recursive: true,
Expand Down
22 changes: 14 additions & 8 deletions test/unit/socket-close-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,14 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
})

it("should release reference to context", async function () {
if (process.env.SKIP_GC_TESTS) {
if (process.env.SKIP_GC_TESTS === "true") {
this.skip()
}
if (global.gc === undefined) {
console.warn("gc is not exposed by the runtime")
this.skip()
}

this.slow(200)

const weak = require("weak-napi") as typeof import("weak-napi")
Expand All @@ -124,14 +129,14 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
})
context = undefined

global.gc?.()
global.gc!()
socket.connect(uniqAddress(proto))
await socket.send(Buffer.from("foo"))
socket.close()
}

await task()
global.gc?.()
global.gc()
await new Promise(resolve => {
setTimeout(resolve, 5)
})
Expand All @@ -141,10 +146,11 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {

describe("in gc finalizer", function () {
it("should release reference to context", async function () {
if (process.env.SKIP_GC_TESTS) {
if (process.env.SKIP_GC_TESTS === "true") {
this.skip()
}
if (process.env.SKIP_GC_FINALIZER_TESTS) {
if (global.gc === undefined) {
console.warn("gc is not exposed by the runtime")
this.skip()
}
this.slow(200)
Expand All @@ -155,17 +161,17 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
const task = async () => {
let context: zmq.Context | undefined = new zmq.Context()

new zmq.Dealer({context, linger: 0})
const _dealer = new zmq.Dealer({context, linger: 0})

weak(context, () => {
released = true
})
context = undefined
global.gc?.()
global.gc!()
}

await task()
global.gc?.()
global.gc()
await new Promise(resolve => {
setTimeout(resolve, 5)
})
Expand Down

0 comments on commit 0d7c94a

Please sign in to comment.