Skip to content

Commit

Permalink
Merge pull request #620 from zeromq/test-endpoints
Browse files Browse the repository at this point in the history
test: fix the ipc endpoint tests
  • Loading branch information
aminya committed Jun 14, 2024
2 parents b675b0a + 3d54dba commit ec1a72d
Show file tree
Hide file tree
Showing 9 changed files with 32 additions and 22 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@ jobs:
docker: node:18-alpine
docker_cmd:
apk add --no-cache pkgconfig curl tar python3 make gcc g++ cmake
musl-dev && npm i -g pnpm && pnpm install && pnpm run build.prebuild
musl-dev && npm i -g pnpm && pnpm install && pnpm run
build.prebuild
node_version: 18
node_arch: x64
ARCH: x64
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@
"scripts": {
"install": "(shx test -f ./script/build.js || run-s build.js) && cross-env npm_config_build_from_source=true aminya-node-gyp-build",
"clean": "shx rm -rf ./build ./lib/ ./prebuilds ./script/*.js ./script/*.js.map ./script/*.d.ts ./script/*.tsbuildinfo",
"clean.temp": "shx rm -rf ./tmp && shx mkdir -p ./tmp && shx touch ./tmp/.gitkeep",
"clean.temp": "shx rm -rf ./tmp && shx mkdir -p ./tmp",
"build.library": "tsc -p ./src/tsconfig.json",
"build.script": "tsc -p ./script/tsconfig.json && tsc -p ./script/tsconfig.esm.json",
"build.js": "run-p build.script build.library",
Expand All @@ -94,9 +94,9 @@
"build": "run-s build.js build.native",
"build.debug": "run-s build.js build.native.debug",
"test.deps": "cd test && pnpm install && cd ..",
"test": "run-s test.deps build && mocha --exit",
"test.skip_gc_tests": "run-s test.deps build.debug && cross-env SKIP_GC_TESTS=true mocha --exit",
"test.electron.main": "run-s test.deps build && electron-mocha",
"test": "run-s clean.temp test.deps build && mocha",
"test.skip_gc_tests": "run-s clean.temp test.deps build.debug && cross-env SKIP_GC_TESTS=true mocha",
"test.electron.main": "run-s clean.temp test.deps build && electron-mocha",
"format": "prettier --write .",
"test.electron.renderer": "run-s build && electron-mocha --renderer",
"lint.clang-format": "clang-format -i -style=file ./src/*.cc ./src/*.h ./src/util/*.h",
Expand Down
2 changes: 1 addition & 1 deletion script/tsconfig.esm.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"extends": "./tsconfig.json",
"compilerOptions": {
"module": "ESNext",
"moduleResolution": "node",
"moduleResolution": "node"
},
"include": ["./**/*.mts"],
"exclude": []
Expand Down
2 changes: 1 addition & 1 deletion src/util/error.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ static inline Napi::Error ErrnoException(

static inline Napi::Error ErrnoException(
const Napi::Env& env, int32_t error, const std::string& address) {
auto exception = ErrnoException(env, error);
auto exception = ErrnoException(env, error, nullptr);
exception.Set("address", Napi::String::New(env, address));
return exception;
}
Expand Down
5 changes: 5 additions & 0 deletions test/unit/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import * as path from "path"
import * as semver from "semver"
import * as fs from "fs"

import {spawn} from "child_process"

Expand All @@ -21,13 +22,17 @@ export function uniqAddress(proto: Proto) {
switch (proto) {
case "ipc": {
const sock = path.resolve(__dirname, `../../tmp/${proto}-${id}`)
// create the directory
fs.mkdirSync(path.dirname(sock), {recursive: true})

return `${proto}://${sock}`
}

case "tcp":
case "udp":
return `${proto}://127.0.0.1:${id}`

case "inproc":
default:
return `${proto}://${proto}-${id}`
}
Expand Down
12 changes: 7 additions & 5 deletions test/unit/proxy-router-dealer-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ import {testProtos, uniqAddress} from "./helpers"

for (const proto of testProtos("tcp", "ipc", "inproc")) {
describe(`proxy with ${proto} router/dealer`, function () {
/* ZMQ < 4.0.5 has no steerable proxy support. */
if (semver.satisfies(zmq.version, "< 4.0.5")) {
return
}

let proxy: zmq.Proxy

let frontAddress: string
Expand All @@ -15,11 +20,6 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
let rep: zmq.Reply

beforeEach(async function () {
/* ZMQ < 4.0.5 has no steerable proxy support. */
if (semver.satisfies(zmq.version, "< 4.0.5")) {
this.skip()
}

proxy = new zmq.Proxy(new zmq.Router(), new zmq.Dealer())

frontAddress = uniqAddress(proto)
Expand Down Expand Up @@ -89,6 +89,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
rep.close()
}

console.log("waiting for messages")

await Promise.all([echo(), send()])
assert.deepEqual(received, messages)

Expand Down
19 changes: 10 additions & 9 deletions test/unit/proxy-terminate-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,14 @@ import {isFullError} from "../../src/errors"

for (const proto of testProtos("tcp", "ipc", "inproc")) {
describe(`proxy with ${proto} terminate`, function () {
/* ZMQ < 4.0.5 has no steerable proxy support. */
if (semver.satisfies(zmq.version, "< 4.0.5")) {
return
}

let proxy: zmq.Proxy

beforeEach(async function () {
/* ZMQ < 4.0.5 has no steerable proxy support. */
if (semver.satisfies(zmq.version, "< 4.0.5")) {
this.skip()
}

proxy = new zmq.Proxy(new zmq.Router(), new zmq.Dealer())
})

Expand All @@ -28,12 +28,13 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) {
await proxy.frontEnd.bind(uniqAddress(proto))
await proxy.backEnd.bind(uniqAddress(proto))

try {
const timer = setTimeout(() => proxy.terminate(), 50)
await proxy.run()
const sleep_ms = 50

setTimeout(() => proxy.terminate(), sleep_ms)
await proxy.run()

try {
await proxy.terminate()
timer.unref()
assert.ok(false)
} catch (err) {
if (!isFullError(err)) {
Expand Down
2 changes: 1 addition & 1 deletion test/unit/typings-compatibility-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import {
readFile,
writeFile,
} from "fs-extra"
import * as which from "which"
import which from "which"

import {assert} from "chai"

Expand Down
1 change: 1 addition & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"noUnusedParameters": false,
"incremental": true,
"sourceMap": true,
"esModuleInterop": true,
"lib": ["ES2020", "dom"]
}
}

0 comments on commit ec1a72d

Please sign in to comment.