Skip to content

Commit 44e061b

Browse files
authored
Merge pull request #624 from zeromq/tests
Fix various failing tests
2 parents 66cf54f + 97dc8d8 commit 44e061b

Some content is hidden

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

46 files changed

+663
-439
lines changed

.eslintrc

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,20 @@
11
{
2-
"plugins": ["prettier"],
3-
"extends": ["plugin:prettier/recommended", "eslint-config-atomic"],
2+
"plugins": [
3+
"prettier"
4+
],
5+
"extends": [
6+
"eslint-config-atomic"
7+
],
48
"rules": {
5-
"@typescript-eslint/quotes": ["error", "double"],
6-
"require-await": "off"
9+
"@typescript-eslint/quotes": [
10+
"error",
11+
"double"
12+
],
13+
"require-await": "off",
14+
"@typescript-eslint/strict-boolean-expressions": "off",
15+
"@typescript-eslint/no-explicit-any": "off",
16+
"no-await-in-loop": "off",
17+
"class-methods-use-this": "off"
718
},
819
"ignorePatterns": [
920
"node_modules/",
@@ -15,6 +26,8 @@
1526
"script/*.js",
1627
"script/*.d.ts",
1728
"docs/",
18-
"docs-raw/"
29+
"docs-raw/",
30+
"test/unit/compat/",
31+
"test/bench/"
1932
]
2033
}

.mocharc.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
1-
"use strict"
2-
3-
module.exports = {
1+
/**
2+
* @type {import('mocha').MochaOptions}
3+
*/
4+
const config = {
45
require: ["ts-node/register", "rocha"],
5-
spec: ["test/unit/*-test.ts", "test/unit/compat/*-test.{ts,js}"],
6+
spec: [
7+
"test/unit/*-test.ts",
8+
"test/unit/compat/*-test.js",
9+
],
610
"expose-gc": true,
711
"v8-expose-gc": true,
812
"experimental-worker": true,
913
recursive: true,
14+
exit: true,
15+
parallel: true,
1016
}
17+
18+
module.exports = config

.vscode/extensions.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"recommendations": [
3+
"hbenl.vscode-mocha-test-adapter",
4+
"hbenl.vscode-test-explorer",
5+
"llvm-vs-code-extensions.vscode-clangd",
6+
"xadillax.gyp",
7+
"dbaeumer.vscode-eslint",
8+
"esbenp.prettier-vscode"
9+
]
10+
}

.vscode/settings.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"mochaExplorer.parallel": true,
3+
"mochaExplorer.globImplementation": "vscode"
4+
}

