Skip to content

Commit 0d7c94a

Browse files
committed
test: require gc definition in GC tests
1 parent 3095787 commit 0d7c94a

File tree

3 files changed

+16
-12
lines changed

3 files changed

+16
-12
lines changed

.github/workflows/CI.yml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,7 @@ jobs:
160160
timeout_minutes: 5
161161
max_attempts: 1
162162
command: |
163-
pnpm run clean
164-
pnpm run test.skip_gc_tests
163+
pnpm run test
165164
continue-on-error: true
166165

167166
- name: Test Electron (Main)
@@ -173,7 +172,6 @@ jobs:
173172
command: |
174173
sudo apt-get install xvfb
175174
pnpm install -g electron@latest
176-
pnpm run clean
177175
xvfb-run --auto-servernum pnpm run test.electron.main
178176
continue-on-error: true
179177

@@ -184,6 +182,5 @@ jobs:
184182
timeout_minutes: 5
185183
max_attempts: 1
186184
command: |
187-
pnpm run clean
188185
pnpm run test
189186
continue-on-error: true

.mocharc.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
module.exports = {
44
require: ["ts-node/register", "rocha"],
55
spec: ["test/unit/*-test.ts", "test/unit/compat/*-test.{ts,js}"],
6+
"expose-gc": true,
67
"v8-expose-gc": true,
78
"experimental-worker": true,
89
recursive: true,

test/unit/socket-close-test.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,14 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
107107
})
108108

109109
it("should release reference to context", async function () {
110-
if (process.env.SKIP_GC_TESTS) {
110+
if (process.env.SKIP_GC_TESTS === "true") {
111111
this.skip()
112112
}
113+
if (global.gc === undefined) {
114+
console.warn("gc is not exposed by the runtime")
115+
this.skip()
116+
}
117+
113118
this.slow(200)
114119

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

127-
global.gc?.()
132+
global.gc!()
128133
socket.connect(uniqAddress(proto))
129134
await socket.send(Buffer.from("foo"))
130135
socket.close()
131136
}
132137

133138
await task()
134-
global.gc?.()
139+
global.gc()
135140
await new Promise(resolve => {
136141
setTimeout(resolve, 5)
137142
})
@@ -141,10 +146,11 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
141146

142147
describe("in gc finalizer", function () {
143148
it("should release reference to context", async function () {
144-
if (process.env.SKIP_GC_TESTS) {
149+
if (process.env.SKIP_GC_TESTS === "true") {
145150
this.skip()
146151
}
147-
if (process.env.SKIP_GC_FINALIZER_TESTS) {
152+
if (global.gc === undefined) {
153+
console.warn("gc is not exposed by the runtime")
148154
this.skip()
149155
}
150156
this.slow(200)
@@ -155,17 +161,17 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
155161
const task = async () => {
156162
let context: zmq.Context | undefined = new zmq.Context()
157163

158-
new zmq.Dealer({context, linger: 0})
164+
const _dealer = new zmq.Dealer({context, linger: 0})
159165

160166
weak(context, () => {
161167
released = true
162168
})
163169
context = undefined
164-
global.gc?.()
170+
global.gc!()
165171
}
166172

167173
await task()
168-
global.gc?.()
174+
global.gc()
169175
await new Promise(resolve => {
170176
setTimeout(resolve, 5)
171177
})

0 commit comments

Comments
 (0)