Skip to content

Commit 6a49ce0

Browse files
authored
Merge pull request #671 from zeromq/test [skip ci]
2 parents f07714d + 40ab894 commit 6a49ce0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+492
-487
lines changed

.eslintrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"@typescript-eslint/quotes": ["error", "double"],
66
"require-await": "off",
77
"@typescript-eslint/strict-boolean-expressions": "off",
8+
"@typescript-eslint/no-extraneous-class": "off",
89
"@typescript-eslint/no-explicit-any": "off",
910
"no-await-in-loop": "off",
1011
"class-methods-use-this": "off"

.github/workflows/CI.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,19 @@ jobs:
175175
timeout_minutes: 5
176176
max_attempts: 1
177177
command: |
178-
pnpm run test
178+
pnpm run clean.temp
179+
pnpm run test.unit
180+
continue-on-error: true
181+
182+
- name: Test Compatibility
183+
if: ${{ !matrix.docker }}
184+
uses: nick-fields/retry@v3
185+
with:
186+
timeout_minutes: 5
187+
max_attempts: 1
188+
command: |
189+
pnpm run clean.temp
190+
pnpm run test.unit.compat
179191
continue-on-error: true
180192

181193
- name: Test Electron (Main)

.mocharc.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@
33
*/
44
const config = {
55
require: ["ts-node/register"],
6-
spec: ["test/unit/*-test.ts", "test/unit/compat/*-test.js"],
76
"expose-gc": true,
87
"v8-expose-gc": true,
98
exit: true,
109
parallel: true,
11-
timeout: 10000,
12-
retries: 3,
10+
timeout: 5000,
11+
retries: 1,
12+
fullTrace: true,
13+
bail: false,
1314
}
1415

1516
module.exports = config

