From 3d54dbaaa73cb1a29fa00a715d373e7bc1d2f1fc Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Fri, 14 Jun 2024 15:21:41 -0700 Subject: [PATCH] test: fix the termination timeout during in terminate tests --- .github/workflows/CI.yml | 3 ++- package.json | 4 ++-- script/tsconfig.esm.json | 2 +- test/unit/proxy-router-dealer-test.ts | 12 +++++++----- test/unit/proxy-terminate-test.ts | 19 ++++++++++--------- test/unit/typings-compatibility-test.ts | 2 +- tsconfig.json | 1 + 7 files changed, 24 insertions(+), 19 deletions(-) diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml index 0c6db85e..93078ccb 100644 --- a/.github/workflows/CI.yml +++ b/.github/workflows/CI.yml @@ -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 diff --git a/package.json b/package.json index 9326d513..77834477 100644 --- a/package.json +++ b/package.json @@ -94,8 +94,8 @@ "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 clean.temp test.deps build && mocha --exit", - "test.skip_gc_tests": "run-s clean.temp test.deps build.debug && cross-env SKIP_GC_TESTS=true mocha --exit", + "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", diff --git a/script/tsconfig.esm.json b/script/tsconfig.esm.json index 698433fd..9789fa80 100644 --- a/script/tsconfig.esm.json +++ b/script/tsconfig.esm.json @@ -2,7 +2,7 @@ "extends": "./tsconfig.json", "compilerOptions": { "module": "ESNext", - "moduleResolution": "node", + "moduleResolution": "node" }, "include": ["./**/*.mts"], "exclude": [] diff --git a/test/unit/proxy-router-dealer-test.ts b/test/unit/proxy-router-dealer-test.ts index 2bd5ecc2..889cee58 100644 --- a/test/unit/proxy-router-dealer-test.ts +++ b/test/unit/proxy-router-dealer-test.ts @@ -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 @@ -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) @@ -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) diff --git a/test/unit/proxy-terminate-test.ts b/test/unit/proxy-terminate-test.ts index b36c0a4c..80b89d9b 100644 --- a/test/unit/proxy-terminate-test.ts +++ b/test/unit/proxy-terminate-test.ts @@ -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()) }) @@ -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)) { diff --git a/test/unit/typings-compatibility-test.ts b/test/unit/typings-compatibility-test.ts index b0677953..4b9675f2 100644 --- a/test/unit/typings-compatibility-test.ts +++ b/test/unit/typings-compatibility-test.ts @@ -8,7 +8,7 @@ import { readFile, writeFile, } from "fs-extra" -import * as which from "which" +import which from "which" import {assert} from "chai" diff --git a/tsconfig.json b/tsconfig.json index 1e58e4da..02c2001c 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -16,6 +16,7 @@ "noUnusedParameters": false, "incremental": true, "sourceMap": true, + "esModuleInterop": true, "lib": ["ES2020", "dom"] } }