From 97587cedd22e48ca4f17b10c0903d50236a83749 Mon Sep 17 00:00:00 2001 From: Amin Yahyaabadi Date: Thu, 25 Aug 2022 03:57:11 -0700 Subject: [PATCH] fix: run lint --- draft.js | 2 +- examples/majordomo/index.ts | 8 +- examples/queue/queue.ts | 4 +- examples/threaded-worker/processor.ts | 4 +- examples/threaded-worker/threaded-worker.ts | 4 +- script/ci/downlevel-dts.js | 4 +- script/ci/download.js | 39 +++-- src/compat.ts | 54 ++++--- src/draft.ts | 8 +- src/index.ts | 8 +- src/native.ts | 4 +- src/poller.h | 6 +- src/proxy.cc | 3 +- src/socket.cc | 6 +- src/util/uvwork.h | 3 +- test/bench/create-socket.js | 56 ++++--- test/bench/deliver-async-iterator.js | 78 +++++----- test/bench/deliver-multipart.js | 138 ++++++++++-------- test/bench/deliver.js | 126 ++++++++-------- test/bench/index.js | 26 ++-- test/bench/queue.js | 90 +++++++----- test/unit/compat/context-test.js | 6 +- test/unit/compat/exports-test.js | 24 +-- test/unit/compat/gc-test.js | 8 +- test/unit/compat/load.js | 8 +- .../unit/compat/socket-error-callback-test.js | 10 +- test/unit/compat/socket-events-test.js | 14 +- test/unit/compat/socket-messages-test.js | 27 ++-- test/unit/compat/socket-monitor-test.js | 28 ++-- test/unit/compat/socket-pair-test.js | 12 +- test/unit/compat/socket-pub-sub-test.js | 44 +++--- test/unit/compat/socket-push-pull-test.js | 34 +++-- test/unit/compat/socket-req-rep-test.js | 42 +++--- test/unit/compat/socket-router-test.js | 25 ++-- test/unit/compat/socket-stream-test.js | 71 +++++---- test/unit/compat/socket-test.js | 18 +-- test/unit/compat/socket-unbind-test.js | 27 ++-- test/unit/compat/socket-xpub-xsub-test.js | 18 ++- test/unit/compat/socket-zap-test.js | 111 +++++++++----- test/unit/compat/zmq-proxy-push-pull-test.js | 40 +++-- .../compat/zmq-proxy-router-dealer-test.js | 50 ++++--- test/unit/compat/zmq-proxy-test.js | 4 +- test/unit/compat/zmq-proxy-xpub-xsub-test.js | 55 ++++--- test/unit/context-construction-test.ts | 18 +-- test/unit/context-options-test.ts | 12 +- test/unit/context-process-exit-test.ts | 26 ++-- test/unit/context-thread-test.ts | 12 +- test/unit/helpers.ts | 16 +- test/unit/proxy-construction-test.ts | 20 +-- test/unit/proxy-router-dealer-test.ts | 18 ++- test/unit/proxy-run-test.ts | 18 ++- test/unit/proxy-terminate-test.ts | 12 +- test/unit/socket-bind-unbind-test.ts | 28 ++-- test/unit/socket-close-test.ts | 40 ++--- test/unit/socket-connect-disconnect-test.ts | 22 +-- test/unit/socket-construction-test.ts | 46 +++--- test/unit/socket-curve-send-receive-test.ts | 20 ++- test/unit/socket-draft-dgram-test.ts | 10 +- test/unit/socket-draft-radio-dish-test.ts | 39 ++--- test/unit/socket-draft-scatter-gather-test.ts | 20 ++- test/unit/socket-draft-server-client-test.ts | 20 ++- test/unit/socket-events-test.ts | 34 +++-- test/unit/socket-options-test.ts | 56 +++---- test/unit/socket-pair-test.ts | 14 +- test/unit/socket-process-exit-test.ts | 12 +- test/unit/socket-pub-sub-test.ts | 22 +-- test/unit/socket-push-pull-test.ts | 20 ++- test/unit/socket-req-rep-test.ts | 16 +- test/unit/socket-router-dealer-test.ts | 20 ++- test/unit/socket-send-receive-test.ts | 124 +++++++++------- test/unit/socket-stream-test.ts | 20 +-- test/unit/socket-thread-test.ts | 20 +-- test/unit/socket-xpub-xsub-test.ts | 62 +++++--- test/unit/socket-zap-test.ts | 38 +++-- test/unit/typings-compatibility-test.ts | 30 ++-- test/unit/typings-test.ts | 36 +++-- test/unit/zmq-draft-test.ts | 6 +- test/unit/zmq-test.ts | 24 +-- 78 files changed, 1342 insertions(+), 956 deletions(-) diff --git a/draft.js b/draft.js index d2befa0f..80036327 100644 --- a/draft.js +++ b/draft.js @@ -5,7 +5,7 @@ if (require(".").capability.draft) { } else { throw new Error( "ZeroMQ draft features are not enabled in this build. " + - "To enable support, (re)compile this library with --zmq-draft.", + "To enable support, (re)compile this library with --zmq-draft.", ) } diff --git a/examples/majordomo/index.ts b/examples/majordomo/index.ts index 144150b5..83660c2f 100644 --- a/examples/majordomo/index.ts +++ b/examples/majordomo/index.ts @@ -49,7 +49,9 @@ async function request( } async function main() { - for (const worker of workers) worker.start() + for (const worker of workers) { + worker.start() + } broker.start() /* Requests are issued in parallel. */ @@ -65,7 +67,9 @@ async function main() { request("coffee", "irish coffee"), ]) - for (const worker of workers) worker.stop() + for (const worker of workers) { + worker.stop() + } broker.stop() } diff --git a/examples/queue/queue.ts b/examples/queue/queue.ts index a784cd1f..d5a2fe0a 100644 --- a/examples/queue/queue.ts +++ b/examples/queue/queue.ts @@ -20,7 +20,9 @@ export class Queue { } async trySend() { - if (this.sending) return + if (this.sending) { + return + } this.sending = true while (this.queue.length) { diff --git a/examples/threaded-worker/processor.ts b/examples/threaded-worker/processor.ts index 2e5bb960..1e5b1baa 100644 --- a/examples/threaded-worker/processor.ts +++ b/examples/threaded-worker/processor.ts @@ -39,7 +39,9 @@ export class Processor { const output: string[] = Array.from({length: input.length}) for await (const [pos, res] of this.output) { output[parseInt(pos.toString(), 10)] = res.toString() - if (output.every(el => el !== undefined)) break + if (output.every(el => el !== undefined)) { + break + } } return output.join("") diff --git a/examples/threaded-worker/threaded-worker.ts b/examples/threaded-worker/threaded-worker.ts index 50074037..beda54a8 100644 --- a/examples/threaded-worker/threaded-worker.ts +++ b/examples/threaded-worker/threaded-worker.ts @@ -42,7 +42,9 @@ export class ThreadedWorker { const listen = async () => { for await (const [sig] of this.signal) { - if (sig.toString() === "stop") this.stop() + if (sig.toString() === "stop") { + this.stop() + } } } diff --git a/script/ci/downlevel-dts.js b/script/ci/downlevel-dts.js index 903aa22b..59b3eb1a 100644 --- a/script/ci/downlevel-dts.js +++ b/script/ci/downlevel-dts.js @@ -142,7 +142,7 @@ function getModifiersText(node) { .getModifiers() .map(m => m.getText()) .join(" ") - return modifiersText.length > 0 ? modifiersText + " " : "" + return modifiersText.length > 0 ? `${modifiersText} ` : "" } function getLeadingComments(node) { @@ -174,7 +174,7 @@ function relativeModulePath(fromAbsModulePath, toAbsTargetDir) { path.join(revertedPath, path.basename(fromAbsModulePath)), ) if (!/^\./.test(relMod)) { - relMod = "./" + relMod + relMod = `./${relMod}` } if (path.sep === "/") { return relMod diff --git a/script/ci/download.js b/script/ci/download.js index b0b3caaa..45ce9289 100644 --- a/script/ci/download.js +++ b/script/ci/download.js @@ -4,34 +4,49 @@ const gunzip = require("gunzip-maybe") const tar = require("tar-fs") async function download() { - const {repository: {url}, version} = require(path.resolve("./package.json")) + const { + repository: {url}, + version, + } = require(path.resolve("./package.json")) if (process.env.TRAVIS_TAG && process.env.TRAVIS_TAG != `v${version}`) { - throw new Error(`Version mismatch (TRAVIS_TAG=${process.env.TRAVIS_TAG}, version=${version}`) + throw new Error( + `Version mismatch (TRAVIS_TAG=${process.env.TRAVIS_TAG}, version=${version}`, + ) } - const [, user, repo] = url.match(/\/([a-z0-9_.-]+)\/([a-z0-9_.-]+)\.git$/i) + const [, user, repo] = url.match(/\/([\w.-]+)\/([\w.-]+)\.git$/i) - const res = await fetch(`https://api.github.com/repos/${user}/${repo}/releases/tags/v${version}`) + const res = await fetch( + `https://api.github.com/repos/${user}/${repo}/releases/tags/v${version}`, + ) if (!res.ok) { if (res.status == 404) { throw new Error(`Github release v${version} not found (${res.status})`) } else { const body = await res.text() - throw new Error(`Github release v${version} not accessible (${res.status}): ${body}`) + throw new Error( + `Github release v${version} not accessible (${res.status}): ${body}`, + ) } } const {assets} = await res.json() - await Promise.all(assets.map(async ({browser_download_url: url}) => { - console.log(`Downloading prebuilds from ${url}`) - const res = await fetch(url) - return new Promise((resolve, reject) => { - res.body.pipe(gunzip()).pipe(tar.extract(".")).on("error", reject).on("finish", resolve) - }) - })) + await Promise.all( + assets.map(async ({browser_download_url: url}) => { + console.log(`Downloading prebuilds from ${url}`) + const res = await fetch(url) + return new Promise((resolve, reject) => { + res.body + .pipe(gunzip()) + .pipe(tar.extract(".")) + .on("error", reject) + .on("finish", resolve) + }) + }), + ) } download().catch(err => { diff --git a/src/compat.ts b/src/compat.ts index 5e9cb0de..8afab3b4 100644 --- a/src/compat.ts +++ b/src/compat.ts @@ -272,7 +272,9 @@ class Socket extends EventEmitter { await this._recv() } - if (!this._socket.closed) recv() + if (!this._socket.closed) { + recv() + } }) } @@ -286,11 +288,15 @@ class Socket extends EventEmitter { await this._send() } - if (!this._socket.closed) send() + if (!this._socket.closed) { + send() + } }) } - if (type !== "push" && type !== "pub") recv() + if (type !== "push" && type !== "pub") { + recv() + } send() this.emit("_flushRecv") @@ -337,7 +343,9 @@ class Socket extends EventEmitter { const [msg, cb] = this._sendQueue.shift()! try { await (this._socket as zmq.Writable).send(msg) - if (cb) cb() + if (cb) { + cb() + } } catch (err) { if (cb) { cb(err) @@ -354,7 +362,9 @@ class Socket extends EventEmitter { .then(() => { process.nextTick(() => { this.emit("bind", address) - if (cb) cb() + if (cb) { + cb() + } }) }) .catch(err => { @@ -376,7 +386,9 @@ class Socket extends EventEmitter { .then(() => { process.nextTick(() => { this.emit("unbind", address) - if (cb) cb() + if (cb) { + cb() + } }) }) .catch(err => { @@ -408,7 +420,9 @@ class Socket extends EventEmitter { if ((flags & sendOptions.ZMQ_SNDMORE) === 0) { this._sendQueue.push([this._msg, cb]) this._msg = [] - if (!this._paused) this.emit("_flushSend") + if (!this._paused) { + this.emit("_flushSend") + } } return this } @@ -634,7 +648,7 @@ class Socket extends EventEmitter { this._socket.ipv6 = !value break case longOptions.ZMQ_ROUTER_MANDATORY: - ;(this._socket as zmq.Router).mandatory = !!value + ;(this._socket as zmq.Router).mandatory = Boolean(value) break case longOptions.ZMQ_TCP_KEEPALIVE: this._socket.tcpKeepalive = value @@ -652,7 +666,7 @@ class Socket extends EventEmitter { this._socket.tcpAcceptFilter = value break case longOptions.ZMQ_DELAY_ATTACH_ON_CONNECT: - this._socket.immediate = !!value + this._socket.immediate = Boolean(value) break case longOptions.ZMQ_XPUB_VERBOSE: ;(this._socket as zmq.XPublisher).verbosity = value ? "allSubs" : null @@ -660,10 +674,10 @@ class Socket extends EventEmitter { case longOptions.ZMQ_ROUTER_RAW: throw new Error("ZMQ_ROUTER_RAW is not supported in compatibility mode") case longOptions.ZMQ_IPV6: - this._socket.ipv6 = !!value + this._socket.ipv6 = Boolean(value) break case longOptions.ZMQ_PLAIN_SERVER: - this._socket.plainServer = !!value + this._socket.plainServer = Boolean(value) break case longOptions.ZMQ_PLAIN_USERNAME: this._socket.plainUsername = value @@ -672,7 +686,7 @@ class Socket extends EventEmitter { this._socket.plainPassword = value break case longOptions.ZMQ_CURVE_SERVER: - this._socket.curveServer = !!value + this._socket.curveServer = Boolean(value) break case longOptions.ZMQ_CURVE_PUBLICKEY: this._socket.curvePublicKey = value @@ -699,7 +713,7 @@ class Socket extends EventEmitter { this._socket.connectTimeout = value break case longOptions.ZMQ_ROUTER_HANDOVER: - ;(this._socket as zmq.Router).handover = !!value + ;(this._socket as zmq.Router).handover = Boolean(value) break default: throw new Error("Unknown option") @@ -821,14 +835,20 @@ class Socket extends EventEmitter { } for (const key in shortOptions) { - if (!shortOptions.hasOwnProperty(key)) continue - if (Socket.prototype.hasOwnProperty(key)) continue + if (!shortOptions.hasOwnProperty(key)) { + continue + } + if (Socket.prototype.hasOwnProperty(key)) { + continue + } Object.defineProperty(Socket.prototype, key, { get(this: Socket) { return this.getsockopt(shortOptions[key as keyof typeof shortOptions]) }, set(this: Socket, val: string | Buffer) { - if ("string" === typeof val) val = Buffer.from(val, "utf8") + if ("string" === typeof val) { + val = Buffer.from(val, "utf8") + } return this.setsockopt( shortOptions[key as keyof typeof shortOptions], val, @@ -853,7 +873,7 @@ function curveKeypair() { } function proxy(frontend: Socket, backend: Socket, capture?: Socket) { - switch (frontend.type + "/" + backend.type) { + switch (`${frontend.type}/${backend.type}`) { case "push/pull": case "pull/push": case "xpub/xsub": diff --git a/src/draft.ts b/src/draft.ts index 325a6e27..b528b557 100644 --- a/src/draft.ts +++ b/src/draft.ts @@ -50,11 +50,15 @@ export class Dish extends Socket { the sake of simplicity. */ join(...values: Array): void { - for (const value of values) join.call(this, value) + for (const value of values) { + join.call(this, value) + } } leave(...values: Array): void { - for (const value of values) leave.call(this, value) + for (const value of values) { + leave.call(this, value) + } } } diff --git a/src/index.ts b/src/index.ts index d38dcc74..ba050fd2 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,7 +56,7 @@ export type MessageLike = */ export interface Writable< M extends MessageLike | MessageLike[] = MessageLike | MessageLike[], - O extends [...object[]] = [] + O extends [...object[]] = [], > { /** * ZMQ_MULTICAST_HOPS @@ -1636,7 +1636,7 @@ function defineOpt>>( set if the property has been defined as readonly in the interface/class. */ function defineOpt< T extends {prototype: any}, - K extends ReadableKeys> + K extends ReadableKeys>, >( targets: T[], name: K, @@ -1674,7 +1674,9 @@ function defineOpt< } for (const target of targets) { - if (target.prototype.hasOwnProperty(name)) continue + if (target.prototype.hasOwnProperty(name)) { + continue + } Object.defineProperty(target.prototype, name, desc) } } diff --git a/src/native.ts b/src/native.ts index ae1868f1..aa897c51 100644 --- a/src/native.ts +++ b/src/native.ts @@ -392,7 +392,7 @@ export declare class Observer { */ export declare class Proxy< F extends Socket = Socket, - B extends Socket = Socket + B extends Socket = Socket, > { /** * Returns the original front-end socket. @@ -646,7 +646,7 @@ export const enum SocketType { /* https://stackoverflow.com/questions/49579094 */ type IfEquals = (() => T extends X ? 1 : 2) extends < - T + T, >() => T extends Y ? 1 : 2 ? A : B diff --git a/src/poller.h b/src/poller.h index 3ef26f86..b8fdc652 100644 --- a/src/poller.h +++ b/src/poller.h @@ -67,7 +67,8 @@ class Poller { assert((events & UV_READABLE) == 0); if (timeout > 0) { - auto err = uv_timer_start(readable_timer, + auto err = uv_timer_start( + readable_timer, [](uv_timer_t* timer) { auto& poller = *reinterpret_cast(timer->data); poller.Trigger(UV_READABLE); @@ -90,7 +91,8 @@ class Poller { assert((events & UV_WRITABLE) == 0); if (timeout > 0) { - auto err = uv_timer_start(writable_timer, + auto err = uv_timer_start( + writable_timer, [](uv_timer_t* timer) { auto& poller = *reinterpret_cast(timer->data); poller.Trigger(UV_WRITABLE); diff --git a/src/proxy.cc b/src/proxy.cc index f2d8da12..86c2d598 100644 --- a/src/proxy.cc +++ b/src/proxy.cc @@ -97,7 +97,8 @@ Napi::Value Proxy::Run(const Napi::CallbackInfo& info) { auto front_ptr = front->socket; auto back_ptr = back->socket; - auto status = UvQueue(Env(), + auto status = UvQueue( + Env(), [=]() { /* Don't access V8 internals here! Executed in worker thread. */ if (zmq_bind(control_sub, run_ctx->address.c_str()) < 0) { diff --git a/src/socket.cc b/src/socket.cc index 77b54c99..b024176a 100644 --- a/src/socket.cc +++ b/src/socket.cc @@ -350,7 +350,8 @@ Napi::Value Socket::Bind(const Napi::CallbackInfo& info) { auto res = Napi::Promise::Deferred::New(Env()); auto run_ctx = std::make_shared(info[0].As()); - auto status = UvQueue(Env(), + auto status = UvQueue( + Env(), [=]() { /* Don't access V8 internals here! Executed in worker thread. */ while (zmq_bind(socket, run_ctx->address.c_str()) < 0) { @@ -400,7 +401,8 @@ Napi::Value Socket::Unbind(const Napi::CallbackInfo& info) { auto res = Napi::Promise::Deferred::New(Env()); auto run_ctx = std::make_shared(info[0].As()); - auto status = UvQueue(Env(), + auto status = UvQueue( + Env(), [=]() { /* Don't access V8 internals here! Executed in worker thread. */ while (zmq_unbind(socket, run_ctx->address.c_str()) < 0) { diff --git a/src/util/uvwork.h b/src/util/uvwork.h index 8ade4b63..20e7b7e9 100644 --- a/src/util/uvwork.h +++ b/src/util/uvwork.h @@ -21,7 +21,8 @@ class UvWork { } inline int32_t Schedule(uv_loop_t* loop) { - auto err = uv_queue_work(loop, work.get(), + auto err = uv_queue_work( + loop, work.get(), [](uv_work_t* req) { auto& work = *reinterpret_cast(req->data); work.execute_callback(); diff --git a/test/bench/create-socket.js b/test/bench/create-socket.js index 1a019d1d..63c529b1 100644 --- a/test/bench/create-socket.js +++ b/test/bench/create-socket.js @@ -1,27 +1,43 @@ if (zmq.cur) { zmq.cur.Context.setMaxSockets(n) - suite.add(`create socket n=${n} zmq=cur`, Object.assign({ - fn: deferred => { - const sockets = [] - for (let i = 0; i < n; i++) { - sockets.push(zmq.cur.socket("dealer")) - } - deferred.resolve() - for (const socket of sockets) socket.close() - } - }, benchOptions)) + suite.add( + `create socket n=${n} zmq=cur`, + Object.assign( + { + fn: deferred => { + const sockets = [] + for (let i = 0; i < n; i++) { + sockets.push(zmq.cur.socket("dealer")) + } + deferred.resolve() + for (const socket of sockets) { + socket.close() + } + }, + }, + benchOptions, + ), + ) } if (zmq.ng) { zmq.ng.context.maxSockets = n - suite.add(`create socket n=${n} zmq=ng`, Object.assign({ - fn: deferred => { - const sockets = [] - for (let i = 0; i < n; i++) { - sockets.push(new zmq.ng.Dealer) - } - deferred.resolve() - for (const socket of sockets) socket.close() - } - }, benchOptions)) + suite.add( + `create socket n=${n} zmq=ng`, + Object.assign( + { + fn: deferred => { + const sockets = [] + for (let i = 0; i < n; i++) { + sockets.push(new zmq.ng.Dealer()) + } + deferred.resolve() + for (const socket of sockets) { + socket.close() + } + }, + }, + benchOptions, + ), + ) } diff --git a/test/bench/deliver-async-iterator.js b/test/bench/deliver-async-iterator.js index 9f8096e7..3aab54d9 100644 --- a/test/bench/deliver-async-iterator.js +++ b/test/bench/deliver-async-iterator.js @@ -1,37 +1,45 @@ if (zmq.ng) { - suite.add(`deliver async iterator proto=${proto} msgsize=${msgsize} n=${n} zmq=ng`, Object.assign({ - fn: async deferred => { - const server = new zmq.ng.Dealer - const client = new zmq.ng.Dealer - - await server.bind(address) - client.connect(address) - - global.gc?.() - - const send = async () => { - for (let i = 0; i < n; i++) { - await client.send(Buffer.alloc(msgsize)) - } - } - - const receive = async () => { - let i = 0 - for await (const [msg] of server) { - if (++i == n) server.close() - } - } - - await Promise.all([send(), receive()]) - - global.gc?.() - - server.close() - client.close() - - global.gc?.() - - deferred.resolve() - } - }, benchOptions)) + suite.add( + `deliver async iterator proto=${proto} msgsize=${msgsize} n=${n} zmq=ng`, + Object.assign( + { + fn: async deferred => { + const server = new zmq.ng.Dealer() + const client = new zmq.ng.Dealer() + + await server.bind(address) + client.connect(address) + + global.gc?.() + + const send = async () => { + for (let i = 0; i < n; i++) { + await client.send(Buffer.alloc(msgsize)) + } + } + + const receive = async () => { + let i = 0 + for await (const [msg] of server) { + if (++i == n) { + server.close() + } + } + } + + await Promise.all([send(), receive()]) + + global.gc?.() + + server.close() + client.close() + + global.gc?.() + + deferred.resolve() + }, + }, + benchOptions, + ), + ) } diff --git a/test/bench/deliver-multipart.js b/test/bench/deliver-multipart.js index 6ad59a2a..06a0ab9c 100644 --- a/test/bench/deliver-multipart.js +++ b/test/bench/deliver-multipart.js @@ -1,71 +1,91 @@ if (zmq.cur) { - suite.add(`deliver multipart proto=${proto} msgsize=${msgsize} n=${n} zmq=cur`, Object.assign({ - fn: deferred => { - const server = zmq.cur.socket("dealer") - const client = zmq.cur.socket("dealer") - - let j = 0 - server.on("message", (msg1, msg2, mgs3) => { - j++ - if (j == n - 1) { - global.gc?.() - - server.close() - client.close() - - global.gc?.() - - deferred.resolve() - } - }) - - server.bind(address, () => { - client.connect(address) - - global.gc?.() - - for (let i = 0; i < n; i++) { - client.send([Buffer.alloc(msgsize), Buffer.alloc(msgsize), Buffer.alloc(msgsize)]) - } - }) - } - }, benchOptions)) + suite.add( + `deliver multipart proto=${proto} msgsize=${msgsize} n=${n} zmq=cur`, + Object.assign( + { + fn: deferred => { + const server = zmq.cur.socket("dealer") + const client = zmq.cur.socket("dealer") + + let j = 0 + server.on("message", (msg1, msg2, mgs3) => { + j++ + if (j == n - 1) { + global.gc?.() + + server.close() + client.close() + + global.gc?.() + + deferred.resolve() + } + }) + + server.bind(address, () => { + client.connect(address) + + global.gc?.() + + for (let i = 0; i < n; i++) { + client.send([ + Buffer.alloc(msgsize), + Buffer.alloc(msgsize), + Buffer.alloc(msgsize), + ]) + } + }) + }, + }, + benchOptions, + ), + ) } if (zmq.ng) { - suite.add(`deliver multipart proto=${proto} msgsize=${msgsize} n=${n} zmq=ng`, Object.assign({ - fn: async deferred => { - const server = new zmq.ng.Dealer - const client = new zmq.ng.Dealer - - await server.bind(address) - client.connect(address) - - global.gc?.() + suite.add( + `deliver multipart proto=${proto} msgsize=${msgsize} n=${n} zmq=ng`, + Object.assign( + { + fn: async deferred => { + const server = new zmq.ng.Dealer() + const client = new zmq.ng.Dealer() - const send = async () => { - for (let i = 0; i < n; i++) { - await client.send([Buffer.alloc(msgsize), Buffer.alloc(msgsize), Buffer.alloc(msgsize)]) - } - } + await server.bind(address) + client.connect(address) - const receive = async () => { - let j = 0 - for (j = 0; j < n - 1; j++) { - const [msg1, msg2, msg3] = await server.receive() - } - } + global.gc?.() - await Promise.all([send(), receive()]) + const send = async () => { + for (let i = 0; i < n; i++) { + await client.send([ + Buffer.alloc(msgsize), + Buffer.alloc(msgsize), + Buffer.alloc(msgsize), + ]) + } + } + + const receive = async () => { + let j = 0 + for (j = 0; j < n - 1; j++) { + const [msg1, msg2, msg3] = await server.receive() + } + } + + await Promise.all([send(), receive()]) - global.gc?.() + global.gc?.() - server.close() - client.close() + server.close() + client.close() - global.gc?.() + global.gc?.() - deferred.resolve() - } - }, benchOptions)) + deferred.resolve() + }, + }, + benchOptions, + ), + ) } diff --git a/test/bench/deliver.js b/test/bench/deliver.js index b52b4d39..ca3e878d 100644 --- a/test/bench/deliver.js +++ b/test/bench/deliver.js @@ -1,71 +1,83 @@ if (zmq.cur) { - suite.add(`deliver proto=${proto} msgsize=${msgsize} n=${n} zmq=cur`, Object.assign({ - fn: deferred => { - const server = zmq.cur.socket("dealer") - const client = zmq.cur.socket("dealer") - - let j = 0 - server.on("message", msg => { - j++ - if (j == n - 1) { - global.gc?.() - - server.close() - client.close() - - global.gc?.() - - deferred.resolve() - } - }) - - server.bind(address, () => { - client.connect(address) - - global.gc?.() - - for (let i = 0; i < n; i++) { - client.send(Buffer.alloc(msgsize)) - } - }) - } - }, benchOptions)) + suite.add( + `deliver proto=${proto} msgsize=${msgsize} n=${n} zmq=cur`, + Object.assign( + { + fn: deferred => { + const server = zmq.cur.socket("dealer") + const client = zmq.cur.socket("dealer") + + let j = 0 + server.on("message", msg => { + j++ + if (j == n - 1) { + global.gc?.() + + server.close() + client.close() + + global.gc?.() + + deferred.resolve() + } + }) + + server.bind(address, () => { + client.connect(address) + + global.gc?.() + + for (let i = 0; i < n; i++) { + client.send(Buffer.alloc(msgsize)) + } + }) + }, + }, + benchOptions, + ), + ) } if (zmq.ng) { - suite.add(`deliver proto=${proto} msgsize=${msgsize} n=${n} zmq=ng`, Object.assign({ - fn: async deferred => { - const server = new zmq.ng.Dealer - const client = new zmq.ng.Dealer + suite.add( + `deliver proto=${proto} msgsize=${msgsize} n=${n} zmq=ng`, + Object.assign( + { + fn: async deferred => { + const server = new zmq.ng.Dealer() + const client = new zmq.ng.Dealer() - await server.bind(address) - client.connect(address) + await server.bind(address) + client.connect(address) - global.gc?.() + global.gc?.() - const send = async () => { - for (let i = 0; i < n; i++) { - await client.send(Buffer.alloc(msgsize)) - } - } + const send = async () => { + for (let i = 0; i < n; i++) { + await client.send(Buffer.alloc(msgsize)) + } + } - const receive = async () => { - let j = 0 - for (j = 0; j < n - 1; j++) { - const [msg] = await server.receive() - } - } + const receive = async () => { + let j = 0 + for (j = 0; j < n - 1; j++) { + const [msg] = await server.receive() + } + } - await Promise.all([send(), receive()]) + await Promise.all([send(), receive()]) - global.gc?.() + global.gc?.() - server.close() - client.close() + server.close() + client.close() - global.gc?.() + global.gc?.() - deferred.resolve() - } - }, benchOptions)) + deferred.resolve() + }, + }, + benchOptions, + ), + ) } diff --git a/test/bench/index.js b/test/bench/index.js index 7e9a4a23..23737f44 100644 --- a/test/bench/index.js +++ b/test/bench/index.js @@ -22,8 +22,8 @@ const msgsizes = [ /* Which benchmarks to run. */ const benchmarks = { // "create-socket": {n, options: {delay: 0.5}}, - "queue": {n, msgsizes}, - "deliver": {n, protos, msgsizes}, + queue: {n, msgsizes}, + deliver: {n, protos, msgsizes}, "deliver-multipart": {n, protos, msgsizes}, "deliver-async-iterator": {n, protos, msgsizes}, } @@ -41,20 +41,20 @@ let seq = 5000 function uniqAddress(proto) { const id = seq++ switch (proto) { - case "ipc": - return `${proto}://${__dirname}/../../tmp/${proto}-${id}` - case "tcp": - case "udp": - return `${proto}://127.0.0.1:${id}` - default: - return `${proto}://${proto}-${id}` + case "ipc": + return `${proto}://${__dirname}/../../tmp/${proto}-${id}` + case "tcp": + case "udp": + return `${proto}://127.0.0.1:${id}` + default: + return `${proto}://${proto}-${id}` } } /* Continue to load and execute benchmarks. */ const fs = require("fs") const bench = require("benchmark") -const suite = new bench.Suite +const suite = new bench.Suite() const defaultOptions = { defer: true, @@ -62,8 +62,10 @@ const defaultOptions = { onError: console.error, } -for (const [benchmark, {n, protos, msgsizes, options}] of Object.entries(benchmarks)) { - let load = ({n, proto, msgsize, address}) => { +for (const [benchmark, {n, protos, msgsizes, options}] of Object.entries( + benchmarks, +)) { + const load = ({n, proto, msgsize, address}) => { const benchOptions = Object.assign({}, defaultOptions, options) eval(fs.readFileSync(`${__dirname}/${benchmark}.js`).toString()) } diff --git a/test/bench/queue.js b/test/bench/queue.js index 94120cd4..6e3cea57 100644 --- a/test/bench/queue.js +++ b/test/bench/queue.js @@ -1,44 +1,56 @@ if (zmq.cur) { - suite.add(`queue msgsize=${msgsize} n=${n} zmq=cur`, Object.assign({ - fn: deferred => { - const client = zmq.cur.socket("dealer") - client.linger = 0 - client.connect(address) - - global.gc?.() - - for (let i = 0; i < n; i++) { - client.send(Buffer.alloc(msgsize)) - } - - global.gc?.() - - client.close() - - deferred.resolve() - } - }, benchOptions)) + suite.add( + `queue msgsize=${msgsize} n=${n} zmq=cur`, + Object.assign( + { + fn: deferred => { + const client = zmq.cur.socket("dealer") + client.linger = 0 + client.connect(address) + + global.gc?.() + + for (let i = 0; i < n; i++) { + client.send(Buffer.alloc(msgsize)) + } + + global.gc?.() + + client.close() + + deferred.resolve() + }, + }, + benchOptions, + ), + ) } if (zmq.ng) { - suite.add(`queue msgsize=${msgsize} n=${n} zmq=ng`, Object.assign({ - fn: async deferred => { - const client = new zmq.ng.Dealer - client.linger = 0 - client.sendHighWaterMark = n * 2 - client.connect(address) - - global.gc?.() - - for (let i = 0; i < n; i++) { - await client.send(Buffer.alloc(msgsize)) - } - - global.gc?.() - - client.close() - - deferred.resolve() - } - }, benchOptions)) + suite.add( + `queue msgsize=${msgsize} n=${n} zmq=ng`, + Object.assign( + { + fn: async deferred => { + const client = new zmq.ng.Dealer() + client.linger = 0 + client.sendHighWaterMark = n * 2 + client.connect(address) + + global.gc?.() + + for (let i = 0; i < n; i++) { + await client.send(Buffer.alloc(msgsize)) + } + + global.gc?.() + + client.close() + + deferred.resolve() + }, + }, + benchOptions, + ), + ) } diff --git a/test/unit/compat/context-test.js b/test/unit/compat/context-test.js index de113ab3..741e5320 100644 --- a/test/unit/compat/context-test.js +++ b/test/unit/compat/context-test.js @@ -2,14 +2,14 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const zmq = require("./load") const {assert} = require("chai") - describe("compat context", function() { - it("should support setting max io threads", function() { + describe("compat context", function () { + it("should support setting max io threads", function () { zmq.Context.setMaxThreads(3) assert.equal(zmq.Context.getMaxThreads(), 3) zmq.Context.setMaxThreads(1) }) - it("should support setting max number of sockets", function() { + it("should support setting max number of sockets", function () { const currMaxSockets = zmq.Context.getMaxSockets() zmq.Context.setMaxSockets(256) assert.equal(zmq.Context.getMaxSockets(), 256) diff --git a/test/unit/compat/exports-test.js b/test/unit/compat/exports-test.js index 410d968f..ff2eefe6 100644 --- a/test/unit/compat/exports-test.js +++ b/test/unit/compat/exports-test.js @@ -3,13 +3,15 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const semver = require("semver") const {assert} = require("chai") - describe("compat exports", function() { - it("should export a valid version", function(){ + describe("compat exports", function () { + it("should export a valid version", function () { assert.ok(semver.valid(zmq.version)) }) - it("should generate valid curve keypair", function() { - if (!zmq.capability.curve) this.skip() + it("should generate valid curve keypair", function () { + if (!zmq.capability.curve) { + this.skip() + } const curve = zmq.curveKeypair() assert.typeOf(curve.public, "string") @@ -18,7 +20,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { assert.equal(curve.secret.length, 40) }) - it("should export socket types and options", function() { + it("should export socket types and options", function () { const constants = [ "PUB", "SUB", @@ -76,23 +78,23 @@ if (process.env.INCLUDE_COMPAT_TESTS) { "ROUTER_RAW", ] - constants.forEach(function(typeOrProp) { - assert.typeOf(zmq["ZMQ_" + typeOrProp], "number") + constants.forEach(function (typeOrProp) { + assert.typeOf(zmq[`ZMQ_${typeOrProp}`], "number") }) }) - it("should export states", function(){ - ["STATE_READY", "STATE_BUSY", "STATE_CLOSED"].forEach(function(state) { + it("should export states", function () { + ;["STATE_READY", "STATE_BUSY", "STATE_CLOSED"].forEach(function (state) { assert.typeOf(zmq[state], "number") }) }) - it("should export constructors", function(){ + it("should export constructors", function () { assert.typeOf(zmq.Context, "function") assert.typeOf(zmq.Socket, "function") }) - it("should export methods", function(){ + it("should export methods", function () { assert.typeOf(zmq.socket, "function") }) }) diff --git a/test/unit/compat/gc-test.js b/test/unit/compat/gc-test.js index a341d2e7..a742b630 100644 --- a/test/unit/compat/gc-test.js +++ b/test/unit/compat/gc-test.js @@ -4,8 +4,8 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto}`, function() { - it("should cooperate with gc", function(done) { + describe(`compat socket with ${proto}`, function () { + it("should cooperate with gc", function (done) { const sockA = zmq.socket("dealer") const sockB = zmq.socket("dealer") @@ -18,7 +18,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { * If a message is delivered, than everything is ok. Otherwise the guard * timeout will make the test fail. */ - sockA.on("message", function(msg) { + sockA.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") sockA.close() @@ -38,7 +38,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { } }) - let interval = setInterval(function() { + const interval = setInterval(function () { global.gc?.() if (bound) { clearInterval(interval) diff --git a/test/unit/compat/load.js b/test/unit/compat/load.js index 0aec5bb3..3de98396 100644 --- a/test/unit/compat/load.js +++ b/test/unit/compat/load.js @@ -1,10 +1,8 @@ const path = require("path") -module.exports = require( - process.env.ZMQ_COMPAT_PATH ? - path.resolve(process.cwd(), process.env.ZMQ_COMPAT_PATH) : - "../../../src/compat" -) +module.exports = require(process.env.ZMQ_COMPAT_PATH + ? path.resolve(process.cwd(), process.env.ZMQ_COMPAT_PATH) + : "../../../src/compat") /* Copy capabilities from regular module. */ module.exports.capability = require("../../../src").capability diff --git a/test/unit/compat/socket-error-callback-test.js b/test/unit/compat/socket-error-callback-test.js index 0ad1ef3d..d7d60117 100644 --- a/test/unit/compat/socket-error-callback-test.js +++ b/test/unit/compat/socket-error-callback-test.js @@ -2,23 +2,23 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const zmq = require("./load") const {assert} = require("chai") - describe("compat socket error callback", function() { + describe("compat socket error callback", function () { let sock - beforeEach(function() { + beforeEach(function () { sock = zmq.socket("router") }) - afterEach(function() { + afterEach(function () { sock.close() }) - it("should create a socket with mandatory", function() { + it("should create a socket with mandatory", function () { sock.setsockopt(zmq.ZMQ_ROUTER_MANDATORY, 1) sock.setsockopt(zmq.ZMQ_SNDTIMEO, 10) }) - it("should callback with error when not connected", function(done) { + it("should callback with error when not connected", function (done) { sock.send(["foo", "bar"], null, err => { assert.instanceOf(err, Error) sock.close() diff --git a/test/unit/compat/socket-events-test.js b/test/unit/compat/socket-events-test.js index 78ca700d..edae1e85 100644 --- a/test/unit/compat/socket-events-test.js +++ b/test/unit/compat/socket-events-test.js @@ -4,26 +4,28 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto} events`, function() { - it("should support events", function(done) { + describe(`compat socket with ${proto} events`, function () { + it("should support events", function (done) { const rep = zmq.socket("rep") const req = zmq.socket("req") const address = uniqAddress(proto) - rep.on("message", function(msg) { + rep.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") rep.send("world") }) rep.bind(address, err => { - if (err) throw err + if (err) { + throw err + } }) - rep.on("bind", function() { + rep.on("bind", function () { req.connect(address) - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "world") req.close() diff --git a/test/unit/compat/socket-messages-test.js b/test/unit/compat/socket-messages-test.js index 234f4a1a..996069f8 100644 --- a/test/unit/compat/socket-messages-test.js +++ b/test/unit/compat/socket-messages-test.js @@ -4,20 +4,21 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto} messages`, function() { - let push, pull + describe(`compat socket with ${proto} messages`, function () { + let push + let pull - beforeEach(function() { + beforeEach(function () { push = zmq.socket("push") pull = zmq.socket("pull") }) - it("should support messages", function(done) { + it("should support messages", function (done) { const address = uniqAddress(proto) let n = 0 - pull.on("message", function(msg) { + pull.on("message", function (msg) { msg = msg.toString() switch (n++) { case 0: @@ -42,10 +43,10 @@ if (process.env.INCLUDE_COMPAT_TESTS) { push.send(Buffer.from("buffer")) }) - it("should support multipart messages", function(done) { + it("should support multipart messages", function (done) { const address = uniqAddress(proto) - pull.on("message", function(msg1, msg2, msg3) { + pull.on("message", function (msg1, msg2, msg3) { assert.equal(msg1.toString(), "string") assert.equal(msg2.toString(), "15.99") assert.equal(msg3.toString(), "buffer") @@ -59,10 +60,10 @@ if (process.env.INCLUDE_COMPAT_TESTS) { push.send(["string", 15.99, Buffer.from("buffer")]) }) - it("should support sndmore", function(done) { + it("should support sndmore", function (done) { const address = uniqAddress(proto) - pull.on("message", function(a, b, c, d, e) { + pull.on("message", function (a, b, c, d, e) { assert.equal(a.toString(), "tobi") assert.equal(b.toString(), "loki") assert.equal(c.toString(), "jane") @@ -81,11 +82,11 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) if (proto != "inproc") { - it("should handle late connect", function(done) { + it("should handle late connect", function (done) { const address = uniqAddress(proto) let n = 0 - pull.on("message", function(msg) { + pull.on("message", function (msg) { msg = msg.toString() switch (n++) { case 0: @@ -114,7 +115,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) } - it("should call send callbacks", function(done) { + it("should call send callbacks", function (done) { const address = uniqAddress(proto) let received = 0 let callbacks = 0 @@ -123,7 +124,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { callbacks += 1 } - pull.on("message", function() { + pull.on("message", function () { received += 1 if (received === 4) { diff --git a/test/unit/compat/socket-monitor-test.js b/test/unit/compat/socket-monitor-test.js index 4a910533..ced0d3c2 100644 --- a/test/unit/compat/socket-monitor-test.js +++ b/test/unit/compat/socket-monitor-test.js @@ -6,36 +6,38 @@ if (process.env.INCLUDE_COMPAT_TESTS) { /* This test case only seems to work reliably with TCP. */ for (const proto of testProtos("tcp")) { - describe(`compat socket with ${proto} monitor`, function() { - beforeEach(function() { + describe(`compat socket with ${proto} monitor`, function () { + beforeEach(function () { /* ZMQ < 4.2 occasionally fails with assertion errors. */ - if (semver.satisfies(zmq.version, "< 4.2")) this.skip() + if (semver.satisfies(zmq.version, "< 4.2")) { + this.skip() + } this.warningListeners = process.listeners("warning") }) - afterEach(function() { + afterEach(function () { process.removeAllListeners("warning") for (const listener of this.warningListeners) { process.on("warning", listener) } }) - it("should be able to monitor the socket", function(done) { + it("should be able to monitor the socket", function (done) { const rep = zmq.socket("rep") const req = zmq.socket("req") const address = uniqAddress(proto) - rep.on("message", function(msg) { + rep.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") rep.send("world") }) const testedEvents = ["listen", "accept", "disconnect"] - testedEvents.forEach(function(e) { - rep.on(e, function(event_value, event_endpoint_addr) { + testedEvents.forEach(function (e) { + rep.on(e, function (event_value, event_endpoint_addr) { assert.equal(event_endpoint_addr.toString(), address) testedEvents.pop() @@ -51,13 +53,15 @@ if (process.env.INCLUDE_COMPAT_TESTS) { rep.monitor() rep.bind(address, err => { - if (err) throw err + if (err) { + throw err + } }) - rep.on("bind", function() { + rep.on("bind", function () { req.connect(address) req.send("hello") - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "world") req.close() @@ -67,7 +71,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { // and to the monitor event const doubleRep = zmq.socket("rep") doubleRep.monitor() - doubleRep.on("bind_error", function(errno, bindAddr, ex) { + doubleRep.on("bind_error", function (errno, bindAddr, ex) { assert.instanceOf(ex, Error) doubleRep.close() }) diff --git a/test/unit/compat/socket-pair-test.js b/test/unit/compat/socket-pair-test.js index 59bcb81b..0e314418 100644 --- a/test/unit/compat/socket-pair-test.js +++ b/test/unit/compat/socket-pair-test.js @@ -4,8 +4,8 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp")) { - describe(`compat socket with ${proto} pair`, function() { - it("should support pair-pair", function(done) { + describe(`compat socket with ${proto} pair`, function () { + it("should support pair-pair", function (done) { const pairA = zmq.socket("pair") const pairB = zmq.socket("pair") @@ -16,7 +16,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { pairB.monitor() pairA.on("bindError", console.log) pairB.on("bindError", console.log) - pairA.on("message", function(msg) { + pairA.on("message", function (msg) { assert.instanceOf(msg, Buffer) switch (n++) { @@ -35,13 +35,15 @@ if (process.env.INCLUDE_COMPAT_TESTS) { } }) - pairB.on("message", function(msg) { + pairB.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "barnacle") }) pairA.bind(address, async err => { - if (err) throw err + if (err) { + throw err + } pairB.connect(address) pairA.send("barnacle") diff --git a/test/unit/compat/socket-pub-sub-test.js b/test/unit/compat/socket-pub-sub-test.js index da181b76..60467ba1 100644 --- a/test/unit/compat/socket-pub-sub-test.js +++ b/test/unit/compat/socket-pub-sub-test.js @@ -4,20 +4,21 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto} pub-sub`, function() { - let pub, sub + describe(`compat socket with ${proto} pub-sub`, function () { + let pub + let sub - beforeEach(function() { + beforeEach(function () { pub = zmq.socket("pub") sub = zmq.socket("sub") }) - it("should support pub-sub", function(done) { + it("should support pub-sub", function (done) { const address = uniqAddress(proto) let n = 0 sub.subscribe("") - sub.on("message", function(msg) { + sub.on("message", function (msg) { assert.instanceOf(msg, Buffer) switch (n++) { case 0: @@ -36,7 +37,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) sub.bind(address, err => { - if (err) throw err + if (err) { + throw err + } pub.connect(address) // The connect is asynchronous, and messages published to a non- @@ -56,14 +59,14 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - it("should support pub-sub filter", function(done) { + it("should support pub-sub filter", function (done) { const address = uniqAddress(proto) let n = 0 sub.subscribe("js") sub.subscribe("luna") - sub.on("message", function(msg) { + sub.on("message", function (msg) { assert.instanceOf(msg, Buffer) switch (n++) { case 0: @@ -79,7 +82,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) sub.bind(address, err => { - if (err) throw err + if (err) { + throw err + } pub.connect(address) // See comments on pub-sub test. @@ -93,28 +98,31 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - describe("with errors", function() { - before(function() { - this.uncaughtExceptionListeners = process.listeners("uncaughtException") + describe("with errors", function () { + before(function () { + this.uncaughtExceptionListeners = + process.listeners("uncaughtException") process.removeAllListeners("uncaughtException") }) - after(function() { + after(function () { process.removeAllListeners("uncaughtException") for (const listener of this.uncaughtExceptionListeners) { process.on("uncaughtException", listener) } }) - it("should continue to deliver messages in message handler", function(done) { + it("should continue to deliver messages in message handler", function (done) { let error - process.once("uncaughtException", err => {error = err}) + process.once("uncaughtException", err => { + error = err + }) const address = uniqAddress(proto) let n = 0 sub.subscribe("") - sub.on("message", function(msg) { + sub.on("message", function (msg) { assert.instanceOf(msg, Buffer) switch (n++) { case 0: @@ -132,7 +140,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) sub.bind(address, err => { - if (err) throw err + if (err) { + throw err + } pub.connect(address) setTimeout(() => { diff --git a/test/unit/compat/socket-push-pull-test.js b/test/unit/compat/socket-push-pull-test.js index 263a553b..c589bf8d 100644 --- a/test/unit/compat/socket-push-pull-test.js +++ b/test/unit/compat/socket-push-pull-test.js @@ -4,15 +4,15 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto} push-pull`, function() { - it("should support push-pull", function(done) { + describe(`compat socket with ${proto} push-pull`, function () { + it("should support push-pull", function (done) { const push = zmq.socket("push") const pull = zmq.socket("pull") const address = uniqAddress(proto) let n = 0 - pull.on("message", function(msg) { + pull.on("message", function (msg) { assert.instanceOf(msg, Buffer) switch (n++) { case 0: @@ -31,7 +31,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) pull.bind(address, err => { - if (err) throw err + if (err) { + throw err + } push.connect(address) push.send("foo") @@ -40,8 +42,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - - it("should not emit messages after pause", function(done) { + it("should not emit messages after pause", function (done) { const push = zmq.socket("push") const pull = zmq.socket("pull") @@ -49,7 +50,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { let n = 0 - pull.on("message", function(msg) { + pull.on("message", function (msg) { if (n++ === 0) { assert.equal(msg.toString(), "foo") } else { @@ -58,7 +59,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) pull.bind(address, err => { - if (err) throw err + if (err) { + throw err + } push.connect(address) push.send("foo") @@ -74,7 +77,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }, 15) }) - it("should be able to read messages after pause", function(done) { + it("should be able to read messages after pause", function (done) { const push = zmq.socket("push") const pull = zmq.socket("pull") @@ -82,11 +85,13 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const messages = ["bar", "foo"] pull.bind(address, err => { - if (err) throw err + if (err) { + throw err + } push.connect(address) pull.pause() - messages.forEach(function(message) { + messages.forEach(function (message) { push.send(message) }) @@ -103,8 +108,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }, 15) }) - - it("should emit messages after resume", function(done) { + it("should emit messages after resume", function (done) { const push = zmq.socket("push") const pull = zmq.socket("pull") @@ -137,7 +141,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) { pull.on("message", checkNoMessages) pull.bind(address, err => { - if (err) throw err + if (err) { + throw err + } push.connect(address) pull.pause() diff --git a/test/unit/compat/socket-req-rep-test.js b/test/unit/compat/socket-req-rep-test.js index 3702f3c1..d83168e0 100644 --- a/test/unit/compat/socket-req-rep-test.js +++ b/test/unit/compat/socket-req-rep-test.js @@ -4,24 +4,26 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto} req-rep`, function() { - it("should support req-rep", function(done) { + describe(`compat socket with ${proto} req-rep`, function () { + it("should support req-rep", function (done) { const rep = zmq.socket("rep") const req = zmq.socket("req") const address = uniqAddress(proto) - rep.on("message", function(msg) { + rep.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") rep.send("world") }) rep.bind(address, err => { - if (err) throw err + if (err) { + throw err + } req.connect(address) req.send("hello") - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "world") rep.close() @@ -31,59 +33,65 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - it("should support multiple", function(done) { - let n = 5 + it("should support multiple", function (done) { + const n = 5 for (let i = 0; i < n; i++) { - (function(n) { + ;(function (n) { const rep = zmq.socket("rep") const req = zmq.socket("req") const address = uniqAddress(proto) - rep.on("message", function(msg) { + rep.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") rep.send("world") }) rep.bind(address, err => { - if (err) throw err + if (err) { + throw err + } req.connect(address) req.send("hello") - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "world") req.close() rep.close() - if (!--n) done() + if (!--n) { + done() + } }) }) })(i) } }) - it("should support a burst", function(done) { + it("should support a burst", function (done) { const rep = zmq.socket("rep") const req = zmq.socket("req") const address = uniqAddress(proto) - let n = 10 + const n = 10 - rep.on("message", function(msg) { + rep.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") rep.send("world") }) rep.bind(address, err => { - if (err) throw err + if (err) { + throw err + } req.connect(address) let received = 0 - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "world") diff --git a/test/unit/compat/socket-router-test.js b/test/unit/compat/socket-router-test.js index a52863dd..8413ffb8 100644 --- a/test/unit/compat/socket-router-test.js +++ b/test/unit/compat/socket-router-test.js @@ -4,13 +4,14 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto} router`, function() { - it("should handle unroutable messages", function(done) { + describe(`compat socket with ${proto} router`, function () { + it("should handle unroutable messages", function (done) { let complete = 0 const envelope = "12384982398293" - const errMsgs = require("os").platform() === "win32" ? ["Unknown error"] : [] + const errMsgs = + require("os").platform() === "win32" ? ["Unknown error"] : [] errMsgs.push("No route to host") errMsgs.push("Resource temporarily unavailable") errMsgs.push("Host unreachable") @@ -27,7 +28,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) { sockA.on("error", err => { sockA.close() assertRouteError(err) - if (++complete === 2) done() + if (++complete === 2) { + done() + } }) sockA.setsockopt(zmq.ZMQ_ROUTER_MANDATORY, 1) @@ -63,10 +66,12 @@ if (process.env.INCLUDE_COMPAT_TESTS) { sockC.send([envelope, ""]) sockC.close() - if (++complete === 2) done() + if (++complete === 2) { + done() + } }) - it("should handle router-dealer message bursts", function(done) { + it("should handle router-dealer message bursts", function (done) { this.slow(150) // tests https://github.com/JustinTulloss/zeromq.node/issues/523 // based on https://gist.github.com/messa/862638ab44ca65f712fe4d6ef79aeb67 @@ -80,13 +85,15 @@ if (process.env.INCLUDE_COMPAT_TESTS) { let counted = 0 router.bind(address, err => { - if (err) throw err + if (err) { + throw err + } - router.on("message", function(...msg) { + router.on("message", function (...msg) { router.send(msg) }) - dealer.on("message", function(part1, part2, part3, part4, part5) { + dealer.on("message", function (part1, part2, part3, part4, part5) { assert.equal(part1.toString(), "Hello") assert.equal(part2.toString(), "world") assert.equal(part3.toString(), "part3") diff --git a/test/unit/compat/socket-stream-test.js b/test/unit/compat/socket-stream-test.js index a67ef8f8..6dcb4ace 100644 --- a/test/unit/compat/socket-stream-test.js +++ b/test/unit/compat/socket-stream-test.js @@ -4,54 +4,65 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") const http = require("http") - describe("compat socket stream", function() { - it("should support a stream socket type", function(done) { + describe("compat socket stream", function () { + it("should support a stream socket type", function (done) { const stream = zmq.socket("stream") const address = uniqAddress("tcp") - stream.on("message", function(id, msg) { + stream.on("message", function (id, msg) { assert.instanceOf(msg, Buffer) - if (msg.length == 0) return + if (msg.length == 0) { + return + } const raw_header = String(msg).split("\r\n") const method = raw_header[0].split(" ")[0] assert.equal(method, "GET") //finding an HTTP GET method, prepare HTTP response for TCP socket - const httpProtocolString = "HTTP/1.0 200 OK\r\n" //status code - + "Content-Type: text/html\r\n" //headers - + "\r\n" - + "" //response body - + "" //make it xml, json, html or something else - + "" - + "" - + "" - + "

derpin over protocols

" - + "" - + "" + const httpProtocolString = + "HTTP/1.0 200 OK\r\n" + //status code + "Content-Type: text/html\r\n" + //headers + "\r\n" + + "" + //response body + "" + //make it xml, json, html or something else + "" + + "" + + "" + + "

derpin over protocols

" + + "" + + "" //zmq streaming prefixed by envelope"s routing identifier stream.send([id, httpProtocolString]) }) stream.bind(address, err => { - if (err) throw err + if (err) { + throw err + } //send non-peer request to zmq, like an http GET method with URI path - http.get(address.replace("tcp:", "http:") + "/aRandomRequestPath", function(httpMsg) { - assert.equal(httpMsg.socket._readableState.reading, false) - - httpMsg.on("data", function(msg) { - assert.instanceOf(msg, Buffer) - assert.equal(msg.toString(), "" - + "" - + "

derpin over protocols

" - + "" - + "") - stream.close() - done() - }) - }) + http.get( + `${address.replace("tcp:", "http:")}/aRandomRequestPath`, + function (httpMsg) { + assert.equal(httpMsg.socket._readableState.reading, false) + + httpMsg.on("data", function (msg) { + assert.instanceOf(msg, Buffer) + assert.equal( + msg.toString(), + "" + + "" + + "

derpin over protocols

" + + "" + + "", + ) + stream.close() + done() + }) + }, + ) }) }) }) diff --git a/test/unit/compat/socket-test.js b/test/unit/compat/socket-test.js index 24625b82..bf8d178f 100644 --- a/test/unit/compat/socket-test.js +++ b/test/unit/compat/socket-test.js @@ -2,34 +2,34 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const zmq = require("./load") const {assert} = require("chai") - describe("compat socket", function() { + describe("compat socket", function () { let sock - beforeEach(function() { + beforeEach(function () { sock = zmq.socket("req") }) - afterEach(function() { + afterEach(function () { sock.close() }) - it("should alias socket", function() { + it("should alias socket", function () { assert.equal(zmq.createSocket, zmq.socket) }) - it("should include type and close", function() { + it("should include type and close", function () { assert.equal(sock.type, "req") assert.typeOf(sock.close, "function") }) - it("should use socketopt", function() { + it("should use socketopt", function () { assert.notEqual(sock.getsockopt(zmq.ZMQ_BACKLOG), 75) assert.equal(sock.setsockopt(zmq.ZMQ_BACKLOG, 75), sock) assert.equal(sock.getsockopt(zmq.ZMQ_BACKLOG), 75) sock.setsockopt(zmq.ZMQ_BACKLOG, 100) }) - it("should use socketopt with sugar", function() { + it("should use socketopt with sugar", function () { assert.notEqual(sock.getsockopt("backlog"), 75) assert.equal(sock.setsockopt("backlog", 75), sock) assert.equal(sock.getsockopt("backlog"), 75) @@ -40,12 +40,12 @@ if (process.env.INCLUDE_COMPAT_TESTS) { assert.equal(sock.backlog, 50) }) - it("should close", function() { + it("should close", function () { sock.close() assert.equal(sock.closed, true) }) - it("should support options", function() { + it("should support options", function () { sock.close() sock = zmq.socket("req", {backlog: 30}) assert.equal(sock.getsockopt("backlog"), 30) diff --git a/test/unit/compat/socket-unbind-test.js b/test/unit/compat/socket-unbind-test.js index 20cf6ab8..dfb72bb8 100644 --- a/test/unit/compat/socket-unbind-test.js +++ b/test/unit/compat/socket-unbind-test.js @@ -1,33 +1,40 @@ /* This test is very unreliable in practice, especially in CI. It is disabled by default. */ -if (process.env.INCLUDE_COMPAT_TESTS && process.env.INCLUDE_COMPAT_UNBIND_TEST) { +if ( + process.env.INCLUDE_COMPAT_TESTS && + process.env.INCLUDE_COMPAT_UNBIND_TEST +) { const zmq = require("./load") const semver = require("semver") const {assert} = require("chai") const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp")) { - describe(`compat socket with ${proto} unbind`, function() { - beforeEach(function() { + describe(`compat socket with ${proto} unbind`, function () { + beforeEach(function () { /* Seems < 4.2 is affected by https://github.com/zeromq/libzmq/issues/1583 */ - if (semver.satisfies(zmq.version, "< 4.2")) this.skip() + if (semver.satisfies(zmq.version, "< 4.2")) { + this.skip() + } }) - let sockA, sockB, sockC + let sockA + let sockB + let sockC - beforeEach(function() { + beforeEach(function () { sockA = zmq.socket("dealer", {linger: 0}) sockB = zmq.socket("dealer", {linger: 0}) sockC = zmq.socket("dealer", {linger: 0}) }) - afterEach(function() { + afterEach(function () { sockA.close() sockB.close() sockC.close() }) - it("should be able to unbind", function(done) { + it("should be able to unbind", function (done) { const address1 = uniqAddress(proto) const address2 = uniqAddress(proto) @@ -35,7 +42,7 @@ if (process.env.INCLUDE_COMPAT_TESTS && process.env.INCLUDE_COMPAT_UNBIND_TEST) sockA.bindSync(address1) sockA.bindSync(address2) - sockA.on("unbind", async function(addr) { + sockA.on("unbind", async function (addr) { if (addr === address1) { sockB.send("Error from sockB.") sockC.send("Messsage from sockC.") @@ -43,7 +50,7 @@ if (process.env.INCLUDE_COMPAT_TESTS && process.env.INCLUDE_COMPAT_UNBIND_TEST) } }) - sockA.on("message", async function(msg) { + sockA.on("message", async function (msg) { msgCount++ if (msg.toString() === "Hello from sockB.") { sockA.unbindSync(address1) diff --git a/test/unit/compat/socket-xpub-xsub-test.js b/test/unit/compat/socket-xpub-xsub-test.js index 76d7afcd..f101a94c 100644 --- a/test/unit/compat/socket-xpub-xsub-test.js +++ b/test/unit/compat/socket-xpub-xsub-test.js @@ -4,8 +4,8 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto} xpub-xsub`, function() { - it("should support pub-sub tracing and filtering", function(done) { + describe(`compat socket with ${proto} xpub-xsub`, function () { + it("should support pub-sub tracing and filtering", function (done) { let n = 0 let m = 0 const pub = zmq.socket("pub") @@ -17,18 +17,22 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const address2 = uniqAddress(proto) pub.bind(address1, err => { - if (err) throw err + if (err) { + throw err + } xsub.connect(address1) xpub.bind(address2, err => { - if (err) throw err + if (err) { + throw err + } sub.connect(address2) - xsub.on("message", function(msg) { + xsub.on("message", function (msg) { xpub.send(msg) // Forward message using the xpub so subscribers can receive it }) - xpub.on("message", function(msg) { + xpub.on("message", function (msg) { assert.instanceOf(msg, Buffer) const type = msg[0] === 0 ? "unsubscribe" : "subscribe" @@ -62,7 +66,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { xsub.send(msg) // Forward message using the xsub so the publisher knows it has a subscriber }) - sub.on("message", function(msg) { + sub.on("message", function (msg) { assert.instanceOf(msg, Buffer) switch (n++) { case 0: diff --git a/test/unit/compat/socket-zap-test.js b/test/unit/compat/socket-zap-test.js index 2c6c4551..11973829 100644 --- a/test/unit/compat/socket-zap-test.js +++ b/test/unit/compat/socket-zap-test.js @@ -7,21 +7,25 @@ if (process.env.INCLUDE_COMPAT_TESTS) { function start() { const zap = zmq.socket("router") - zap.on("message", function() { + zap.on("message", function () { const data = Array.prototype.slice.call(arguments) - if (!data || !data.length) throw new Error("Invalid ZAP request") + if (!data || !data.length) { + throw new Error("Invalid ZAP request") + } const returnPath = [] let frame = data.shift() - while (frame && (frame.length != 0)) { + while (frame && frame.length != 0) { returnPath.push(frame) frame = data.shift() } returnPath.push(frame) - if (data.length < 6) throw new Error("Invalid ZAP request") + if (data.length < 6) { + throw new Error("Invalid ZAP request") + } const zapReq = { version: data.shift(), @@ -30,63 +34,85 @@ if (process.env.INCLUDE_COMPAT_TESTS) { address: Buffer.from(data.shift()).toString("utf8"), identity: Buffer.from(data.shift()).toString("utf8"), mechanism: Buffer.from(data.shift()).toString("utf8"), - credentials: data.slice(0) + credentials: data.slice(0), } - zap.send(returnPath.concat([ - zapReq.version, - zapReq.requestId, - Buffer.from("200", "utf8"), - Buffer.from("OK", "utf8"), - Buffer.alloc(0), - Buffer.alloc(0) - ])) + zap.send( + returnPath.concat([ + zapReq.version, + zapReq.requestId, + Buffer.from("200", "utf8"), + Buffer.from("OK", "utf8"), + Buffer.alloc(0), + Buffer.alloc(0), + ]), + ) }) return new Promise((resolve, reject) => { zap.bind("inproc://zeromq.zap.01", err => { - if (err) return reject(err) + if (err) { + return reject(err) + } resolve(zap) }) }) } for (const proto of testProtos("tcp", "inproc")) { - describe(`compat socket with ${proto} zap`, function() { - let zapSocket, rep, req + describe(`compat socket with ${proto} zap`, function () { + let zapSocket + let rep + let req - before(async function() { + before(async function () { zapSocket = await start() }) - after(async function() { + after(async function () { zapSocket.close() await new Promise(resolve => setTimeout(resolve, 15)) }) - beforeEach(function() { + beforeEach(function () { /* Since ZAP uses inproc transport, it does not work reliably. */ - if (semver.satisfies(zmq.version, "< 4.2")) this.skip() + if (semver.satisfies(zmq.version, "< 4.2")) { + this.skip() + } rep = zmq.socket("rep") req = zmq.socket("req") }) - afterEach(function() { + afterEach(function () { req.close() rep.close() }) - it("should support curve", function(done) { - if (!zmq.capability.curve) this.skip() + it("should support curve", function (done) { + if (!zmq.capability.curve) { + this.skip() + } const address = uniqAddress(proto) - const serverPublicKey = Buffer.from("7f188e5244b02bf497b86de417515cf4d4053ce4eb977aee91a55354655ec33a", "hex") - const serverPrivateKey = Buffer.from("1f5d3873472f95e11f4723d858aaf0919ab1fb402cb3097742c606e61dd0d7d8", "hex") - const clientPublicKey = Buffer.from("ea1cc8bd7c8af65497d43fc21dbec6560c5e7b61bcfdcbd2b0dfacf0b4c38d45", "hex") - const clientPrivateKey = Buffer.from("83f99afacfab052406e5f421612568034e85f4c8182a1c92671e83dca669d31d", "hex") - - rep.on("message", function(msg) { + const serverPublicKey = Buffer.from( + "7f188e5244b02bf497b86de417515cf4d4053ce4eb977aee91a55354655ec33a", + "hex", + ) + const serverPrivateKey = Buffer.from( + "1f5d3873472f95e11f4723d858aaf0919ab1fb402cb3097742c606e61dd0d7d8", + "hex", + ) + const clientPublicKey = Buffer.from( + "ea1cc8bd7c8af65497d43fc21dbec6560c5e7b61bcfdcbd2b0dfacf0b4c38d45", + "hex", + ) + const clientPrivateKey = Buffer.from( + "83f99afacfab052406e5f421612568034e85f4c8182a1c92671e83dca669d31d", + "hex", + ) + + rep.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") rep.send("world") @@ -98,7 +124,9 @@ if (process.env.INCLUDE_COMPAT_TESTS) { assert.equal(rep.mechanism, 2) rep.bind(address, err => { - if (err) throw err + if (err) { + throw err + } req.curve_serverkey = serverPublicKey req.curve_publickey = clientPublicKey req.curve_secretkey = clientPrivateKey @@ -106,19 +134,18 @@ if (process.env.INCLUDE_COMPAT_TESTS) { req.connect(address) req.send("hello") - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "world") done() }) }) - }) - it("should support null", function(done) { + it("should support null", function (done) { const address = uniqAddress(proto) - rep.on("message", function(msg) { + rep.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") rep.send("world") @@ -128,11 +155,13 @@ if (process.env.INCLUDE_COMPAT_TESTS) { assert.equal(rep.mechanism, 0) rep.bind(address, err => { - if (err) throw err + if (err) { + throw err + } assert.equal(req.mechanism, 0) req.connect(address) req.send("hello") - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "world") done() @@ -140,10 +169,10 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - it("should support plain", function(done) { + it("should support plain", function (done) { const address = uniqAddress(proto) - rep.on("message", function(msg) { + rep.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "hello") rep.send("world") @@ -154,14 +183,16 @@ if (process.env.INCLUDE_COMPAT_TESTS) { assert.equal(rep.mechanism, 1) rep.bind(address, err => { - if (err) throw err + if (err) { + throw err + } req.plain_username = "user" req.plain_password = "pass" assert.equal(req.mechanism, 1) req.connect(address) req.send("hello") - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "world") done() diff --git a/test/unit/compat/zmq-proxy-push-pull-test.js b/test/unit/compat/zmq-proxy-push-pull-test.js index 12003be9..41837694 100644 --- a/test/unit/compat/zmq-proxy-push-pull-test.js +++ b/test/unit/compat/zmq-proxy-push-pull-test.js @@ -4,16 +4,16 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp")) { - describe(`compat proxy with ${proto} push-pull`, function() { + describe(`compat proxy with ${proto} push-pull`, function () { const sockets = [] - afterEach(function() { + afterEach(function () { while (sockets.length) { sockets.pop().close() } }) - it("should proxy push-pull connected to pull-push", function(done) { + it("should proxy push-pull connected to pull-push", function (done) { const frontendAddr = uniqAddress(proto) const backendAddr = uniqAddress(proto) @@ -24,9 +24,13 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const push = zmq.socket("push") frontend.bind(frontendAddr, err => { - if (err) throw err + if (err) { + throw err + } backend.bind(backendAddr, err => { - if (err) throw err + if (err) { + throw err + } push.connect(frontendAddr) pull.connect(backendAddr) sockets.push(frontend, backend, push, pull) @@ -43,7 +47,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - it("should proxy pull-push connected to push-pull with capture", function(done) { + it("should proxy pull-push connected to push-pull with capture", function (done) { const frontendAddr = uniqAddress(proto) const backendAddr = uniqAddress(proto) const captureAddr = uniqAddress(proto) @@ -59,30 +63,40 @@ if (process.env.INCLUDE_COMPAT_TESTS) { sockets.push(frontend, backend, push, pull, capture, capSub) frontend.bind(frontendAddr, err => { - if (err) throw err + if (err) { + throw err + } backend.bind(backendAddr, err => { - if (err) throw err + if (err) { + throw err + } capture.bind(captureAddr, err => { - if (err) throw err + if (err) { + throw err + } pull.connect(frontendAddr) push.connect(backendAddr) capSub.connect(captureAddr) let counter = 2 - pull.on("message", function(msg) { + pull.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "foo") - if (--counter == 0) done() + if (--counter == 0) { + done() + } }) capSub.subscribe("") - capSub.on("message", function(msg) { + capSub.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "foo") - if (--counter == 0) done() + if (--counter == 0) { + done() + } }) setTimeout(() => push.send("foo"), 15) diff --git a/test/unit/compat/zmq-proxy-router-dealer-test.js b/test/unit/compat/zmq-proxy-router-dealer-test.js index 1084501a..148412dd 100644 --- a/test/unit/compat/zmq-proxy-router-dealer-test.js +++ b/test/unit/compat/zmq-proxy-router-dealer-test.js @@ -4,16 +4,16 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp")) { - describe(`compat proxy with ${proto} router-dealer`, function() { + describe(`compat proxy with ${proto} router-dealer`, function () { const sockets = [] - afterEach(function() { + afterEach(function () { while (sockets.length) { sockets.pop().close() } }) - it("should proxy req-rep connected over router-dealer", function(done) { + it("should proxy req-rep connected over router-dealer", function (done) { const frontendAddr = uniqAddress(proto) const backendAddr = uniqAddress(proto) @@ -24,22 +24,26 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const req = zmq.socket("req") frontend.bind(frontendAddr, err => { - if (err) throw err + if (err) { + throw err + } backend.bind(backendAddr, err => { - if (err) throw err + if (err) { + throw err + } req.connect(frontendAddr) rep.connect(backendAddr) sockets.push(frontend, backend, req, rep) - req.on("message", function(msg) { + req.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "foo bar") done() }) - rep.on("message", function(msg) { - rep.send(msg + " bar") + rep.on("message", function (msg) { + rep.send(`${msg} bar`) }) setTimeout(() => req.send("foo"), 15) @@ -48,7 +52,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - it("should proxy rep-req connections with capture", function(done) { + it("should proxy rep-req connections with capture", function (done) { const frontendAddr = uniqAddress(proto) const backendAddr = uniqAddress(proto) const captureAddr = uniqAddress(proto) @@ -63,11 +67,17 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const capSub = zmq.socket("sub") frontend.bind(frontendAddr, err => { - if (err) throw err + if (err) { + throw err + } backend.bind(backendAddr, err => { - if (err) throw err + if (err) { + throw err + } capture.bind(captureAddr, err => { - if (err) throw err + if (err) { + throw err + } req.connect(frontendAddr) rep.connect(backendAddr) @@ -77,19 +87,23 @@ if (process.env.INCLUDE_COMPAT_TESTS) { let counter = 2 - req.on("message", function(msg) { - if (--counter == 0) done() + req.on("message", function (msg) { + if (--counter == 0) { + done() + } }) - rep.on("message", function(msg) { - rep.send(msg + " bar") + rep.on("message", function (msg) { + rep.send(`${msg} bar`) }) - capSub.on("message", function(msg) { + capSub.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "foo bar") - if (--counter == 0) done() + if (--counter == 0) { + done() + } }) setTimeout(() => req.send("foo"), 15) diff --git a/test/unit/compat/zmq-proxy-test.js b/test/unit/compat/zmq-proxy-test.js index 7f893d71..8146a89f 100644 --- a/test/unit/compat/zmq-proxy-test.js +++ b/test/unit/compat/zmq-proxy-test.js @@ -2,8 +2,8 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const zmq = require("./load") const {assert} = require("chai") - describe("compat proxy", function() { - it("should be a function off the module namespace", function() { + describe("compat proxy", function () { + it("should be a function off the module namespace", function () { assert.typeOf(zmq.proxy, "function") }) }) diff --git a/test/unit/compat/zmq-proxy-xpub-xsub-test.js b/test/unit/compat/zmq-proxy-xpub-xsub-test.js index c687f77d..c0580fca 100644 --- a/test/unit/compat/zmq-proxy-xpub-xsub-test.js +++ b/test/unit/compat/zmq-proxy-xpub-xsub-test.js @@ -4,16 +4,16 @@ if (process.env.INCLUDE_COMPAT_TESTS) { const {testProtos, uniqAddress} = require("../helpers") for (const proto of testProtos("tcp")) { - describe(`compat proxy with ${proto} xpub-xsub`, function() { + describe(`compat proxy with ${proto} xpub-xsub`, function () { const sockets = [] - afterEach(function() { + afterEach(function () { while (sockets.length) { sockets.pop().close() } }) - it("should proxy pub-sub connected to xpub-xsub", function(done) { + it("should proxy pub-sub connected to xpub-xsub", function (done) { const frontendAddr = uniqAddress(proto) const backendAddr = uniqAddress(proto) @@ -25,16 +25,20 @@ if (process.env.INCLUDE_COMPAT_TESTS) { sockets.push(frontend, backend, sub, pub) sub.subscribe("") - sub.on("message", function(msg) { + sub.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "foo") done() }) frontend.bind(frontendAddr, err => { - if (err) throw err + if (err) { + throw err + } backend.bind(backendAddr, err => { - if (err) throw err + if (err) { + throw err + } sub.connect(frontendAddr) pub.connect(backendAddr) @@ -45,7 +49,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - it("should proxy connections with capture", function(done) { + it("should proxy connections with capture", function (done) { const frontendAddr = uniqAddress(proto) const backendAddr = uniqAddress(proto) const captureAddr = uniqAddress(proto) @@ -63,27 +67,37 @@ if (process.env.INCLUDE_COMPAT_TESTS) { let counter = 2 sub.subscribe("") - sub.on("message", function(msg) { + sub.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "foo") - if (--counter == 0) done() + if (--counter == 0) { + done() + } }) capSub.subscribe("") - capSub.on("message", function(msg) { + capSub.on("message", function (msg) { assert.instanceOf(msg, Buffer) assert.equal(msg.toString(), "foo") - if (--counter == 0) done() + if (--counter == 0) { + done() + } }) capture.bind(captureAddr, err => { - if (err) throw err + if (err) { + throw err + } frontend.bind(frontendAddr, err => { - if (err) throw err + if (err) { + throw err + } backend.bind(backendAddr, err => { - if (err) throw err + if (err) { + throw err + } pub.connect(backendAddr) sub.connect(frontendAddr) @@ -96,7 +110,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) { }) }) - it("should throw an error if the order is wrong", function() { + it("should throw an error if the order is wrong", function () { const frontend = zmq.socket("xpub") const backend = zmq.socket("xsub") @@ -105,10 +119,13 @@ if (process.env.INCLUDE_COMPAT_TESTS) { try { zmq.proxy(backend, frontend) } catch (err) { - assert.include([ - "wrong socket order to proxy", - "This socket type order is not supported in compatibility mode", - ], err.message) + assert.include( + [ + "wrong socket order to proxy", + "This socket type order is not supported in compatibility mode", + ], + err.message, + ) } }) }) diff --git a/test/unit/context-construction-test.ts b/test/unit/context-construction-test.ts index f4c57b8b..6b8e70c0 100644 --- a/test/unit/context-construction-test.ts +++ b/test/unit/context-construction-test.ts @@ -2,12 +2,12 @@ import * as zmq from "../../src" import {assert} from "chai" -describe("context construction", function() { - afterEach(function() { +describe("context construction", function () { + afterEach(function () { global.gc?.() }) - it("should throw if called as function", function() { + it("should throw if called as function", function () { assert.throws( () => (zmq.Context as any)(), TypeError, @@ -15,7 +15,7 @@ describe("context construction", function() { ) }) - it("should throw with wrong options argument", function() { + it("should throw with wrong options argument", function () { assert.throws( () => new (zmq.Context as any)(1), TypeError, @@ -23,7 +23,7 @@ describe("context construction", function() { ) }) - it("should throw with too many arguments", function() { + it("should throw with too many arguments", function () { assert.throws( () => new (zmq.Context as any)({}, 2), TypeError, @@ -31,12 +31,12 @@ describe("context construction", function() { ) }) - it("should set option", function() { + it("should set option", function () { const context = new zmq.Context({ioThreads: 5}) assert.equal(context.ioThreads, 5) }) - it("should throw with invalid option value", function() { + it("should throw with invalid option value", function () { assert.throws( () => new (zmq.Context as any)({ioThreads: "hello"}), TypeError, @@ -44,7 +44,7 @@ describe("context construction", function() { ) }) - it("should throw with readonly option", function() { + it("should throw with readonly option", function () { assert.throws( () => new (zmq.Context as any)({maxSocketsLimit: 1}), TypeError, @@ -52,7 +52,7 @@ describe("context construction", function() { ) }) - it("should throw with unknown option", function() { + it("should throw with unknown option", function () { assert.throws( () => new (zmq.Context as any)({doesNotExist: 1}), TypeError, diff --git a/test/unit/context-options-test.ts b/test/unit/context-options-test.ts index 95b50d2a..6e344114 100644 --- a/test/unit/context-options-test.ts +++ b/test/unit/context-options-test.ts @@ -2,26 +2,26 @@ import * as zmq from "../../src" import {assert} from "chai" -describe("context options", function() { - afterEach(function() { +describe("context options", function () { + afterEach(function () { global.gc?.() }) - it("should set and get bool socket option", function() { + it("should set and get bool socket option", function () { const context = new zmq.Context() assert.equal(context.ipv6, false) context.ipv6 = true assert.equal(context.ipv6, true) }) - it("should set and get int socket option", function() { + it("should set and get int socket option", function () { const context = new zmq.Context() assert.equal(context.ioThreads, 1) context.ioThreads = 75 assert.equal(context.ioThreads, 75) }) - it("should throw for readonly option", function() { + it("should throw for readonly option", function () { const context = new zmq.Context() assert.throws( () => ((context as any).maxSocketsLimit = 1), @@ -30,7 +30,7 @@ describe("context options", function() { ) }) - it("should throw for unknown option", function() { + it("should throw for unknown option", function () { const context = new zmq.Context() assert.throws( () => ((context as any).doesNotExist = 1), diff --git a/test/unit/context-process-exit-test.ts b/test/unit/context-process-exit-test.ts index 8bdbf9bd..8eebc58f 100644 --- a/test/unit/context-process-exit-test.ts +++ b/test/unit/context-process-exit-test.ts @@ -4,9 +4,9 @@ import * as zmq from "../../src" import {assert} from "chai" import {createProcess} from "./helpers" -describe("context process exit", function() { - describe("with default context", function() { - it("should occur when sockets are closed", async function() { +describe("context process exit", function () { + describe("with default context", function () { + it("should occur when sockets are closed", async function () { this.slow(200) const {code} = await createProcess(() => { const socket1 = new zmq.Dealer() @@ -18,7 +18,7 @@ describe("context process exit", function() { assert.equal(code, 0) }) - it("should occur when sockets are not closed", async function() { + it("should occur when sockets are not closed", async function () { this.slow(200) const {code} = await createProcess(() => { const socket1 = new zmq.Dealer() @@ -28,7 +28,7 @@ describe("context process exit", function() { assert.equal(code, 0) }) - it("should not occur when sockets are open and polling", async function() { + it("should not occur when sockets are open and polling", async function () { this.slow(1000) const {code} = await createProcess(() => { const socket1 = new zmq.Dealer() @@ -39,7 +39,7 @@ describe("context process exit", function() { assert.equal(code, -1) }) - it("should produce warning when messages are queued with blocky", async function() { + it("should produce warning when messages are queued with blocky", async function () { this.slow(2000) const {stderr} = await createProcess(() => { zmq.context.blocky = true @@ -61,7 +61,7 @@ describe("context process exit", function() { } }) - it("should produce warning when messages are queued without blocky", async function() { + it("should produce warning when messages are queued without blocky", async function () { this.slow(2000) const {stderr} = await createProcess(() => { zmq.context.blocky = false @@ -76,7 +76,7 @@ describe("context process exit", function() { ) }) - it("should not produce warning when messages are queued for a short time", async function() { + it("should not produce warning when messages are queued for a short time", async function () { this.slow(1000) const {stderr} = await createProcess(() => { zmq.context.blocky = true @@ -89,8 +89,8 @@ describe("context process exit", function() { }) }) - describe("with custom context", function() { - it("should occur when sockets are closed", async function() { + describe("with custom context", function () { + it("should occur when sockets are closed", async function () { this.slow(200) const {code} = await createProcess(() => { const context = new zmq.Context() @@ -103,7 +103,7 @@ describe("context process exit", function() { assert.equal(code, 0) }) - it("should occur when sockets are closed and context is gced", async function() { + it("should occur when sockets are closed and context is gced", async function () { this.slow(200) const {code} = await createProcess(() => { function run() { @@ -121,7 +121,7 @@ describe("context process exit", function() { assert.equal(code, 0) }) - it("should occur when sockets are not closed", async function() { + it("should occur when sockets are not closed", async function () { this.slow(200) const {code} = await createProcess(() => { const context = new zmq.Context() @@ -132,7 +132,7 @@ describe("context process exit", function() { assert.equal(code, 0) }) - it("should not occur when sockets are open and polling", async function() { + it("should not occur when sockets are open and polling", async function () { this.slow(1000) const {code} = await createProcess(() => { const context = new zmq.Context() diff --git a/test/unit/context-thread-test.ts b/test/unit/context-thread-test.ts index 83f8e687..3d44a206 100644 --- a/test/unit/context-thread-test.ts +++ b/test/unit/context-thread-test.ts @@ -4,17 +4,19 @@ import * as zmq from "../../src" import {assert} from "chai" import {createWorker} from "./helpers" -describe("context in thread", function() { +describe("context in thread", function () { this.slow(2000) this.timeout(5000) - beforeEach(function() { + beforeEach(function () { /* Node.js worker support introduced in version 10.5. */ - if (semver.satisfies(process.versions.node, "< 10.5")) this.skip() + if (semver.satisfies(process.versions.node, "< 10.5")) { + this.skip() + } }) - describe("with default context", function() { - it("should be shared", async function() { + describe("with default context", function () { + it("should be shared", async function () { try { zmq.context.ioThreads = 3 diff --git a/test/unit/helpers.ts b/test/unit/helpers.ts index 73bded4f..a0088607 100644 --- a/test/unit/helpers.ts +++ b/test/unit/helpers.ts @@ -37,12 +37,18 @@ export function testProtos(...requested: Proto[]) { const set = new Set(requested) /* Do not test with ipc if unsupported. */ - if (!zmq.capability.ipc) set.delete("ipc") + if (!zmq.capability.ipc) { + set.delete("ipc") + } /* Only test inproc with version 4.2+, earlier versions are unreliable. */ - if (semver.satisfies(zmq.version, "< 4.2")) set.delete("inproc") + if (semver.satisfies(zmq.version, "< 4.2")) { + set.delete("inproc") + } - if (!set.size) console.error("Warning: test protocol set is empty") + if (!set.size) { + console.error("Warning: test protocol set is empty") + } return [...set] } @@ -144,7 +150,9 @@ export async function captureEventsUntil( for await (const event of socket.events) { events.push(event) - if (event.type === type) break + if (event.type === type) { + break + } } return events diff --git a/test/unit/proxy-construction-test.ts b/test/unit/proxy-construction-test.ts index 048abb89..0275d101 100644 --- a/test/unit/proxy-construction-test.ts +++ b/test/unit/proxy-construction-test.ts @@ -3,18 +3,20 @@ import * as zmq from "../../src" import {assert} from "chai" -describe("proxy construction", function() { - beforeEach(function() { +describe("proxy construction", function () { + beforeEach(function () { /* ZMQ < 4.0.5 has no steerable proxy support. */ - if (semver.satisfies(zmq.version, "< 4.0.5")) this.skip() + if (semver.satisfies(zmq.version, "< 4.0.5")) { + this.skip() + } }) - afterEach(function() { + afterEach(function () { global.gc?.() }) - describe("with constructor", function() { - it("should throw if called as function", function() { + describe("with constructor", function () { + it("should throw if called as function", function () { assert.throws( () => (zmq.Proxy as any)(), TypeError, @@ -22,7 +24,7 @@ describe("proxy construction", function() { ) }) - it("should throw with too few arguments", function() { + it("should throw with too few arguments", function () { assert.throws( () => new (zmq.Proxy as any)(), TypeError, @@ -30,7 +32,7 @@ describe("proxy construction", function() { ) }) - it("should throw with too many arguments", function() { + it("should throw with too many arguments", function () { assert.throws( () => new (zmq.Proxy as any)( @@ -43,7 +45,7 @@ describe("proxy construction", function() { ) }) - it("should throw with invalid socket", function() { + it("should throw with invalid socket", function () { try { new (zmq.Proxy as any)({}, {}) assert.ok(false) diff --git a/test/unit/proxy-router-dealer-test.ts b/test/unit/proxy-router-dealer-test.ts index 5b347c6f..2bd5ecc2 100644 --- a/test/unit/proxy-router-dealer-test.ts +++ b/test/unit/proxy-router-dealer-test.ts @@ -5,7 +5,7 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`proxy with ${proto} router/dealer`, function() { + describe(`proxy with ${proto} router/dealer`, function () { let proxy: zmq.Proxy let frontAddress: string @@ -14,9 +14,11 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { let req: zmq.Request let rep: zmq.Reply - beforeEach(async function() { + beforeEach(async function () { /* ZMQ < 4.0.5 has no steerable proxy support. */ - if (semver.satisfies(zmq.version, "< 4.0.5")) this.skip() + if (semver.satisfies(zmq.version, "< 4.0.5")) { + this.skip() + } proxy = new zmq.Proxy(new zmq.Router(), new zmq.Dealer()) @@ -27,7 +29,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { rep = new zmq.Reply() }) - afterEach(function() { + afterEach(function () { /* Closing proxy sockets is only necessary if run() fails. */ proxy.frontEnd.close() proxy.backEnd.close() @@ -37,8 +39,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { global.gc?.() }) - describe("run", function() { - it("should proxy messages", async function() { + describe("run", function () { + it("should proxy messages", async function () { /* REQ -> foo -> ROUTER <-> DEALER -> foo -> REP <- foo <- <- foo <- -> bar -> -> bar -> @@ -79,7 +81,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { const [res] = await req.receive() received.push(res.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } rep.close() diff --git a/test/unit/proxy-run-test.ts b/test/unit/proxy-run-test.ts index d86d204e..08e875ff 100644 --- a/test/unit/proxy-run-test.ts +++ b/test/unit/proxy-run-test.ts @@ -5,23 +5,25 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`proxy with ${proto} run`, function() { + describe(`proxy with ${proto} run`, function () { let proxy: zmq.Proxy - beforeEach(async function() { + beforeEach(async function () { /* ZMQ < 4.0.5 has no steerable proxy support. */ - if (semver.satisfies(zmq.version, "< 4.0.5")) this.skip() + if (semver.satisfies(zmq.version, "< 4.0.5")) { + this.skip() + } proxy = new zmq.Proxy(new zmq.Router(), new zmq.Dealer()) }) - afterEach(function() { + afterEach(function () { proxy.frontEnd.close() proxy.backEnd.close() global.gc?.() }) - it("should fail if front end is not bound or connected", async function() { + it("should fail if front end is not bound or connected", async function () { await proxy.backEnd.bind(uniqAddress(proto)) try { @@ -33,7 +35,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should fail if front end is not open", async function() { + it("should fail if front end is not open", async function () { await proxy.frontEnd.bind(uniqAddress(proto)) await proxy.backEnd.bind(uniqAddress(proto)) proxy.frontEnd.close() @@ -47,7 +49,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should fail if back end is not bound or connected", async function() { + it("should fail if back end is not bound or connected", async function () { await proxy.frontEnd.bind(uniqAddress(proto)) try { @@ -61,7 +63,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should fail if back end is not open", async function() { + it("should fail if back end is not open", async function () { await proxy.frontEnd.bind(uniqAddress(proto)) await proxy.backEnd.bind(uniqAddress(proto)) proxy.backEnd.close() diff --git a/test/unit/proxy-terminate-test.ts b/test/unit/proxy-terminate-test.ts index d62e4953..29d45485 100644 --- a/test/unit/proxy-terminate-test.ts +++ b/test/unit/proxy-terminate-test.ts @@ -5,23 +5,25 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`proxy with ${proto} terminate`, function() { + describe(`proxy with ${proto} terminate`, function () { let proxy: zmq.Proxy - beforeEach(async function() { + beforeEach(async function () { /* ZMQ < 4.0.5 has no steerable proxy support. */ - if (semver.satisfies(zmq.version, "< 4.0.5")) this.skip() + if (semver.satisfies(zmq.version, "< 4.0.5")) { + this.skip() + } proxy = new zmq.Proxy(new zmq.Router(), new zmq.Dealer()) }) - afterEach(function() { + afterEach(function () { proxy.frontEnd.close() proxy.backEnd.close() global.gc?.() }) - it("should throw if called after termination", async function() { + it("should throw if called after termination", async function () { await proxy.frontEnd.bind(uniqAddress(proto)) await proxy.backEnd.bind(uniqAddress(proto)) diff --git a/test/unit/socket-bind-unbind-test.ts b/test/unit/socket-bind-unbind-test.ts index 47e849fb..ef8cc765 100644 --- a/test/unit/socket-bind-unbind-test.ts +++ b/test/unit/socket-bind-unbind-test.ts @@ -4,25 +4,25 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} bind/unbind`, function() { + describe(`socket with ${proto} bind/unbind`, function () { let sock: zmq.Dealer - beforeEach(function() { + beforeEach(function () { sock = new zmq.Dealer() }) - afterEach(function() { + afterEach(function () { sock.close() global.gc?.() }) - describe("bind", function() { - it("should resolve", async function() { + describe("bind", function () { + it("should resolve", async function () { await sock.bind(uniqAddress(proto)) assert.ok(true) }) - it("should throw error if not bound to endpoint", async function() { + it("should throw error if not bound to endpoint", async function () { const address = uniqAddress(proto) try { await sock.unbind(address) @@ -36,7 +36,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should throw error for invalid uri", async function() { + it("should throw error for invalid uri", async function () { try { await sock.bind("foo-bar") assert.ok(false) @@ -49,7 +49,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should throw error for invalid protocol", async function() { + it("should throw error for invalid protocol", async function () { try { await sock.bind("foo://bar") assert.ok(false) @@ -62,7 +62,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should fail during other bind", async function() { + it("should fail during other bind", async function () { let promise try { promise = sock.bind(uniqAddress(proto)) @@ -81,15 +81,15 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("unbind", function() { - it("should unbind", async function() { + describe("unbind", function () { + it("should unbind", async function () { const address = uniqAddress(proto) await sock.bind(address) await sock.unbind(address) assert.ok(true) }) - it("should throw error for invalid uri", async function() { + it("should throw error for invalid uri", async function () { try { await sock.unbind("foo-bar") assert.ok(false) @@ -102,7 +102,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should throw error for invalid protocol", async function() { + it("should throw error for invalid protocol", async function () { try { await sock.unbind("foo://bar") assert.ok(false) @@ -115,7 +115,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should fail during other unbind", async function() { + it("should fail during other unbind", async function () { let promise const address = uniqAddress(proto) await sock.bind(address) diff --git a/test/unit/socket-close-test.ts b/test/unit/socket-close-test.ts index 39bda25c..29695035 100644 --- a/test/unit/socket-close-test.ts +++ b/test/unit/socket-close-test.ts @@ -5,26 +5,26 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} close`, function() { + describe(`socket with ${proto} close`, function () { let sock: zmq.Dealer - beforeEach(function() { + beforeEach(function () { sock = new zmq.Dealer() }) - afterEach(function() { + afterEach(function () { sock.close() global.gc?.() }) - describe("with explicit call", function() { - it("should close socket", function() { + describe("with explicit call", function () { + it("should close socket", function () { assert.equal(sock.closed, false) sock.close() assert.equal(sock.closed, true) }) - it("should close socket and cancel send", async function() { + it("should close socket and cancel send", async function () { assert.equal(sock.closed, false) const promise = sock.send(Buffer.from("foo")) sock.close() @@ -39,7 +39,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should close socket and cancel receive", async function() { + it("should close socket and cancel receive", async function () { assert.equal(sock.closed, false) const promise = sock.receive() sock.close() @@ -54,7 +54,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should close after successful bind", async function() { + it("should close after successful bind", async function () { const promise = sock.bind(uniqAddress(proto)) sock.close() assert.equal(sock.closed, false) @@ -62,7 +62,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.equal(sock.closed, true) }) - it("should close after unsuccessful bind", async function() { + it("should close after unsuccessful bind", async function () { const address = uniqAddress(proto) await sock.bind(address) const promise = sock.bind(address) @@ -77,7 +77,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.equal(sock.closed, true) }) - it("should close after successful unbind", async function() { + it("should close after successful unbind", async function () { const address = uniqAddress(proto) await sock.bind(address) const promise = sock.unbind(address) @@ -87,7 +87,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.equal(sock.closed, true) }) - it("should close after unsuccessful unbind", async function() { + it("should close after unsuccessful unbind", async function () { const address = uniqAddress(proto) const promise = sock.unbind(address) sock.close() @@ -101,8 +101,10 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.equal(sock.closed, true) }) - it("should release reference to context", async function() { - if (process.env.SKIP_GC_TESTS) this.skip() + it("should release reference to context", async function () { + if (process.env.SKIP_GC_TESTS) { + this.skip() + } this.slow(200) const weak = require("weak-napi") as typeof import("weak-napi") @@ -130,10 +132,14 @@ 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) this.skip() - if (process.env.SKIP_GC_FINALIZER_TESTS) this.skip() + describe("in gc finalizer", function () { + it("should release reference to context", async function () { + if (process.env.SKIP_GC_TESTS) { + this.skip() + } + if (process.env.SKIP_GC_FINALIZER_TESTS) { + this.skip() + } this.slow(200) const weak = require("weak-napi") as typeof import("weak-napi") diff --git a/test/unit/socket-connect-disconnect-test.ts b/test/unit/socket-connect-disconnect-test.ts index 15415524..60ad1d1c 100644 --- a/test/unit/socket-connect-disconnect-test.ts +++ b/test/unit/socket-connect-disconnect-test.ts @@ -5,20 +5,20 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} connect/disconnect`, function() { + describe(`socket with ${proto} connect/disconnect`, function () { let sock: zmq.Dealer | zmq.Router - beforeEach(function() { + beforeEach(function () { sock = new zmq.Dealer() }) - afterEach(function() { + afterEach(function () { sock.close() global.gc?.() }) - describe("connect", function() { - it("should throw error for invalid uri", async function() { + describe("connect", function () { + it("should throw error for invalid uri", async function () { try { await sock.connect("foo-bar") assert.ok(false) @@ -31,7 +31,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should throw error for invalid protocol", async function() { + it("should throw error for invalid protocol", async function () { try { await sock.connect("foo://bar") assert.ok(false) @@ -45,7 +45,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) if (semver.satisfies(zmq.version, ">= 4.1")) { - it("should allow setting routing id on router", async function() { + it("should allow setting routing id on router", async function () { sock = new zmq.Router({mandatory: true, linger: 0}) await sock.connect(uniqAddress(proto), {routingId: "remoteId"}) await sock.send(["remoteId", "hi"]) @@ -53,8 +53,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - describe("disconnect", function() { - it("should throw error if not connected to endpoint", async function() { + describe("disconnect", function () { + it("should throw error if not connected to endpoint", async function () { const address = uniqAddress(proto) try { await sock.disconnect(address) @@ -68,7 +68,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should throw error for invalid uri", async function() { + it("should throw error for invalid uri", async function () { try { await sock.disconnect("foo-bar") assert.ok(false) @@ -81,7 +81,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should throw error for invalid protocol", async function() { + it("should throw error for invalid protocol", async function () { try { await sock.disconnect("foo://bar") assert.ok(false) diff --git a/test/unit/socket-construction-test.ts b/test/unit/socket-construction-test.ts index d3c82cde..b6b75b26 100644 --- a/test/unit/socket-construction-test.ts +++ b/test/unit/socket-construction-test.ts @@ -2,13 +2,13 @@ import * as zmq from "../../src" import {assert} from "chai" -describe("socket construction", function() { - afterEach(function() { +describe("socket construction", function () { + afterEach(function () { global.gc?.() }) - describe("with constructor", function() { - it("should throw if called as function", function() { + describe("with constructor", function () { + it("should throw if called as function", function () { assert.throws( () => (zmq.Socket as any)(1, new zmq.Context()), TypeError, @@ -16,7 +16,7 @@ describe("socket construction", function() { ) }) - it("should throw with too few arguments", function() { + it("should throw with too few arguments", function () { assert.throws( () => new (zmq.Socket as any)(), TypeError, @@ -24,7 +24,7 @@ describe("socket construction", function() { ) }) - it("should throw with too many arguments", function() { + it("should throw with too many arguments", function () { assert.throws( () => new (zmq.Socket as any)(1, new zmq.Context(), 2), TypeError, @@ -32,7 +32,7 @@ describe("socket construction", function() { ) }) - it("should throw with wrong options argument", function() { + it("should throw with wrong options argument", function () { assert.throws( () => new (zmq.Socket as any)(3, 1), TypeError, @@ -40,7 +40,7 @@ describe("socket construction", function() { ) }) - it("should throw with wrong type argument", function() { + it("should throw with wrong type argument", function () { assert.throws( () => new (zmq.Socket as any)("foo", new zmq.Context()), TypeError, @@ -48,7 +48,7 @@ describe("socket construction", function() { ) }) - it("should throw with wrong type id", function() { + it("should throw with wrong type id", function () { try { new (zmq.Socket as any)(37, new zmq.Context()) assert.ok(false) @@ -60,7 +60,7 @@ describe("socket construction", function() { } }) - it("should throw with invalid context", function() { + it("should throw with invalid context", function () { try { new (zmq.Socket as any)(1, {context: {}}) assert.ok(false) @@ -73,7 +73,7 @@ describe("socket construction", function() { } }) - it("should create socket with default context", function() { + it("should create socket with default context", function () { class MySocket extends zmq.Socket { constructor() { super(1) @@ -85,7 +85,7 @@ describe("socket construction", function() { assert.equal(sock1.context, sock2.context) }) - it("should create socket with given context", function() { + it("should create socket with given context", function () { class MySocket extends zmq.Socket { constructor(opts: zmq.SocketOptions) { super(1, opts) @@ -98,8 +98,8 @@ describe("socket construction", function() { }) }) - describe("with child constructor", function() { - it("should throw if called as function", function() { + describe("with child constructor", function () { + it("should throw if called as function", function () { assert.throws( () => (zmq.Dealer as any)(), TypeError, @@ -107,25 +107,25 @@ describe("socket construction", function() { ) }) - it("should create socket with default context", function() { + it("should create socket with default context", function () { const sock = new zmq.Dealer() assert.instanceOf(sock, zmq.Dealer) assert.equal(sock.context, zmq.context) }) - it("should create socket with given context", function() { + it("should create socket with given context", function () { const ctxt = new zmq.Context() const sock = new zmq.Dealer({context: ctxt}) assert.instanceOf(sock, zmq.Socket) assert.equal(sock.context, ctxt) }) - it("should set option", function() { + it("should set option", function () { const sock = new zmq.Dealer({recoveryInterval: 5}) assert.equal(sock.recoveryInterval, 5) }) - it("should throw with invalid option value", function() { + it("should throw with invalid option value", function () { assert.throws( () => new (zmq.Dealer as any)({recoveryInterval: "hello"}), TypeError, @@ -133,7 +133,7 @@ describe("socket construction", function() { ) }) - it("should throw with readonly option", function() { + it("should throw with readonly option", function () { assert.throws( () => new (zmq.Dealer as any)({securityMechanism: 1}), TypeError, @@ -141,7 +141,7 @@ describe("socket construction", function() { ) }) - it("should throw with unknown option", function() { + it("should throw with unknown option", function () { assert.throws( () => new (zmq.Dealer as any)({doesNotExist: 1}), TypeError, @@ -149,7 +149,7 @@ describe("socket construction", function() { ) }) - it("should throw with invalid type", function() { + it("should throw with invalid type", function () { assert.throws( () => new (zmq.Socket as any)(4591), Error, @@ -158,7 +158,7 @@ describe("socket construction", function() { }) if (!zmq.capability.draft) { - it("should throw with draft type", function() { + it("should throw with draft type", function () { assert.throws( () => new (zmq.Socket as any)(14), Error, @@ -167,7 +167,7 @@ describe("socket construction", function() { }) } - it("should throw error on file descriptor limit", async function() { + it("should throw error on file descriptor limit", async function () { const context = new zmq.Context({maxSockets: 10}) const sockets = [] const n = 10 diff --git a/test/unit/socket-curve-send-receive-test.ts b/test/unit/socket-curve-send-receive-test.ts index d8fb1416..c2681679 100644 --- a/test/unit/socket-curve-send-receive-test.ts +++ b/test/unit/socket-curve-send-receive-test.ts @@ -4,12 +4,14 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} curve send/receive`, function() { + describe(`socket with ${proto} curve send/receive`, function () { let sockA: zmq.Pair let sockB: zmq.Pair - beforeEach(function() { - if (!zmq.capability.curve) this.skip() + beforeEach(function () { + if (!zmq.capability.curve) { + this.skip() + } const serverKeypair = zmq.curveKeyPair() const clientKeypair = zmq.curveKeyPair() @@ -29,22 +31,24 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - afterEach(function() { + afterEach(function () { sockA.close() sockB.close() global.gc?.() }) - describe("when connected", function() { - beforeEach(async function() { - if (!zmq.capability.curve) this.skip() + describe("when connected", function () { + beforeEach(async function () { + if (!zmq.capability.curve) { + this.skip() + } const address = uniqAddress(proto) await sockB.bind(address) await sockA.connect(address) }) - it("should deliver single string message", async function() { + it("should deliver single string message", async function () { const sent = "foo" await sockA.send(sent) diff --git a/test/unit/socket-draft-dgram-test.ts b/test/unit/socket-draft-dgram-test.ts index 55523e12..02b10312 100644 --- a/test/unit/socket-draft-dgram-test.ts +++ b/test/unit/socket-draft-dgram-test.ts @@ -7,20 +7,20 @@ import {testProtos, uniqAddress} from "./helpers" if (zmq.capability.draft) { for (const proto of testProtos("udp")) { - describe(`draft socket with ${proto} dgram`, function() { + describe(`draft socket with ${proto} dgram`, function () { let dgram: draft.Datagram - beforeEach(function() { + beforeEach(function () { dgram = new draft.Datagram() }) - afterEach(function() { + afterEach(function () { dgram.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { const messages = ["foo", "bar", "baz", "qux"] const address = uniqAddress(proto) const port = parseInt(address.split(":").pop()!, 10) diff --git a/test/unit/socket-draft-radio-dish-test.ts b/test/unit/socket-draft-radio-dish-test.ts index 120aa253..b33f9d15 100644 --- a/test/unit/socket-draft-radio-dish-test.ts +++ b/test/unit/socket-draft-radio-dish-test.ts @@ -6,24 +6,24 @@ import {testProtos, uniqAddress} from "./helpers" if (zmq.capability.draft) { for (const proto of testProtos("tcp", "ipc", "inproc", "udp")) { - describe(`draft socket with ${proto} radio/dish`, function() { + describe(`draft socket with ${proto} radio/dish`, function () { let radio: draft.Radio let dish: draft.Dish - beforeEach(function() { + beforeEach(function () { radio = new draft.Radio() dish = new draft.Dish() }) - afterEach(function() { + afterEach(function () { global.gc?.() radio.close() dish.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { /* RADIO -> foo -> DISH -> bar -> joined all -> baz -> @@ -35,21 +35,8 @@ if (zmq.capability.draft) { /* Max 15 non-null bytes. */ const uuid = Buffer.from([ - 0xf6, - 0x46, - 0x1f, - 0x03, - 0xd2, - 0x0d, - 0xc8, - 0x66, - 0xe5, - 0x5f, - 0xf5, - 0xa1, - 0x65, - 0x62, - 0xb2, + 0xf6, 0x46, 0x1f, 0x03, 0xd2, 0x0d, 0xc8, 0x66, 0xe5, 0x5f, 0xf5, + 0xa1, 0x65, 0x62, 0xb2, ]) const received: string[] = [] @@ -73,7 +60,9 @@ if (zmq.capability.draft) { assert.instanceOf(group, Buffer) assert.deepEqual(group, uuid) received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } } @@ -82,8 +71,8 @@ if (zmq.capability.draft) { }) }) - describe("join/leave", function() { - it("should filter messages", async function() { + describe("join/leave", function () { + it("should filter messages", async function () { /* RADIO -> foo -X DISH -> bar -> joined "ba" -> baz -> @@ -114,7 +103,9 @@ if (zmq.capability.draft) { assert.instanceOf(msg, Buffer) assert.deepEqual(group, msg.slice(0, 2)) received.push(msg.toString()) - if (received.length === 2) break + if (received.length === 2) { + break + } } } diff --git a/test/unit/socket-draft-scatter-gather-test.ts b/test/unit/socket-draft-scatter-gather-test.ts index 842a9ed7..dcfaa369 100644 --- a/test/unit/socket-draft-scatter-gather-test.ts +++ b/test/unit/socket-draft-scatter-gather-test.ts @@ -6,23 +6,23 @@ import {testProtos, uniqAddress} from "./helpers" if (zmq.capability.draft) { for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} scatter/gather`, function() { + describe(`socket with ${proto} scatter/gather`, function () { let scatter: draft.Scatter let gather: draft.Gather - beforeEach(function() { + beforeEach(function () { scatter = new draft.Scatter() gather = new draft.Gather() }) - afterEach(function() { + afterEach(function () { scatter.close() gather.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { /* SCATTER -> foo -> GATHER -> bar -> -> baz -> @@ -43,14 +43,16 @@ if (zmq.capability.draft) { for await (const [msg] of gather) { assert.instanceOf(msg, Buffer) received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } assert.deepEqual(received, messages) }) if (proto !== "inproc") { - it("should deliver messages with immediate", async function() { + it("should deliver messages with immediate", async function () { const address = uniqAddress(proto) const messages = ["foo", "bar", "baz", "qux"] const received: string[] = [] @@ -70,7 +72,9 @@ if (zmq.capability.draft) { for await (const [msg] of gather) { assert.instanceOf(msg, Buffer) received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } assert.deepEqual(received, messages) diff --git a/test/unit/socket-draft-server-client-test.ts b/test/unit/socket-draft-server-client-test.ts index bb00348c..52809575 100644 --- a/test/unit/socket-draft-server-client-test.ts +++ b/test/unit/socket-draft-server-client-test.ts @@ -6,26 +6,26 @@ import {testProtos, uniqAddress} from "./helpers" if (zmq.capability.draft) { for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`draft socket with ${proto} server/client`, function() { + describe(`draft socket with ${proto} server/client`, function () { let server: draft.Server let clientA: draft.Client let clientB: draft.Client - beforeEach(function() { + beforeEach(function () { server = new draft.Server() clientA = new draft.Client() clientB = new draft.Client() }) - afterEach(function() { + afterEach(function () { server.close() clientA.close() clientB.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { const address = uniqAddress(proto) const messages = ["foo", "bar", "baz", "qux"] const receivedA: string[] = [] @@ -50,12 +50,16 @@ if (zmq.capability.draft) { for await (const msg of clientA) { receivedA.push(msg.toString()) - if (receivedA.length === messages.length) break + if (receivedA.length === messages.length) { + break + } } for await (const msg of clientB) { receivedB.push(msg.toString()) - if (receivedB.length === messages.length) break + if (receivedB.length === messages.length) { + break + } } server.close() @@ -66,7 +70,7 @@ if (zmq.capability.draft) { assert.deepEqual(receivedB, messages) }) - it("should fail with unroutable message", async function() { + it("should fail with unroutable message", async function () { try { await server.send("foo", {routingId: 12345}) assert.ok(false) diff --git a/test/unit/socket-events-test.ts b/test/unit/socket-events-test.ts index 8d904950..422a4c63 100644 --- a/test/unit/socket-events-test.ts +++ b/test/unit/socket-events-test.ts @@ -9,23 +9,23 @@ import { } from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} events`, function() { + describe(`socket with ${proto} events`, function () { let sockA: zmq.Dealer let sockB: zmq.Dealer - beforeEach(function() { + beforeEach(function () { sockA = new zmq.Dealer() sockB = new zmq.Dealer() }) - afterEach(function() { + afterEach(function () { sockA.close() sockB.close() global.gc?.() }) - describe("when not connected", function() { - it("should receive events", async function() { + describe("when not connected", function () { + it("should receive events", async function () { const done = captureEventsUntil(sockA, "end") sockA.close() @@ -34,13 +34,13 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("when connected", function() { - it("should return same object", function() { + describe("when connected", function () { + it("should return same object", function () { assert.equal(sockA.events, sockA.events) }) if (proto !== "inproc") { - it("should receive bind events", async function() { + it("should receive bind events", async function () { const address = uniqAddress(proto) const [event] = await Promise.all([ @@ -52,7 +52,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.deepEqual(event, {type: "bind", address}) }) - it("should receive connect events", async function() { + it("should receive connect events", async function () { this.slow(250) const address = uniqAddress(proto) @@ -67,7 +67,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } if (proto === "tcp") { - it("should receive error events", async function() { + it("should receive error events", async function () { const address = uniqAddress(proto) await sockA.bind(address) @@ -78,7 +78,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }), ]) - assert.equal("tcp://" + event.address, address) + assert.equal(`tcp://${event.address}`, address) assert.instanceOf(event.error, Error) assert.equal(event.error.message, "Address already in use") assert.equal(event.error.code, "EADDRINUSE") @@ -86,7 +86,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) } - it("should receive events with emitter", async function() { + it("should receive events with emitter", async function () { const address = uniqAddress(proto) const events: zmq.Event[] = [] @@ -120,7 +120,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { sockB.connect(address), ]) - if (proto !== "inproc") await connected + if (proto !== "inproc") { + await connected + } sockA.close() sockB.close() @@ -136,8 +138,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("when closed automatically", function() { - it("should not be able to receive", async function() { + describe("when closed automatically", function () { + it("should not be able to receive", async function () { const events = sockA.events sockA.close() @@ -155,7 +157,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should be closed", async function() { + it("should be closed", async function () { const events = sockA.events sockA.close() await events.receive() diff --git a/test/unit/socket-options-test.ts b/test/unit/socket-options-test.ts index e86516fc..8b164adc 100644 --- a/test/unit/socket-options-test.ts +++ b/test/unit/socket-options-test.ts @@ -4,14 +4,14 @@ import * as zmq from "../../src" import {assert} from "chai" import {uniqAddress} from "./helpers" -describe("socket options", function() { +describe("socket options", function () { let warningListeners: NodeJS.WarningListener[] - beforeEach(function() { + beforeEach(function () { warningListeners = process.listeners("warning") }) - afterEach(function() { + afterEach(function () { process.removeAllListeners("warning") for (const listener of warningListeners) { process.on("warning", listener as (warning: Error) => void) @@ -20,42 +20,42 @@ describe("socket options", function() { global.gc?.() }) - it("should set and get bool socket option", function() { + it("should set and get bool socket option", function () { const sock = new zmq.Dealer() assert.equal(sock.immediate, false) sock.immediate = true assert.equal(sock.immediate, true) }) - it("should set and get int32 socket option", function() { + it("should set and get int32 socket option", function () { const sock = new zmq.Dealer() assert.equal(sock.backlog, 100) sock.backlog = 75 assert.equal(sock.backlog, 75) }) - it("should set and get int64 socket option", function() { + it("should set and get int64 socket option", function () { const sock = new zmq.Dealer() assert.equal(sock.maxMessageSize, -1) sock.maxMessageSize = 0xffffffff assert.equal(sock.maxMessageSize, 0xffffffff) }) - it("should set and get string socket option", function() { + it("should set and get string socket option", function () { const sock = new zmq.Dealer() assert.equal(sock.routingId, null) sock.routingId = "åbçdéfghïjk" assert.equal(sock.routingId, "åbçdéfghïjk") }) - it("should set and get string socket option as buffer", function() { + it("should set and get string socket option as buffer", function () { const sock = new zmq.Dealer() assert.equal(sock.routingId, null) ;(sock as any).routingId = Buffer.from("åbçdéfghïjk") assert.equal(sock.routingId, "åbçdéfghïjk") }) - it("should set and get string socket option to undefined", function() { + it("should set and get string socket option to undefined", function () { if (semver.satisfies(zmq.version, "> 4.2.3")) { /* As of ZMQ 4.2.4, zap domain can no longer be reset to null. */ const sock = new zmq.Dealer() @@ -75,28 +75,28 @@ describe("socket options", function() { } }) - it("should set and get bool socket option", function() { + it("should set and get bool socket option", function () { const sock = new zmq.Dealer() assert.equal((sock as any).getBoolOption(39), false) ;(sock as any).setBoolOption(39, true) assert.equal((sock as any).getBoolOption(39), true) }) - it("should set and get int32 socket option", function() { + it("should set and get int32 socket option", function () { const sock = new zmq.Dealer() assert.equal((sock as any).getInt32Option(19), 100) ;(sock as any).setInt32Option(19, 75) assert.equal((sock as any).getInt32Option(19), 75) }) - it("should set and get int64 socket option", function() { + it("should set and get int64 socket option", function () { const sock = new zmq.Dealer() assert.equal((sock as any).getInt64Option(22), -1) ;(sock as any).setInt64Option(22, 0xffffffffffff) assert.equal((sock as any).getInt64Option(22), 0xffffffffffff) }) - it("should set and get uint64 socket option", function() { + it("should set and get uint64 socket option", function () { process.removeAllListeners("warning") const sock = new zmq.Dealer() @@ -105,21 +105,21 @@ describe("socket options", function() { assert.equal((sock as any).getUint64Option(4), 0xffffffffffffffff) }) - it("should set and get string socket option", function() { + it("should set and get string socket option", function () { const sock = new zmq.Dealer() assert.equal((sock as any).getStringOption(5), null) ;(sock as any).setStringOption(5, "åbçdéfghïjk") assert.equal((sock as any).getStringOption(5), "åbçdéfghïjk") }) - it("should set and get string socket option as buffer", function() { + it("should set and get string socket option as buffer", function () { const sock = new zmq.Dealer() assert.equal((sock as any).getStringOption(5), null) ;(sock as any).setStringOption(5, Buffer.from("åbçdéfghïjk")) assert.equal((sock as any).getStringOption(5), "åbçdéfghïjk") }) - it("should set and get string socket option to null", function() { + it("should set and get string socket option to null", function () { if (semver.satisfies(zmq.version, "> 4.2.3")) { /* As of ZMQ 4.2.4, zap domain can no longer be reset to null. */ const sock = new zmq.Dealer() @@ -145,7 +145,7 @@ describe("socket options", function() { } }) - it("should throw for readonly option", function() { + it("should throw for readonly option", function () { const sock = new zmq.Dealer() assert.throws( () => ((sock as any).securityMechanism = 1), @@ -154,7 +154,7 @@ describe("socket options", function() { ) }) - it("should throw for unknown option", function() { + it("should throw for unknown option", function () { const sock = new zmq.Dealer() assert.throws( () => ((sock as any).doesNotExist = 1), @@ -163,30 +163,32 @@ describe("socket options", function() { ) }) - it("should get mechanism", function() { + it("should get mechanism", function () { const sock = new zmq.Dealer() assert.equal(sock.securityMechanism, null) sock.plainServer = true assert.equal(sock.securityMechanism, "plain") }) - describe("warnings", function() { - beforeEach(function() { + describe("warnings", function () { + beforeEach(function () { /* ZMQ < 4.2 fails with assertion errors with inproc. See: https://github.com/zeromq/libzmq/pull/2123/files */ - if (semver.satisfies(zmq.version, "< 4.2")) this.skip() + if (semver.satisfies(zmq.version, "< 4.2")) { + this.skip() + } warningListeners = process.listeners("warning") }) - afterEach(function() { + afterEach(function () { process.removeAllListeners("warning") for (const listener of warningListeners) { process.on("warning", listener as (warning: Error) => void) } }) - it("should be emitted for set after connect", async function() { + it("should be emitted for set after connect", async function () { const warnings: Error[] = [] process.removeAllListeners("warning") process.on("warning", warning => warnings.push(warning)) @@ -204,7 +206,7 @@ describe("socket options", function() { sock.close() }) - it("should be emitted for set during bind", async function() { + it("should be emitted for set during bind", async function () { const warnings: Error[] = [] process.removeAllListeners("warning") process.on("warning", warning => warnings.push(warning)) @@ -223,7 +225,7 @@ describe("socket options", function() { sock.close() }) - it("should be emitted for set after bind", async function() { + it("should be emitted for set after bind", async function () { const warnings: Error[] = [] process.removeAllListeners("warning") process.on("warning", warning => warnings.push(warning)) @@ -241,7 +243,7 @@ describe("socket options", function() { sock.close() }) - it("should be emitted when setting large uint64 socket option", async function() { + it("should be emitted when setting large uint64 socket option", async function () { const warnings: Error[] = [] process.removeAllListeners("warning") process.on("warning", warning => warnings.push(warning)) diff --git a/test/unit/socket-pair-test.ts b/test/unit/socket-pair-test.ts index 649d8fc1..df66fdcd 100644 --- a/test/unit/socket-pair-test.ts +++ b/test/unit/socket-pair-test.ts @@ -4,23 +4,23 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} pair/pair`, function() { + describe(`socket with ${proto} pair/pair`, function () { let sockA: zmq.Pair let sockB: zmq.Pair - beforeEach(function() { + beforeEach(function () { sockA = new zmq.Pair() sockB = new zmq.Pair() }) - afterEach(function() { + afterEach(function () { sockA.close() sockB.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { /* PAIR -> foo -> PAIR [A] -> bar -> [B] -> baz -> responds when received @@ -51,7 +51,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const msg of sockA) { received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } sockB.close() diff --git a/test/unit/socket-process-exit-test.ts b/test/unit/socket-process-exit-test.ts index cd758014..2d3392fb 100644 --- a/test/unit/socket-process-exit-test.ts +++ b/test/unit/socket-process-exit-test.ts @@ -3,9 +3,9 @@ import * as zmq from "../../src" import {assert} from "chai" import {createProcess} from "./helpers" -describe("socket process exit", function() { +describe("socket process exit", function () { /* Reported: https://github.com/nodejs/node-addon-api/issues/591 */ - it.skip("should occur cleanly when sending in exit hook", async function() { + it.skip("should occur cleanly when sending in exit hook", async function () { this.slow(200) const {code} = await createProcess(async () => { const sockA = new zmq.Pair() @@ -23,7 +23,7 @@ describe("socket process exit", function() { assert.equal(code, 0) }) - it("should occur cleanly when sending on unbound socket", async function() { + it("should occur cleanly when sending on unbound socket", async function () { this.slow(200) const {code} = await createProcess(async () => { const sock = new zmq.Publisher() @@ -33,7 +33,7 @@ describe("socket process exit", function() { assert.equal(code, 0) }) - it("should not occur when sending and blocked on unbound socket", async function() { + it("should not occur when sending and blocked on unbound socket", async function () { this.slow(1000) const {code} = await createProcess(async () => { const sock = new zmq.Dealer() @@ -43,7 +43,7 @@ describe("socket process exit", function() { assert.equal(code, -1) }) - it("should occur cleanly on socket close when reading events", async function() { + it("should occur cleanly on socket close when reading events", async function () { this.slow(200) const {code} = await createProcess(() => { const sock = new zmq.Dealer() @@ -62,7 +62,7 @@ describe("socket process exit", function() { assert.equal(code, 0) }) - it("should not occur while reading events", async function() { + it("should not occur while reading events", async function () { this.slow(1000) const {code} = await createProcess(async () => { const sock = new zmq.Dealer() diff --git a/test/unit/socket-pub-sub-test.ts b/test/unit/socket-pub-sub-test.ts index 3472f799..f85e1bc3 100644 --- a/test/unit/socket-pub-sub-test.ts +++ b/test/unit/socket-pub-sub-test.ts @@ -4,23 +4,23 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} pub/sub`, function() { + describe(`socket with ${proto} pub/sub`, function () { let pub: zmq.Publisher let sub: zmq.Subscriber - beforeEach(function() { + beforeEach(function () { pub = new zmq.Publisher() sub = new zmq.Subscriber() }) - afterEach(function() { + afterEach(function () { pub.close() sub.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { /* PUB -> foo -> SUB -> bar -> subscribed to all -> baz -> @@ -49,7 +49,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of sub) { assert.instanceOf(msg, Buffer) received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } } @@ -58,8 +60,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("subscribe/unsubscribe", function() { - it("should filter messages", async function() { + describe("subscribe/unsubscribe", function () { + it("should filter messages", async function () { /* PUB -> foo -X SUB -> bar -> subscribed to "ba" -> baz -> @@ -88,7 +90,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of sub) { assert.instanceOf(msg, Buffer) received.push(msg.toString()) - if (received.length === 2) break + if (received.length === 2) { + break + } } } diff --git a/test/unit/socket-push-pull-test.ts b/test/unit/socket-push-pull-test.ts index c04f4edd..c0e5c95a 100644 --- a/test/unit/socket-push-pull-test.ts +++ b/test/unit/socket-push-pull-test.ts @@ -4,23 +4,23 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} push/pull`, function() { + describe(`socket with ${proto} push/pull`, function () { let push: zmq.Push let pull: zmq.Pull - beforeEach(function() { + beforeEach(function () { push = new zmq.Push() pull = new zmq.Pull() }) - afterEach(function() { + afterEach(function () { push.close() pull.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { /* PUSH -> foo -> PULL -> bar -> -> baz -> @@ -41,14 +41,16 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of pull) { assert.instanceOf(msg, Buffer) received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } assert.deepEqual(received, messages) }) if (proto !== "inproc") { - it("should deliver messages with immediate", async function() { + it("should deliver messages with immediate", async function () { const address = uniqAddress(proto) const messages = ["foo", "bar", "baz", "qux"] const received: string[] = [] @@ -68,7 +70,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of pull) { assert.instanceOf(msg, Buffer) received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } assert.deepEqual(received, messages) diff --git a/test/unit/socket-req-rep-test.ts b/test/unit/socket-req-rep-test.ts index fad69103..8e0e96d7 100644 --- a/test/unit/socket-req-rep-test.ts +++ b/test/unit/socket-req-rep-test.ts @@ -4,23 +4,23 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} req/rep`, function() { + describe(`socket with ${proto} req/rep`, function () { let req: zmq.Request let rep: zmq.Reply - beforeEach(function() { + beforeEach(function () { req = new zmq.Request() rep = new zmq.Reply() }) - afterEach(function() { + afterEach(function () { req.close() rep.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { /* REQ -> foo -> REP <- foo <- -> bar -> @@ -50,7 +50,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { const [res] = await req.receive() received.push(res.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } rep.close() @@ -60,7 +62,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.deepEqual(received, messages) }) - it("should throw when waiting for a response", async function() { + it("should throw when waiting for a response", async function () { /* REQ -> foo -> REP -X foo <- foo <- diff --git a/test/unit/socket-router-dealer-test.ts b/test/unit/socket-router-dealer-test.ts index 61072515..bdeecfbd 100644 --- a/test/unit/socket-router-dealer-test.ts +++ b/test/unit/socket-router-dealer-test.ts @@ -5,26 +5,26 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} router/dealer`, function() { + describe(`socket with ${proto} router/dealer`, function () { let router: zmq.Router let dealerA: zmq.Dealer let dealerB: zmq.Dealer - beforeEach(function() { + beforeEach(function () { router = new zmq.Router() dealerA = new zmq.Dealer() dealerB = new zmq.Dealer() }) - afterEach(function() { + afterEach(function () { router.close() dealerA.close() dealerB.close() global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { const address = uniqAddress(proto) const messages = ["foo", "bar", "baz", "qux"] const receivedA: string[] = [] @@ -48,12 +48,16 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const msg of dealerA) { receivedA.push(msg.toString()) - if (receivedA.length === messages.length) break + if (receivedA.length === messages.length) { + break + } } for await (const msg of dealerB) { receivedB.push(msg.toString()) - if (receivedB.length === messages.length) break + if (receivedB.length === messages.length) { + break + } } router.close() @@ -66,7 +70,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { /* This only works reliably with ZMQ 4.2.3+ */ if (semver.satisfies(zmq.version, ">= 4.2.3")) { - it("should fail with unroutable message if mandatory", async function() { + it("should fail with unroutable message if mandatory", async function () { router.mandatory = true router.sendTimeout = 0 try { diff --git a/test/unit/socket-send-receive-test.ts b/test/unit/socket-send-receive-test.ts index a242c96b..7bd9dbf8 100644 --- a/test/unit/socket-send-receive-test.ts +++ b/test/unit/socket-send-receive-test.ts @@ -5,23 +5,23 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} send/receive`, function() { + describe(`socket with ${proto} send/receive`, function () { let sockA: zmq.Pair let sockB: zmq.Pair - beforeEach(function() { + beforeEach(function () { sockA = new zmq.Pair({linger: 0}) sockB = new zmq.Pair({linger: 0}) }) - afterEach(function() { + afterEach(function () { sockA.close() sockB.close() global.gc?.() }) - describe("when not applicable", function() { - it("should fail sending", function() { + describe("when not applicable", function () { + it("should fail sending", function () { try { ;(new zmq.Subscriber() as any).send() } catch (err) { @@ -30,7 +30,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should fail receiving", function() { + it("should fail receiving", function () { try { ;(new zmq.Publisher() as any).receive() } catch (err) { @@ -39,7 +39,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should fail iterating", async function() { + it("should fail iterating", async function () { try { /* eslint-disable-next-line no-empty */ for await (const msg of new zmq.Publisher() as any) { @@ -51,21 +51,21 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("when not connected", function() { - beforeEach(async function() { + describe("when not connected", function () { + beforeEach(async function () { sockA.sendHighWaterMark = 1 await sockA.connect(uniqAddress(proto)) }) - it("should be writable", async function() { + it("should be writable", async function () { assert.equal(sockA.writable, true) }) - it("should not be readable", async function() { + it("should not be readable", async function () { assert.equal(sockA.readable, false) }) - it("should honor send high water mark and timeout", async function() { + it("should honor send high water mark and timeout", async function () { sockA.sendTimeout = 2 await sockA.send(Buffer.alloc(8192)) try { @@ -79,8 +79,10 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should copy and release small buffers", async function() { - if (process.env.SKIP_GC_TESTS) this.skip() + it("should copy and release small buffers", async function () { + if (process.env.SKIP_GC_TESTS) { + this.skip() + } const weak = require("weak-napi") let released = false @@ -99,8 +101,10 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.equal(released, true) }) - it("should retain large buffers", async function() { - if (process.env.SKIP_GC_TESTS) this.skip() + it("should retain large buffers", async function () { + if (process.env.SKIP_GC_TESTS) { + this.skip() + } const weak = require("weak-napi") let released = false @@ -120,28 +124,28 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("when connected", function() { - beforeEach(async function() { + describe("when connected", function () { + beforeEach(async function () { const address = uniqAddress(proto) await sockB.bind(address) await sockA.connect(address) }) - it("should be writable", async function() { + it("should be writable", async function () { assert.equal(sockA.writable, true) }) - it("should not be readable", async function() { + it("should not be readable", async function () { assert.equal(sockA.readable, false) }) - it("should be readable if message is available", async function() { + it("should be readable if message is available", async function () { await sockB.send(Buffer.from("foo")) await new Promise(resolve => setTimeout(resolve, 15)) assert.equal(sockA.readable, true) }) - it("should deliver single string message", async function() { + it("should deliver single string message", async function () { const sent = "foo" await sockA.send(sent) @@ -152,7 +156,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { ) }) - it("should deliver single buffer message", async function() { + it("should deliver single buffer message", async function () { const sent = Buffer.from("foo") await sockA.send(sent) @@ -160,7 +164,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.deepEqual([sent], recv) }) - it("should deliver single multipart string message", async function() { + it("should deliver single multipart string message", async function () { const sent = ["foo", "bar"] await sockA.send(sent) @@ -171,7 +175,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { ) }) - it("should deliver single multipart buffer message", async function() { + it("should deliver single multipart buffer message", async function () { const sent = [Buffer.from("foo"), Buffer.from("bar")] await sockA.send(sent) @@ -179,7 +183,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.deepEqual(sent, recv) }) - it("should deliver multiple messages", async function() { + it("should deliver multiple messages", async function () { const messages = ["foo", "bar", "baz", "qux"] for (const msg of messages) { await sockA.send(msg) @@ -188,13 +192,15 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { const received: string[] = [] for await (const msg of sockB) { received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } assert.deepEqual(received, messages) }) - it("should deliver typed array and array buffer messages", async function() { + it("should deliver typed array and array buffer messages", async function () { const messages = [ Uint8Array.from([0x66, 0x6f, 0x6f]), Uint8Array.from([0x66, 0x6f, 0x6f]).buffer, @@ -209,7 +215,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { const received: string[] = [] for await (const msg of sockB) { received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } assert.deepEqual(received, [ @@ -220,11 +228,11 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { ]) }) - it("should deliver messages coercible to string", async function() { + it("should deliver messages coercible to string", async function () { const messages = [ null, /* eslint-disable-next-line @typescript-eslint/no-empty-function */ - function() {}, + function () {}, 16.19, true, {}, @@ -237,7 +245,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { const received: string[] = [] for await (const msg of sockB) { received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } /* Unify different output across Node/TypeScript versions. */ @@ -253,7 +263,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { ]) }) - it("should poll simultaneously", async function() { + it("should poll simultaneously", async function () { const sendReceiveA = async () => { const [msg1] = await Promise.all([ sockA.receive(), @@ -274,7 +284,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.deepEqual(msgs, ["bar", "foo"]) }) - it("should poll simultaneously after delay", async function() { + it("should poll simultaneously after delay", async function () { await new Promise(resolve => setTimeout(resolve, 15)) const sendReceiveA = async () => { const [msg1] = await Promise.all([ @@ -296,7 +306,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.deepEqual(msgs, ["bar", "foo"]) }) - it("should honor receive timeout", async function() { + it("should honor receive timeout", async function () { sockA.receiveTimeout = 2 try { await sockA.receive() @@ -309,8 +319,10 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should release buffers", async function() { - if (process.env.SKIP_GC_TESTS) this.skip() + it("should release buffers", async function () { + if (process.env.SKIP_GC_TESTS) { + this.skip() + } const weak = require("weak-napi") const n = 10 @@ -346,8 +358,10 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.equal(released, n * 2) }) - it("should release buffers after echo", async function() { - if (process.env.SKIP_GC_TESTS) this.skip() + it("should release buffers after echo", async function () { + if (process.env.SKIP_GC_TESTS) { + this.skip() + } const weak = require("weak-napi") const n = 10 @@ -393,7 +407,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) if (proto === "inproc") { - it("should share memory of large buffers", async function() { + it("should share memory of large buffers", async function () { const orig = Buffer.alloc(2048) await sockA.send(orig) @@ -410,7 +424,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) } - it("should not starve event loop", async function() { + it("should not starve event loop", async function () { this.slow(250) sockA.sendHighWaterMark = 5000 @@ -450,8 +464,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) if (proto !== "inproc") { - describe("when connected after send/receive", function() { - it("should deliver message", async function() { + describe("when connected after send/receive", function () { + it("should deliver message", async function () { const address = uniqAddress(proto) const sent = "foo" @@ -469,21 +483,21 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) } - describe("when closed", function() { - beforeEach(function() { + describe("when closed", function () { + beforeEach(function () { sockA.close() sockB.close() }) - it("should not be writable", async function() { + it("should not be writable", async function () { assert.equal(sockA.writable, false) }) - it("should not be readable", async function() { + it("should not be readable", async function () { assert.equal(sockA.readable, false) }) - it("should not be able to send", async function() { + it("should not be able to send", async function () { try { await sockA.send(Buffer.alloc(8192)) assert.ok(false) @@ -495,7 +509,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should not be able to receive", async function() { + it("should not be able to receive", async function () { try { await sockA.receive() assert.ok(false) @@ -508,15 +522,15 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("during close", function() { - it("should gracefully stop async iterator", async function() { + describe("during close", function () { + it("should gracefully stop async iterator", async function () { process.nextTick(() => sockA.close()) /* eslint-disable-next-line no-empty */ for await (const _ of sockA) { } }) - it("should not mask other error type in async iterator", async function() { + it("should not mask other error type in async iterator", async function () { sockA = new zmq.Request() process.nextTick(() => sockA.close()) try { @@ -536,8 +550,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("concurrently", function() { - it("should throw error on concurrent send", async function() { + describe("concurrently", function () { + it("should throw error on concurrent send", async function () { sockA.sendTimeout = 20 const done = sockA.send(null).catch(() => null) try { @@ -556,7 +570,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { } }) - it("should throw error on concurrent receive", async function() { + it("should throw error on concurrent receive", async function () { sockA.receiveTimeout = 20 const done = sockA.receive().catch(() => null) try { diff --git a/test/unit/socket-stream-test.ts b/test/unit/socket-stream-test.ts index d2301613..158f91ec 100644 --- a/test/unit/socket-stream-test.ts +++ b/test/unit/socket-stream-test.ts @@ -5,27 +5,29 @@ import {createServer, get, Server} from "http" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp")) { - describe(`socket with ${proto} stream`, function() { + describe(`socket with ${proto} stream`, function () { let stream: zmq.Stream - beforeEach(function() { + beforeEach(function () { stream = new zmq.Stream() }) - afterEach(function() { + afterEach(function () { stream.close() global.gc?.() }) - describe("send/receive as server", function() { - it("should deliver messages", async function() { + describe("send/receive as server", function () { + it("should deliver messages", async function () { const address = uniqAddress(proto) await stream.bind(address) const serve = async () => { for await (const [id, msg] of stream) { - if (!msg.length) continue + if (!msg.length) { + continue + } assert.equal(msg.toString().split("\r\n")[0], "GET /foo HTTP/1.1") await stream.send([ @@ -43,7 +45,7 @@ for (const proto of testProtos("tcp")) { let body = "" const request = async () => { return new Promise(resolve => { - get(address.replace("tcp:", "http:") + "/foo", res => { + get(`${address.replace("tcp:", "http:")}/foo`, res => { res.on("data", buffer => { body += buffer.toString() }) @@ -57,8 +59,8 @@ for (const proto of testProtos("tcp")) { }) }) - describe("send/receive as client", function() { - it("should deliver messages", async function() { + describe("send/receive as client", function () { + it("should deliver messages", async function () { const address = uniqAddress(proto) const port = parseInt(address.split(":").pop()!, 10) diff --git a/test/unit/socket-thread-test.ts b/test/unit/socket-thread-test.ts index 8a9a2b25..f0038c91 100644 --- a/test/unit/socket-thread-test.ts +++ b/test/unit/socket-thread-test.ts @@ -5,17 +5,19 @@ import {assert} from "chai" import {createWorker, testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} in thread`, function() { + describe(`socket with ${proto} in thread`, function () { this.slow(2000) this.timeout(5000) - beforeEach(function() { + beforeEach(function () { /* Node.js worker support introduced in version 10.5. */ - if (semver.satisfies(process.versions.node, "< 10.5")) this.skip() + if (semver.satisfies(process.versions.node, "< 10.5")) { + this.skip() + } }) - describe("when connected within thread", function() { - it("should deliver messages", async function() { + describe("when connected within thread", function () { + it("should deliver messages", async function () { const data = {address: uniqAddress(proto)} const recv = await createWorker(data, async ({address}) => { const sockA = new zmq.Pair({linger: 0}) @@ -34,8 +36,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("when connected to thread", function() { - it("should deliver messages", async function() { + describe("when connected to thread", function () { + it("should deliver messages", async function () { const address = uniqAddress(proto) const sockA = new zmq.Pair({linger: 0}) @@ -60,8 +62,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("when connected between threads", function() { - it("should deliver messages", async function() { + describe("when connected between threads", function () { + it("should deliver messages", async function () { const address = uniqAddress(proto) const worker1 = createWorker({address}, async ({address}) => { diff --git a/test/unit/socket-xpub-xsub-test.ts b/test/unit/socket-xpub-xsub-test.ts index bbca03ae..30e54bbd 100644 --- a/test/unit/socket-xpub-xsub-test.ts +++ b/test/unit/socket-xpub-xsub-test.ts @@ -5,20 +5,20 @@ import {assert} from "chai" import {testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc", "inproc")) { - describe(`socket with ${proto} xpub/xsub`, function() { + describe(`socket with ${proto} xpub/xsub`, function () { let pub: zmq.Publisher let sub: zmq.Subscriber let xpub: zmq.XPublisher let xsub: zmq.XSubscriber - beforeEach(function() { + beforeEach(function () { pub = new zmq.Publisher() sub = new zmq.Subscriber() xpub = new zmq.XPublisher() xsub = new zmq.XSubscriber() }) - afterEach(function() { + afterEach(function () { pub.close() sub.close() xpub.close() @@ -26,8 +26,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { global.gc?.() }) - describe("send/receive", function() { - it("should deliver messages", async function() { + describe("send/receive", function () { + it("should deliver messages", async function () { /* PUB -> foo -> XSUB -> XPUB -> SUB -> bar -> subscribed to all -> baz -> @@ -61,7 +61,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of xpub) { assert.instanceOf(msg, Buffer) await xsub.send(msg) - if (++subbed === 1) break + if (++subbed === 1) { + break + } } } @@ -70,7 +72,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of xsub) { assert.instanceOf(msg, Buffer) await xpub.send(msg) - if (++pubbed === messages.length) break + if (++pubbed === messages.length) { + break + } } } @@ -78,7 +82,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of sub) { assert.instanceOf(msg, Buffer) received.push(msg.toString()) - if (received.length === messages.length) break + if (received.length === messages.length) { + break + } } } @@ -87,8 +93,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("subscribe/unsubscribe", function() { - it("should filter messages", async function() { + describe("subscribe/unsubscribe", function () { + it("should filter messages", async function () { /* PUB -> foo -X XSUB -> XPUB -> SUB -> bar -> subscribed to "ba" -> baz -> @@ -123,7 +129,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of xpub) { assert.instanceOf(msg, Buffer) await xsub.send(msg) - if (++subbed === 1) break + if (++subbed === 1) { + break + } } } @@ -132,7 +140,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of xsub) { assert.instanceOf(msg, Buffer) await xpub.send(msg) - if (++pubbed === 2) break + if (++pubbed === 2) { + break + } } } @@ -140,7 +150,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { for await (const [msg] of sub) { assert.instanceOf(msg, Buffer) received.push(msg.toString()) - if (received.length === 2) break + if (received.length === 2) { + break + } } } @@ -149,8 +161,8 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { }) }) - describe("verbosity", function() { - it("should deduplicate subscriptions/unsubscriptions", async function() { + describe("verbosity", function () { + it("should deduplicate subscriptions/unsubscriptions", async function () { const address = uniqAddress(proto) const subs: Buffer[] = [] @@ -175,7 +187,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.instanceOf(msg, Buffer) await xsub.send(msg) subs.push(msg) - if (subs.length === 1) break + if (subs.length === 1) { + break + } } } @@ -185,7 +199,7 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { sub2.close() }) - it("should forward all subscriptions", async function() { + it("should forward all subscriptions", async function () { const address = uniqAddress(proto) const subs: Buffer[] = [] @@ -210,7 +224,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.instanceOf(msg, Buffer) await xsub.send(msg) subs.push(msg) - if (subs.length === 2) break + if (subs.length === 2) { + break + } } } @@ -223,9 +239,11 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { sub2.close() }) - it("should forward all subscriptions/unsubscriptions", async function() { + it("should forward all subscriptions/unsubscriptions", async function () { /* ZMQ 4.2 first introduced ZMQ_XPUB_VERBOSER. */ - if (semver.satisfies(zmq.version, "< 4.2")) this.skip() + if (semver.satisfies(zmq.version, "< 4.2")) { + this.skip() + } const address = uniqAddress(proto) @@ -251,7 +269,9 @@ for (const proto of testProtos("tcp", "ipc", "inproc")) { assert.instanceOf(msg, Buffer) await xsub.send(msg) subs.push(msg) - if (subs.length === 3) break + if (subs.length === 3) { + break + } } } diff --git a/test/unit/socket-zap-test.ts b/test/unit/socket-zap-test.ts index 90e0ee85..213cef1e 100644 --- a/test/unit/socket-zap-test.ts +++ b/test/unit/socket-zap-test.ts @@ -5,25 +5,27 @@ import {assert} from "chai" import {captureEvent, testProtos, uniqAddress} from "./helpers" for (const proto of testProtos("tcp", "ipc")) { - describe(`socket with ${proto} zap`, function() { + describe(`socket with ${proto} zap`, function () { let sockA: zmq.Pair let sockB: zmq.Pair let handler: ZapHandler - beforeEach(function() { + beforeEach(function () { sockA = new zmq.Pair() sockB = new zmq.Pair() }) - afterEach(function() { - if (handler) handler.stop() + afterEach(function () { + if (handler) { + handler.stop() + } sockA.close() sockB.close() global.gc?.() }) - describe("with plain mechanism", function() { - it("should deliver message", async function() { + describe("with plain mechanism", function () { + it("should deliver message", async function () { handler = new ValidatingZapHandler({ domain: "test", mechanism: "PLAIN", @@ -52,9 +54,11 @@ for (const proto of testProtos("tcp", "ipc")) { ) }) - it("should report authentication error", async function() { + it("should report authentication error", async function () { /* ZMQ < 4.3.0 does not have these event details. */ - if (semver.satisfies(zmq.version, "< 4.3.0")) this.skip() + if (semver.satisfies(zmq.version, "< 4.3.0")) { + this.skip() + } handler = new ValidatingZapHandler({ domain: "test", @@ -93,9 +97,11 @@ for (const proto of testProtos("tcp", "ipc")) { assert.equal(eventB.error.status, 400) }) - it("should report protocol version error", async function() { + it("should report protocol version error", async function () { /* ZMQ < 4.3.0 does not have these event details. */ - if (semver.satisfies(zmq.version, "< 4.3.0")) this.skip() + if (semver.satisfies(zmq.version, "< 4.3.0")) { + this.skip() + } handler = new CustomZapHandler( ([path, delim, version, id, ...rest]) => { @@ -122,9 +128,11 @@ for (const proto of testProtos("tcp", "ipc")) { assert.equal(eventA.error.code, "ERR_ZAP_BAD_VERSION") }) - it("should report protocol format error", async function() { + it("should report protocol format error", async function () { /* ZMQ < 4.3.0 does not have these event details. */ - if (semver.satisfies(zmq.version, "< 4.3.0")) this.skip() + if (semver.satisfies(zmq.version, "< 4.3.0")) { + this.skip() + } handler = new CustomZapHandler(([path, delim, ...rest]) => { return [path, delim, null, null] @@ -149,9 +157,11 @@ for (const proto of testProtos("tcp", "ipc")) { assert.equal(eventA.error.code, "ERR_ZAP_MALFORMED_REPLY") }) - it("should report mechanism mismatch error", async function() { + it("should report mechanism mismatch error", async function () { /* ZMQ < 4.3.0 does not have these event details. */ - if (semver.satisfies(zmq.version, "< 4.3.0")) this.skip() + if (semver.satisfies(zmq.version, "< 4.3.0")) { + this.skip() + } this.slow(250) diff --git a/test/unit/typings-compatibility-test.ts b/test/unit/typings-compatibility-test.ts index 587e0cc1..a47b3b23 100644 --- a/test/unit/typings-compatibility-test.ts +++ b/test/unit/typings-compatibility-test.ts @@ -72,9 +72,9 @@ async function run( errorAsString: boolean, ): Promise { return new Promise(resolve => { - exec(cmd, {cwd: cwd}, (error, stdout, stderr) => { + exec(cmd, {cwd}, (error, stdout, stderr) => { if (error) { - resolve(errorAsString ? stdout + "\n" + stderr : error) + resolve(errorAsString ? `${stdout}\n${stderr}` : error) } else { resolve(undefined) } @@ -86,16 +86,18 @@ function getItLabelDetails(tsVer: TestDef): string { const lbl = `v${tsVer.version} for (minimal) compile target ${JSON.stringify( tsVer.minTarget, )}` - if (!tsVer.requiredLibs || tsVer.requiredLibs.length === 0) return lbl + if (!tsVer.requiredLibs || tsVer.requiredLibs.length === 0) { + return lbl + } return `${lbl}, and required compile lib: ${JSON.stringify( tsVer.requiredLibs, )}` } -describe("compatibility of typings for typescript versions", function() { +describe("compatibility of typings for typescript versions", function () { let execCmd: "npm" | "yarn" - before(function(done) { + before(function (done) { this.timeout(10000) if (/^true$/.test(process.env.EXCLUDE_TYPINGS_COMPAT_TESTS as string)) { this.skip() @@ -124,7 +126,7 @@ describe("compatibility of typings for typescript versions", function() { }) for (const tsVer of tsVersions) { - describe(`when used in a project with typescript version ${tsVer.version}`, function() { + describe(`when used in a project with typescript version ${tsVer.version}`, function () { // must increase timeout for allowing `npm install`'ing the version of // the typescript package to complete this.timeout(30000) @@ -167,9 +169,11 @@ describe("compatibility of typings for typescript versions", function() { ), ), ]) - .then(() => run(execCmd + " install", tscTargetPath, false)) + .then(() => run(`${execCmd} install`, tscTargetPath, false)) .catch(err => { - if (err) done(err) + if (err) { + done(err) + } }) .then(() => done()) }) @@ -177,16 +181,18 @@ describe("compatibility of typings for typescript versions", function() { afterEach(done => { remove(tscTargetPath, err => { - if (err) return done(err) + if (err) { + return done(err) + } done() }) }) it(`it should compile successfully with tsc ${getItLabelDetails( tsVer, - )}`, async function() { - const cmd = execCmd === "npm" ? execCmd + " run" : execCmd - const errMsg = (await run(cmd + " test", tscTargetPath, true)) as + )}`, async function () { + const cmd = execCmd === "npm" ? `${execCmd} run` : execCmd + const errMsg = (await run(`${cmd} test`, tscTargetPath, true)) as | string | undefined assert.isUndefined(errMsg, errMsg) diff --git a/test/unit/typings-test.ts b/test/unit/typings-test.ts index a1095b5d..906ae599 100644 --- a/test/unit/typings-test.ts +++ b/test/unit/typings-test.ts @@ -1,7 +1,7 @@ import * as zmq from "../../src" -describe("typings", function() { - it("should compile successfully", function() { +describe("typings", function () { + it("should compile successfully", function () { /* To test the TypeScript typings this file should compile successfully. We don't actually execute the code in this function. */ @@ -11,13 +11,27 @@ describe("typings", function() { console.log(version) const capability = zmq.capability - if (capability.ipc) console.log("ipc") - if (capability.pgm) console.log("pgm") - if (capability.tipc) console.log("tipc") - if (capability.norm) console.log("norm") - if (capability.curve) console.log("curve") - if (capability.gssapi) console.log("gssapi") - if (capability.draft) console.log("draft") + if (capability.ipc) { + console.log("ipc") + } + if (capability.pgm) { + console.log("pgm") + } + if (capability.tipc) { + console.log("tipc") + } + if (capability.norm) { + console.log("norm") + } + if (capability.curve) { + console.log("curve") + } + if (capability.gssapi) { + console.log("gssapi") + } + if (capability.draft) { + console.log("draft") + } const keypair = zmq.curveKeyPair() console.log(keypair.publicKey) @@ -44,7 +58,9 @@ describe("typings", function() { }) const router = new zmq.Router() - if (router.type !== 6) throw new Error() + if (router.type !== 6) { + throw new Error() + } console.log(socket.context) console.log(socket.sendTimeout) diff --git a/test/unit/zmq-draft-test.ts b/test/unit/zmq-draft-test.ts index 2b1b513c..c1568ac2 100644 --- a/test/unit/zmq-draft-test.ts +++ b/test/unit/zmq-draft-test.ts @@ -4,9 +4,9 @@ import * as draft from "../../src/draft" import {assert} from "chai" if (zmq.capability.draft) { - describe("zmq draft", function() { - describe("exports", function() { - it("should include functions and constructors", function() { + describe("zmq draft", function () { + describe("exports", function () { + it("should include functions and constructors", function () { const expected = [ /* Specific socket constructors. */ "Server", diff --git a/test/unit/zmq-test.ts b/test/unit/zmq-test.ts index 0a84be9d..23ee0687 100644 --- a/test/unit/zmq-test.ts +++ b/test/unit/zmq-test.ts @@ -3,9 +3,9 @@ import * as zmq from "../../src" import {assert} from "chai" -describe("zmq", function() { - describe("exports", function() { - it("should include functions and constructors", function() { +describe("zmq", function () { + describe("exports", function () { + it("should include functions and constructors", function () { const expected = [ /* Utility functions. */ "version", @@ -45,8 +45,8 @@ describe("zmq", function() { }) }) - describe("version", function() { - it("should return version string", function() { + describe("version", function () { + it("should return version string", function () { if (process.env.ZMQ_VERSION) { assert.equal(zmq.version, process.env.ZMQ_VERSION) } else { @@ -55,8 +55,8 @@ describe("zmq", function() { }) }) - describe("capability", function() { - it("should return library capability booleans", function() { + describe("capability", function () { + it("should return library capability booleans", function () { assert.equal( Object.values(zmq.capability).every(c => typeof c === "boolean"), true, @@ -64,12 +64,14 @@ describe("zmq", function() { }) }) - describe("curve keypair", function() { - beforeEach(function() { - if (!zmq.capability.curve) this.skip() + describe("curve keypair", function () { + beforeEach(function () { + if (!zmq.capability.curve) { + this.skip() + } }) - it("should return keypair", function() { + it("should return keypair", function () { const {publicKey, secretKey} = zmq.curveKeyPair() assert.match(publicKey, /^[\x20-\x7F]{40}$/) assert.match(secretKey, /^[\x20-\x7F]{40}$/)