.vscode/settings.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,13 @@
1313
},
1414
"mochaExplorer.parallel": true,
1515
"mochaExplorer.globImplementation": "vscode",
16-
"mochaExplorer.nodeArgv": [
17-
"--expose-gc"
18-
],
16+
"mochaExplorer.nodeArgv": ["--expose-gc"],
1917
"mochaExplorer.debuggerConfig": "JS-Attach",
18+
"mochaExplorer.env": {
19+
"INCLUDE_COMPAT_TESTS": "true"
20+
},
21+
"mochaExplorer.files": "test/unit/**/*-test.ts",
22+
"mochaExplorer.mochaPath": "./node_modules/mocha",
2023
"files.exclude": {
2124
"**/.DS_Store": true,
2225
"**/Thumbs.db": true,

package.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"@types/which": "^3.0.4",
3737
"benchmark": "^2.1.4",
3838
"chai": "^4",
39+
"cross-env": "^7.0.3",
3940
"deasync": "^0.1.30",
4041
"downlevel-dts": "^0.11.0",
4142
"electron-mocha": "^13.0.0",
@@ -97,9 +98,11 @@
9798
"build.native.debug": "cmake-ts dev-os-only",
9899
"build": "run-p build.js build.native",
99100
"build.debug": "run-s build.js build.native.debug",
100-
"test": "run-s clean.temp build && mocha",
101+
"test": "run-s test.unit",
102+
"test.unit": "run-s clean.temp build && cross-env INCLUDE_COMPAT_TESTS=false mocha ./test/unit/*-test.ts",
103+
"test.unit.compat": "run-s clean.temp build && cross-env INCLUDE_COMPAT_TESTS=true mocha ./test/unit/compat/*-test.ts",
101104
"test.smoke": "bash ./script/smoke-test.bash",
102-
"test.skip_gc_tests": "run-s clean.temp build.debug && cross-env SKIP_GC_TESTS=true mocha",
105+
"test.skip_gc_tests": "run-s clean.temp build && cross-env SKIP_GC_TESTS=true mocha",
103106
"test.electron.main": "run-s clean.temp build && electron-mocha",
104107
"format": "run-s format.prettier format.clang-format",
105108
"format.prettier": "prettier -l --cache --cache-location ./.cache/prettier --write .",

pnpm-lock.yaml

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/compat.ts

Lines changed: 30 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
import {EventEmitter} from "events"
77
import * as zmq from "."
88
import {FullError} from "./errors"
9+
import * as longOptions from "./compat/long-options"
10+
import * as pollStates from "./compat/poll-states"
11+
import * as sendOptions from "./compat/send-options"
912

1013
type AnySocket =
1114
| zmq.Pair
@@ -22,99 +25,6 @@ type AnySocket =
2225
| zmq.Stream
2326

2427
let count = 1
25-
const types = {
26-
ZMQ_PAIR: 0,
27-
ZMQ_PUB: 1,
28-
ZMQ_SUB: 2,
29-
ZMQ_REQ: 3,
30-
ZMQ_REP: 4,
31-
ZMQ_DEALER: 5,
32-
ZMQ_XREQ: 5,
33-
ZMQ_ROUTER: 6,
34-
ZMQ_XREP: 6,
35-
ZMQ_PULL: 7,
36-
ZMQ_PUSH: 8,
37-
ZMQ_XPUB: 9,
38-
ZMQ_XSUB: 10,
39-
ZMQ_STREAM: 11,
40-
}
41-
42-
const longOptions = {
43-
ZMQ_AFFINITY: 4,
44-
ZMQ_IDENTITY: 5,
45-
ZMQ_SUBSCRIBE: 6,
46-
ZMQ_UNSUBSCRIBE: 7,
47-
ZMQ_RATE: 8,
48-
ZMQ_RECOVERY_IVL: 9,
49-
ZMQ_RECOVERY_IVL_MSEC: 9,
50-
ZMQ_SNDBUF: 11,
51-
ZMQ_RCVBUF: 12,
52-
ZMQ_RCVMORE: 13,
53-
ZMQ_FD: 14,
54-
ZMQ_EVENTS: 15,
55-
ZMQ_TYPE: 16,
56-
ZMQ_LINGER: 17,
57-
ZMQ_RECONNECT_IVL: 18,
58-
ZMQ_BACKLOG: 19,
59-
ZMQ_RECONNECT_IVL_MAX: 21,
60-
ZMQ_MAXMSGSIZE: 22,
61-
ZMQ_SNDHWM: 23,
62-
ZMQ_RCVHWM: 24,
63-
ZMQ_MULTICAST_HOPS: 25,
64-
ZMQ_RCVTIMEO: 27,
65-
ZMQ_SNDTIMEO: 28,
66-
ZMQ_IPV4ONLY: 31,
67-
ZMQ_LAST_ENDPOINT: 32,
68-
ZMQ_ROUTER_MANDATORY: 33,
69-
ZMQ_TCP_KEEPALIVE: 34,
70-
ZMQ_TCP_KEEPALIVE_CNT: 35,
71-
ZMQ_TCP_KEEPALIVE_IDLE: 36,
72-
ZMQ_TCP_KEEPALIVE_INTVL: 37,
73-
ZMQ_TCP_ACCEPT_FILTER: 38,
74-
ZMQ_DELAY_ATTACH_ON_CONNECT: 39,
75-
ZMQ_XPUB_VERBOSE: 40,
76-
ZMQ_ROUTER_RAW: 41,
77-
ZMQ_IPV6: 42,
78-
ZMQ_MECHANISM: 43,
79-
ZMQ_PLAIN_SERVER: 44,
80-
ZMQ_PLAIN_USERNAME: 45,
81-
ZMQ_PLAIN_PASSWORD: 46,
82-
ZMQ_CURVE_SERVER: 47,
83-
ZMQ_CURVE_PUBLICKEY: 48,
84-
ZMQ_CURVE_SECRETKEY: 49,
85-
ZMQ_CURVE_SERVERKEY: 50,
86-
ZMQ_ZAP_DOMAIN: 55,
87-
ZMQ_HEARTBEAT_IVL: 75,
88-
ZMQ_HEARTBEAT_TTL: 76,
89-
ZMQ_HEARTBEAT_TIMEOUT: 77,
90-
ZMQ_CONNECT_TIMEOUT: 79,
91-
ZMQ_IO_THREADS: 1,
92-
ZMQ_MAX_SOCKETS: 2,
93-
ZMQ_ROUTER_HANDOVER: 56,
94-
}
95-
96-
const pollStates = {
97-
ZMQ_POLLIN: 1,
98-
ZMQ_POLLOUT: 2,
99-
ZMQ_POLLERR: 4,
100-
}
101-
102-
const sendOptions = {
103-
ZMQ_SNDMORE: 2,
104-
}
105-
106-
const capabilities = {
107-
ZMQ_CAN_MONITOR: 1,
108-
ZMQ_CAN_DISCONNECT: 1,
109-
ZMQ_CAN_UNBIND: 1,
110-
ZMQ_CAN_SET_CTX: 1,
111-
}
112-
113-
const socketStates = {
114-
STATE_READY: 0,
115-
STATE_BUSY: 1,
116-
STATE_CLOSED: 2,
117-
}
11828

11929
const shortOptions = {
12030
_fd: longOptions.ZMQ_FD,
@@ -241,9 +151,11 @@ class Socket extends EventEmitter {
241151
case "stream":
242152
this._socket = new zmq.Stream()
243153
break
154+
default:
155+
throw new Error(`Invalid socket type: ${type}`)
244156
}
245157

246-
const recv = async () => {
158+
const recv = () => {
247159
this.once("_flushRecv", async () => {
248160
while (!this._socket.closed && !this._paused) {
249161
await this._recv()
@@ -347,7 +259,7 @@ class Socket extends EventEmitter {
347259
.catch(err => {
348260
process.nextTick(() => {
349261
if (cb) {
350-
cb(err)
262+
cb(err as Error)
351263
} else {
352264
this.emit("error", err)
353265
}
@@ -371,7 +283,7 @@ class Socket extends EventEmitter {
371283
.catch(err => {
372284
process.nextTick(() => {
373285
if (cb) {
374-
cb(err)
286+
cb(err as Error)
375287
} else {
376288
this.emit("error", err)
377289
}
@@ -391,8 +303,12 @@ class Socket extends EventEmitter {
391303
return this
392304
}
393305

394-
send(message: zmq.MessageLike[], flags = 0, cb?: Callback) {
395-
flags = flags | 0
306+
send(
307+
message: zmq.MessageLike[] | zmq.MessageLike,
308+
givenFlags: number | undefined | null = 0,
309+
cb: Callback | undefined = undefined,
310+
) {
311+
const flags = (givenFlags ?? 0) | 0
396312
this._msg = this._msg.concat(message)
397313
if ((flags & sendOptions.ZMQ_SNDMORE) === 0) {
398314
this._sendQueue.push([this._msg, cb])
@@ -460,7 +376,7 @@ class Socket extends EventEmitter {
460376
return this._socket.closed
461377
}
462378

463-
monitor(interval: number, num: number) {
379+
monitor(interval?: number, num?: number) {
464380
this._count = count++
465381

466382
/* eslint-disable-next-line no-unused-expressions */
@@ -560,8 +476,9 @@ class Socket extends EventEmitter {
560476
}
561477
}
562478

563-
setsockopt(option: number | keyof typeof shortOptions, value: any) {
564-
option = typeof option !== "number" ? shortOptions[option] : option
479+
setsockopt(givenOption: number | keyof typeof shortOptions, value: any) {
480+
const option =
481+
typeof givenOption === "number" ? givenOption : shortOptions[givenOption]
565482

566483
switch (option) {
567484
case longOptions.ZMQ_AFFINITY:
@@ -699,8 +616,9 @@ class Socket extends EventEmitter {
699616
return this
700617
}
701618

702-
getsockopt(option: number | keyof typeof shortOptions) {
703-
option = typeof option !== "number" ? shortOptions[option] : option
619+
getsockopt(givenOption: number | keyof typeof shortOptions) {
620+
const option =
621+
typeof givenOption !== "number" ? shortOptions[givenOption] : givenOption
704622

705623
switch (option) {
706624
case longOptions.ZMQ_AFFINITY:
@@ -822,10 +740,9 @@ for (const key in shortOptions) {
822740
get(this: Socket) {
823741
return this.getsockopt(shortOptions[key as keyof typeof shortOptions])
824742
},
825-
set(this: Socket, val: string | Buffer) {
826-
if ("string" === typeof val) {
827-
val = Buffer.from(val, "utf8")
828-
}
743+
set(this: Socket, givenVal: string | Buffer) {
744+
const val =
745+
typeof givenVal === "string" ? Buffer.from(givenVal, "utf8") : givenVal
829746
return this.setsockopt(
830747
shortOptions[key as keyof typeof shortOptions],
831748
val,
@@ -909,11 +826,9 @@ export {
909826
shortOptions as options,
910827
}
911828

912-
/* Unfortunately there is no easy way to include these in the resulting
913-
TS definitions. */
914-
Object.assign(module.exports, longOptions)
915-
Object.assign(module.exports, types)
916-
Object.assign(module.exports, pollStates)
917-
Object.assign(module.exports, sendOptions)
918-
Object.assign(module.exports, socketStates)
919-
Object.assign(module.exports, capabilities)
829+
export * from "./compat/long-options"
830+
export * from "./compat/types"
831+
export * from "./compat/poll-states"
832+
export * from "./compat/send-options"
833+
export * from "./compat/capabilities"
834+
export * from "./compat/socket-states"

src/compat/capabilities.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
export const ZMQ_CAN_MONITOR = 1
2+
export const ZMQ_CAN_DISCONNECT = 1
3+
export const ZMQ_CAN_UNBIND = 1
4+
export const ZMQ_CAN_SET_CTX = 1

src/compat/long-options.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
export const ZMQ_AFFINITY = 4
2+
export const ZMQ_IDENTITY = 5
3+
export const ZMQ_SUBSCRIBE = 6
4+
export const ZMQ_UNSUBSCRIBE = 7
5+
export const ZMQ_RATE = 8
6+
export const ZMQ_RECOVERY_IVL = 9
7+
export const ZMQ_RECOVERY_IVL_MSEC = 9
8+
export const ZMQ_SNDBUF = 11
9+
export const ZMQ_RCVBUF = 12
10+
export const ZMQ_RCVMORE = 13
11+
export const ZMQ_FD = 14
12+
export const ZMQ_EVENTS = 15
13+
export const ZMQ_TYPE = 16
14+
export const ZMQ_LINGER = 17
15+
export const ZMQ_RECONNECT_IVL = 18
16+
export const ZMQ_BACKLOG = 19
17+
export const ZMQ_RECONNECT_IVL_MAX = 21
18+
export const ZMQ_MAXMSGSIZE = 22
19+
export const ZMQ_SNDHWM = 23
20+
export const ZMQ_RCVHWM = 24
21+
export const ZMQ_MULTICAST_HOPS = 25
22+
export const ZMQ_RCVTIMEO = 27
23+
export const ZMQ_SNDTIMEO = 28
24+
export const ZMQ_IPV4ONLY = 31
25+
export const ZMQ_LAST_ENDPOINT = 32
26+
export const ZMQ_ROUTER_MANDATORY = 33
27+
export const ZMQ_TCP_KEEPALIVE = 34
28+
export const ZMQ_TCP_KEEPALIVE_CNT = 35
29+
export const ZMQ_TCP_KEEPALIVE_IDLE = 36
30+
export const ZMQ_TCP_KEEPALIVE_INTVL = 37
31+
export const ZMQ_TCP_ACCEPT_FILTER = 38
32+
export const ZMQ_DELAY_ATTACH_ON_CONNECT = 39
33+
export const ZMQ_XPUB_VERBOSE = 40
34+
export const ZMQ_ROUTER_RAW = 41
35+
export const ZMQ_IPV6 = 42
36+
export const ZMQ_MECHANISM = 43
37+
export const ZMQ_PLAIN_SERVER = 44
38+
export const ZMQ_PLAIN_USERNAME = 45
39+
export const ZMQ_PLAIN_PASSWORD = 46
40+
export const ZMQ_CURVE_SERVER = 47
41+
export const ZMQ_CURVE_PUBLICKEY = 48
42+
export const ZMQ_CURVE_SECRETKEY = 49
43+
export const ZMQ_CURVE_SERVERKEY = 50
44+
export const ZMQ_ZAP_DOMAIN = 55
45+
export const ZMQ_HEARTBEAT_IVL = 75
46+
export const ZMQ_HEARTBEAT_TTL = 76
47+
export const ZMQ_HEARTBEAT_TIMEOUT = 77
48+
export const ZMQ_CONNECT_TIMEOUT = 79
49+
export const ZMQ_IO_THREADS = 1
50+
export const ZMQ_MAX_SOCKETS = 2
51+
export const ZMQ_ROUTER_HANDOVER = 56

0 commit comments

Comments
 (0)