Skip to content

Commit

Permalink
Merge pull request #623 from zeromq/weak-napi
Browse files Browse the repository at this point in the history
test: update weak-napi's dependencies + fix expose GC in the tests
  • Loading branch information
aminya authored Jun 15, 2024
2 parents 828ed28 + 0d7c94a commit 66cf54f
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 23 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 @@ -4,6 +4,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,
}
2 changes: 1 addition & 1 deletion test/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"devDependencies": {
"@types/weak-napi": "^2.0.3",
"weak-napi": "^2.0.2"
"weak-napi": "https://github.com/aminya/weak-napi#ea97678fc4c9304eea7f3fb1ddc88eaf59cccc6f"
}
}
20 changes: 11 additions & 9 deletions test/pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
4 changes: 4 additions & 0 deletions test/unit/socket-zap-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ for (const proto of testProtos("tcp", "ipc")) {
if (semver.satisfies(zmq.version, "< 4.3.0")) {
this.skip()
}
if (zmq.capability.curve !== true) {
console.warn("Curve not supported by this zmq build")
this.skip()
}

this.slow(250)

Expand Down
3 changes: 2 additions & 1 deletion typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"test/**/*",
"examples/**/*",
"src/errors.ts",
"src/util.ts"
"src/util.ts",
"build/**/*"
],
"cleanOutputDir": true,
"pretty": false,
Expand Down

0 comments on commit 66cf54f

Please sign in to comment.