examples/majordomo/broker.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ export class Broker {
1818
await this.socket.bind(this.address)
1919

2020
const loop = async () => {
21-
for await (const [sender, blank, header, ...rest] of this.socket) {
21+
for await (const [sender, _blank, header, ...rest] of this.socket) {
2222
switch (header.toString()) {
2323
case Header.Client:
2424
this.handleClient(sender, ...rest)
@@ -32,7 +32,7 @@ export class Broker {
3232
}
3333
}
3434

35-
loop()
35+
return loop()
3636
}
3737

3838
async stop() {
@@ -56,8 +56,10 @@ export class Broker {
5656
}
5757

5858
case Message.Reply: {
59-
const [client, blank, ...rep] = rest
60-
this.dispatchReply(worker, client, ...rep)
59+
const [client, _blank, ...rep] = rest
60+
this.dispatchReply(worker, client, ...rep).catch(err => {
61+
console.error(err)
62+
})
6163
break
6264
}
6365

@@ -85,7 +87,7 @@ export class Broker {
8587

8688
dispatchReply(worker: Buffer, client: Buffer, ...rep: Buffer[]) {
8789
const service = this.getWorkerService(worker)
88-
this.getService(service).dispatchReply(worker, client, ...rep)
90+
return this.getService(service).dispatchReply(worker, client, ...rep)
8991
}
9092

9193
deregister(worker: Buffer) {

examples/majordomo/index.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import {Broker} from "./broker"
44
import {Worker} from "./worker"
55

66
async function sleep(msec: number) {
7-
return new Promise(resolve => setTimeout(resolve, msec))
7+
return new Promise(resolve => {
8+
setTimeout(resolve, msec)
9+
})
810
}
911

1012
class TeaWorker extends Worker {
@@ -40,7 +42,7 @@ async function request(
4042
await socket.send(["MDPC01", service, ...req])
4143

4244
try {
43-
const [blank, header, ...res] = await socket.receive()
45+
const [_blank, _header, ...res] = await socket.receive()
4446
console.log(`received '${res.join(", ")}' from '${service}'`)
4547
return res
4648
} catch (err) {
@@ -50,9 +52,9 @@ async function request(
5052

5153
async function main() {
5254
for (const worker of workers) {
53-
worker.start()
55+
await worker.start()
5456
}
55-
broker.start()
57+
await broker.start()
5658

5759
/* Requests are issued in parallel. */
5860
await Promise.all([
@@ -68,9 +70,9 @@ async function main() {
6870
])
6971

7072
for (const worker of workers) {
71-
worker.stop()
73+
await worker.stop()
7274
}
73-
broker.stop()
75+
await broker.stop()
7476
}
7577

7678
main().catch(err => {

examples/majordomo/service.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class Service {
1515

1616
dispatchRequest(client: Buffer, ...req: Buffer[]) {
1717
this.requests.push([client, req])
18-
this.dispatchPending()
18+
return this.dispatchPending()
1919
}
2020

2121
async dispatchReply(worker: Buffer, client: Buffer, ...rep: Buffer[]) {
@@ -28,12 +28,15 @@ export class Service {
2828

2929
await this.socket.send([client, null, Header.Client, this.name, ...rep])
3030

31-
this.dispatchPending()
31+
return this.dispatchPending()
3232
}
3333

3434
async dispatchPending() {
3535
while (this.workers.size && this.requests.length) {
36-
const [key, worker] = this.workers.entries().next().value!
36+
const [key, worker] = this.workers.entries().next().value as [
37+
string,
38+
Buffer,
39+
]
3740
this.workers.delete(key)
3841
const [client, req] = this.requests.shift()!
3942

@@ -42,6 +45,7 @@ export class Service {
4245
`${client.toString("hex")} req -> ${worker.toString("hex")}`,
4346
)
4447

48+
// eslint-disable-next-line no-await-in-loop
4549
await this.socket.send([
4650
worker,
4751
null,
@@ -59,14 +63,14 @@ export class Service {
5963
`registered worker ${worker.toString("hex")} for '${this.name}'`,
6064
)
6165
this.workers.set(worker.toString("hex"), worker)
62-
this.dispatchPending()
66+
return this.dispatchPending()
6367
}
6468

6569
deregister(worker: Buffer) {
6670
console.log(
6771
`deregistered worker ${worker.toString("hex")} for '${this.name}'`,
6872
)
6973
this.workers.delete(worker.toString("hex"))
70-
this.dispatchPending()
74+
return this.dispatchPending()
7175
}
7276
}

examples/majordomo/worker.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,14 @@ export class Worker {
1616
await this.socket.send([null, Header.Worker, Message.Ready, this.service])
1717

1818
const loop = async () => {
19-
for await (const [blank1, header, type, client, blank2, ...req] of this
20-
.socket) {
19+
for await (const [
20+
_blank1,
21+
_header,
22+
_type,
23+
client,
24+
_blank2,
25+
...req
26+
] of this.socket) {
2127
const rep = await this.process(...req)
2228
try {
2329
await this.socket.send([
@@ -34,7 +40,7 @@ export class Worker {
3440
}
3541
}
3642

37-
loop()
43+
return loop()
3844
}
3945

4046
async stop() {

examples/threaded-worker/processor.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ export class Processor {
2222
this.input.bind("inproc://input"),
2323
this.output.bind("inproc://output"),
2424
this.signal.bind("inproc://signal"),
25-
new Promise(resolve => setTimeout(resolve, 100)),
25+
new Promise(resolve => {
26+
setTimeout(resolve, 100)
27+
}),
2628
])
2729

2830
this.exit = Promise.all([ThreadedWorker.spawn(this.threads)])

examples/threaded-worker/threaded-worker.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,14 @@ export class ThreadedWorker {
4343
const listen = async () => {
4444
for await (const [sig] of this.signal) {
4545
if (sig.toString() === "stop") {
46-
this.stop()
46+
await this.stop()
4747
}
4848
}
4949
}
5050

51-
listen()
51+
listen().catch(err => {
52+
throw err
53+
})
5254
}
5355

5456
async stop() {

0 commit comments

Comments
 (0)