Skip to content

Commit cd82f49

Browse files
committed
fix: do not mix done/async
1 parent b658989 commit cd82f49

11 files changed

+78
-68
lines changed

test/unit/compat/README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
The tests in this directory have been modified from the original ZeroMQ.js version
2-
(up to 5.x) for which the license and copyright notice is reproduced below.
1+
The tests in this directory have been modified from the original ZeroMQ.js
2+
version (up to 5.x) for which the license and copyright notice is reproduced
3+
below.
34

45
Copyright (c) 2011 TJ Holowaychuk Copyright (c) 2010, 2011 Justin Tulloss
56

test/unit/compat/gc-test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
import * as zmq from "../../../v5-compat"
22
import {assert} from "chai"
3-
import { testProtos, uniqAddress } from "../helpers"
3+
import {testProtos, uniqAddress} from "../helpers"
44

55
if (process.env.INCLUDE_COMPAT_TESTS) {
6-
76
for (const proto of testProtos("tcp", "inproc")) {
87
describe(`compat socket with ${proto}`, function () {
9-
it("should cooperate with gc", async function (done) {
8+
let address: string
9+
beforeEach(async () => {
10+
address = await uniqAddress(proto)
11+
})
12+
13+
it("should cooperate with gc", function (done) {
1014
const sockA = zmq.socket("dealer")
1115
const sockB = zmq.socket("dealer")
1216

@@ -29,7 +33,6 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
2933

3034
let bound = false
3135

32-
const address = await uniqAddress(proto)
3336
sockA.bind(address, err => {
3437
if (err) {
3538
clearInterval(interval)

test/unit/compat/socket-events-test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import {testProtos, uniqAddress} from "../helpers"
55
if (process.env.INCLUDE_COMPAT_TESTS) {
66
for (const proto of testProtos("tcp", "inproc")) {
77
describe(`compat socket with ${proto} events`, function () {
8-
it("should support events", async function (done) {
8+
let address: string
9+
beforeEach(async () => {
10+
address = await uniqAddress(proto)
11+
})
12+
13+
it("should support events", function (done) {
914
const rep = zmq.socket("rep")
1015
const req = zmq.socket("req")
1116

12-
const address = await uniqAddress(proto)
13-
1417
rep.on("message", function (msg) {
1518
assert.instanceOf(msg, Buffer)
1619
assert.equal(msg.toString(), "hello")

test/unit/compat/socket-messages-test.ts

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
77
describe(`compat socket with ${proto} messages`, function () {
88
let push: zmq.Socket
99
let pull: zmq.Socket
10+
let address: string
1011

11-
beforeEach(function () {
12+
beforeEach(async function () {
1213
push = zmq.socket("push")
1314
pull = zmq.socket("pull")
15+
address = await uniqAddress(proto)
1416
})
1517

16-
it("should support messages", async function (done) {
17-
const address = await uniqAddress(proto)
18-
18+
it("should support messages", function (done) {
1919
let n = 0
2020

2121
pull.on("message", function (msg) {
@@ -43,9 +43,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
4343
push.send(Buffer.from("buffer"))
4444
})
4545

46-
it("should support multipart messages", async function (done) {
47-
const address = await uniqAddress(proto)
48-
46+
it("should support multipart messages", function (done) {
4947
pull.on("message", function (msg1, msg2, msg3) {
5048
assert.equal(msg1.toString(), "string")
5149
assert.equal(msg2.toString(), "15.99")
@@ -60,9 +58,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
6058
push.send(["string", 15.99, Buffer.from("buffer")])
6159
})
6260

63-
it("should support sndmore", async function (done) {
64-
const address = await uniqAddress(proto)
65-
61+
it("should support sndmore", function (done) {
6662
pull.on("message", function (a, b, c, d, e) {
6763
assert.equal(a.toString(), "tobi")
6864
assert.equal(b.toString(), "loki")
@@ -82,8 +78,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
8278
})
8379

8480
if (proto != "inproc") {
85-
it("should handle late connect", async function (done) {
86-
const address = await uniqAddress(proto)
81+
it("should handle late connect", function (done) {
8782
let n = 0
8883

8984
pull.on("message", function (msg) {
@@ -115,8 +110,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
115110
})
116111
}
117112

118-
it("should call send callbacks", async function (done) {
119-
const address = await uniqAddress(proto)
113+
it("should call send callbacks", function (done) {
120114
let received = 0
121115
let callbacks = 0
122116

test/unit/compat/socket-monitor-test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
88
/* This test case only seems to work reliably with TCP. */
99
for (const proto of testProtos("tcp")) {
1010
describe(`compat socket with ${proto} monitor`, function () {
11+
let address: string
12+
beforeEach(async () => {
13+
address = await uniqAddress(proto)
14+
})
15+
1116
beforeEach(function () {
1217
/* ZMQ < 4.2 occasionally fails with assertion errors. */
1318
if (semver.satisfies(zmq.version, "< 4.2")) {
@@ -24,12 +29,10 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
2429
}
2530
})
2631

27-
it("should be able to monitor the socket", async function (done) {
32+
it("should be able to monitor the socket", function (done) {
2833
const rep = zmq.socket("rep")
2934
const req = zmq.socket("req")
3035

31-
const address = await uniqAddress(proto)
32-
3336
rep.on("message", function (msg) {
3437
assert.instanceOf(msg, Buffer)
3538
assert.equal(msg.toString(), "hello")

test/unit/compat/socket-pair-test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import {testProtos, uniqAddress} from "../helpers"
55
if (process.env.INCLUDE_COMPAT_TESTS) {
66
for (const proto of testProtos("tcp")) {
77
describe(`compat socket with ${proto} pair`, function () {
8-
it("should support pair-pair", async function (done) {
8+
let address: string
9+
beforeEach(async () => {
10+
address = await uniqAddress(proto)
11+
})
12+
13+
it("should support pair-pair", function (done) {
914
const pairA = zmq.socket("pair")
1015
const pairB = zmq.socket("pair")
1116

12-
const address = await uniqAddress(proto)
13-
1417
let n = 0
1518
pairA.monitor()
1619
pairB.monitor()

test/unit/compat/socket-pub-sub-test.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
77
describe(`compat socket with ${proto} pub-sub`, function () {
88
let pub: zmq.Socket
99
let sub: zmq.Socket
10-
11-
beforeEach(function () {
10+
let address: string
11+
beforeEach(async function () {
1212
pub = zmq.socket("pub")
1313
sub = zmq.socket("sub")
14+
address = await uniqAddress(proto)
1415
})
1516

16-
it("should support pub-sub", async function (done) {
17-
const address = await uniqAddress(proto)
17+
it("should support pub-sub", function (done) {
1818
let n = 0
1919

2020
sub.subscribe("")
@@ -59,8 +59,7 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
5959
})
6060
})
6161

62-
it("should support pub-sub filter", async function (done) {
63-
const address = await uniqAddress(proto)
62+
it("should support pub-sub filter", function (done) {
6463
let n = 0
6564

6665
sub.subscribe("js")
@@ -112,13 +111,12 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
112111
}
113112
})
114113

115-
it("should continue to deliver messages in message handler", async function (done) {
114+
it("should continue to deliver messages in message handler", function (done) {
116115
let error: Error
117116
process.once("uncaughtException", err => {
118117
error = err
119118
})
120119

121-
const address = await uniqAddress(proto)
122120
let n = 0
123121

124122
sub.subscribe("")

test/unit/compat/socket-push-pull-test.ts

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import {testProtos, uniqAddress} from "../helpers"
55
if (process.env.INCLUDE_COMPAT_TESTS) {
66
for (const proto of testProtos("tcp", "inproc")) {
77
describe(`compat socket with ${proto} push-pull`, function () {
8-
it("should support push-pull", async function (done) {
8+
let address: string
9+
beforeEach(async () => {
10+
address = await uniqAddress(proto)
11+
})
12+
13+
it("should support push-pull", function (done) {
914
const push = zmq.socket("push")
1015
const pull = zmq.socket("pull")
1116

12-
const address = await uniqAddress(proto)
13-
1417
let n = 0
1518
pull.on("message", function (msg) {
1619
assert.instanceOf(msg, Buffer)
@@ -42,12 +45,10 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
4245
})
4346
})
4447

45-
it("should not emit messages after pause", async function (done) {
48+
it("should not emit messages after pause", function (done) {
4649
const push = zmq.socket("push")
4750
const pull = zmq.socket("pull")
4851

49-
const address = await uniqAddress(proto)
50-
5152
let n = 0
5253

5354
pull.on("message", function (msg) {
@@ -77,12 +78,10 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
7778
}, 15)
7879
})
7980

80-
it("should be able to read messages after pause", async function (done) {
81+
it("should be able to read messages after pause", function (done) {
8182
const push = zmq.socket("push")
8283
const pull = zmq.socket("pull")
8384

84-
const address = await uniqAddress(proto)
85-
8685
const messages = ["bar", "foo"]
8786
pull.bind(address, err => {
8887
if (err) {
@@ -108,12 +107,10 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
108107
}, 15)
109108
})
110109

111-
it("should emit messages after resume", async function (done) {
110+
it("should emit messages after resume", function (done) {
112111
const push = zmq.socket("push")
113112
const pull = zmq.socket("pull")
114113

115-
const address = await uniqAddress(proto)
116-
117114
let n = 0
118115

119116
function checkNoMessages(msg: string) {

test/unit/compat/socket-req-rep-test.ts

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,15 @@ import {testProtos, uniqAddress} from "../helpers"
55
if (process.env.INCLUDE_COMPAT_TESTS) {
66
for (const proto of testProtos("tcp", "inproc")) {
77
describe(`compat socket with ${proto} req-rep`, function () {
8-
it("should support req-rep", async function (done) {
8+
let address: string
9+
beforeEach(async () => {
10+
address = await uniqAddress(proto)
11+
})
12+
13+
it("should support req-rep", function (done) {
914
const rep = zmq.socket("rep")
1015
const req = zmq.socket("req")
1116

12-
const address = await uniqAddress(proto)
13-
1417
rep.on("message", function (msg: string) {
1518
assert.instanceOf(msg, Buffer)
1619
assert.equal(msg.toString(), "hello")
@@ -33,11 +36,11 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
3336
})
3437
})
3538

36-
it("should support multiple", function (done) {
37-
const n = 5
38-
39-
for (let i = 0; i < n; i++) {
40-
;(async function (n) {
39+
it("should support multiple", function () {
40+
return new Promise<void>(async resolve => {
41+
const n = 5
42+
for (let i = 0; i < n; i++) {
43+
let n = i
4144
const rep = zmq.socket("rep")
4245
const req = zmq.socket("req")
4346

@@ -61,20 +64,18 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
6164
req.close()
6265
rep.close()
6366
if (!--n) {
64-
done()
67+
resolve()
6568
}
6669
})
6770
})
68-
})(i)
69-
}
71+
}
72+
})
7073
})
7174

72-
it("should support a burst", async function (done) {
75+
it("should support a burst", function (done) {
7376
const rep = zmq.socket("rep")
7477
const req = zmq.socket("req")
7578

76-
const address = await uniqAddress(proto)
77-
7879
const n = 10
7980

8081
rep.on("message", function (msg) {

test/unit/compat/socket-router-test.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ import {testProtos, uniqAddress} from "../helpers"
55
if (process.env.INCLUDE_COMPAT_TESTS) {
66
for (const proto of testProtos("tcp", "inproc")) {
77
describe(`compat socket with ${proto} router`, function () {
8+
let address: string
9+
beforeEach(async () => {
10+
address = await uniqAddress(proto)
11+
})
12+
813
it("should handle unroutable messages", function (done) {
914
let complete = 0
1015

@@ -74,15 +79,13 @@ if (process.env.INCLUDE_COMPAT_TESTS) {
7479
}
7580
})
7681

77-
it("should handle router-dealer message bursts", async function (done) {
82+
it("should handle router-dealer message bursts", function (done) {
7883
// tests https://github.com/JustinTulloss/zeromq.node/issues/523
7984
// based on https://gist.github.com/messa/862638ab44ca65f712fe4d6ef79aeb67
8085

8186
const router = zmq.socket("router")
8287
const dealer = zmq.socket("dealer")
8388

84-
const address = await uniqAddress(proto)
85-
8689
const expected = 1000
8790
let counted = 0
8891

0 commit comments

Comments
 (0)