aedes 0.51.2 → 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.github/actions/sticky-pr-comment/action.yml +55 -0
- package/.github/workflows/benchmark-compare-serial.yml +60 -0
- package/.github/workflows/ci.yml +12 -17
- package/.release-it.json +18 -0
- package/.taprc +15 -6
- package/README.md +6 -4
- package/aedes.d.ts +0 -6
- package/aedes.js +270 -238
- package/benchmarks/README.md +33 -0
- package/benchmarks/pingpong.js +94 -25
- package/benchmarks/receiver.js +77 -0
- package/benchmarks/report.js +150 -0
- package/benchmarks/runBenchmarks.js +118 -0
- package/benchmarks/sender.js +86 -0
- package/benchmarks/server.js +19 -18
- package/checkVersion.js +20 -0
- package/docs/Aedes.md +66 -8
- package/docs/Client.md +3 -4
- package/docs/Examples.md +39 -22
- package/docs/MIGRATION.md +50 -0
- package/eslint.config.js +8 -0
- package/example.js +51 -40
- package/examples/clusters/index.js +28 -23
- package/examples/clusters/package.json +10 -6
- package/lib/client.js +405 -306
- package/lib/handlers/connect.js +42 -38
- package/lib/handlers/index.js +9 -11
- package/lib/handlers/ping.js +2 -3
- package/lib/handlers/puback.js +5 -5
- package/lib/handlers/publish.js +29 -14
- package/lib/handlers/pubrec.js +9 -17
- package/lib/handlers/pubrel.js +34 -25
- package/lib/handlers/subscribe.js +54 -43
- package/lib/handlers/unsubscribe.js +16 -19
- package/lib/qos-packet.js +14 -17
- package/lib/utils.js +5 -12
- package/lib/write.js +4 -5
- package/package.json +134 -136
- package/test/auth.js +468 -804
- package/test/basic.js +613 -575
- package/test/bridge.js +44 -40
- package/test/client-pub-sub.js +531 -504
- package/test/close_socket_by_other_party.js +137 -102
- package/test/connect.js +487 -484
- package/test/drain-timeout.js +593 -0
- package/test/drain-toxiproxy.js +620 -0
- package/test/events.js +174 -144
- package/test/helper.js +351 -73
- package/test/keep-alive.js +40 -67
- package/test/meta.js +257 -210
- package/test/not-blocking.js +93 -197
- package/test/qos1.js +464 -554
- package/test/qos2.js +308 -393
- package/test/regr-21.js +39 -21
- package/test/require.cjs +22 -0
- package/test/retain.js +349 -398
- package/test/topics.js +176 -183
- package/test/types/aedes.test-d.ts +4 -8
- package/test/will.js +310 -428
- package/types/instance.d.ts +40 -35
- package/types/packet.d.ts +10 -10
- package/.coveralls.yml +0 -1
- package/benchmarks/bombing.js +0 -34
- package/benchmarks/bombingQoS1.js +0 -36
- package/benchmarks/throughputCounter.js +0 -23
- package/benchmarks/throughputCounterQoS1.js +0 -33
- package/types/.eslintrc.json +0 -47
package/test/meta.js
CHANGED
|
@@ -1,318 +1,360 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
1
|
+
import { test } from 'node:test'
|
|
2
|
+
import { once } from 'node:events'
|
|
3
|
+
import {
|
|
4
|
+
connect,
|
|
5
|
+
createAndConnect,
|
|
6
|
+
delay,
|
|
7
|
+
nextPacket,
|
|
8
|
+
setup,
|
|
9
|
+
subscribe,
|
|
10
|
+
withTimeout
|
|
11
|
+
} from './helper.js'
|
|
12
|
+
import { Aedes } from '../aedes.js'
|
|
13
|
+
import pkg from '../package.json' with { type: 'json' }
|
|
14
|
+
const version = pkg.version
|
|
15
|
+
|
|
16
|
+
test('count connected clients', async (t) => {
|
|
8
17
|
t.plan(4)
|
|
9
18
|
|
|
10
|
-
const broker =
|
|
11
|
-
t.
|
|
12
|
-
|
|
13
|
-
t.equal(broker.connectedClients, 0, 'no connected clients')
|
|
19
|
+
const broker = await Aedes.createBroker()
|
|
20
|
+
t.after(() => broker.close())
|
|
21
|
+
t.assert.equal(broker.connectedClients, 0, 'no connected clients')
|
|
14
22
|
|
|
15
|
-
connect(setup(broker), {
|
|
16
|
-
|
|
17
|
-
t.equal(broker.connectedClients, 1, 'one connected clients')
|
|
23
|
+
await connect(setup(broker), { autoClientId: true })
|
|
24
|
+
t.assert.equal(broker.connectedClients, 1, 'one connected clients')
|
|
18
25
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
26
|
+
const last = setup(broker)
|
|
27
|
+
await connect(last, { autoClientId: true })
|
|
28
|
+
t.assert.equal(broker.connectedClients, 2, 'two connected clients')
|
|
22
29
|
|
|
23
|
-
|
|
30
|
+
last.conn.destroy()
|
|
24
31
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
})
|
|
31
|
-
})
|
|
32
|
+
// needed because destroy() will do the trick before
|
|
33
|
+
// the next tick
|
|
34
|
+
await delay(0)
|
|
35
|
+
t.assert.equal(broker.connectedClients, 1, 'one connected clients')
|
|
32
36
|
})
|
|
33
37
|
|
|
34
|
-
test('call published method',
|
|
38
|
+
test('call published method', async (t) => {
|
|
35
39
|
t.plan(4)
|
|
36
40
|
|
|
37
|
-
const broker =
|
|
38
|
-
t.
|
|
41
|
+
const broker = await Aedes.createBroker()
|
|
42
|
+
t.after(() => broker.close())
|
|
39
43
|
|
|
40
|
-
broker.published =
|
|
41
|
-
t.equal(packet.topic, 'hello', 'topic matches')
|
|
42
|
-
t.equal(packet.payload.toString(), 'world', 'payload matches')
|
|
43
|
-
t.equal(client, null, 'no client')
|
|
44
|
+
broker.published = (packet, client, done) => {
|
|
45
|
+
t.assert.equal(packet.topic, 'hello', 'topic matches')
|
|
46
|
+
t.assert.equal(packet.payload.toString(), 'world', 'payload matches')
|
|
47
|
+
t.assert.equal(client, null, 'no client')
|
|
44
48
|
done()
|
|
45
49
|
}
|
|
46
50
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
51
|
+
await new Promise((resolve) => {
|
|
52
|
+
broker.publish({
|
|
53
|
+
topic: 'hello',
|
|
54
|
+
payload: Buffer.from('world')
|
|
55
|
+
}, err => {
|
|
56
|
+
t.assert.ok(!err, 'no error')
|
|
57
|
+
resolve()
|
|
58
|
+
})
|
|
52
59
|
})
|
|
53
60
|
})
|
|
54
61
|
|
|
55
|
-
test('call published method with client',
|
|
62
|
+
test('call published method with client', async (t) => {
|
|
56
63
|
t.plan(4)
|
|
57
64
|
|
|
58
|
-
const
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
65
|
+
const s = await createAndConnect(t)
|
|
66
|
+
|
|
67
|
+
const checkPublished = new Promise(resolve => {
|
|
68
|
+
s.broker.published = (packet, client, done) => {
|
|
69
|
+
// for internal messages, client will be null
|
|
70
|
+
if (client) {
|
|
71
|
+
t.assert.equal(packet.topic, 'hello', 'topic matches')
|
|
72
|
+
t.assert.equal(packet.payload.toString(), 'world', 'payload matches')
|
|
73
|
+
t.assert.equal(packet.qos, 1)
|
|
74
|
+
t.assert.equal(packet.messageId, 42)
|
|
75
|
+
done()
|
|
76
|
+
resolve()
|
|
77
|
+
}
|
|
69
78
|
}
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
const s = connect(setup(broker))
|
|
73
|
-
|
|
74
|
-
s.inStream.write({
|
|
75
|
-
cmd: 'publish',
|
|
76
|
-
topic: 'hello',
|
|
77
|
-
payload: Buffer.from('world'),
|
|
78
|
-
qos: 1,
|
|
79
|
-
messageId: 42
|
|
80
79
|
})
|
|
80
|
+
|
|
81
|
+
const sendPacket = () => {
|
|
82
|
+
s.inStream.write({
|
|
83
|
+
cmd: 'publish',
|
|
84
|
+
topic: 'hello',
|
|
85
|
+
payload: Buffer.from('world'),
|
|
86
|
+
qos: 1,
|
|
87
|
+
messageId: 42
|
|
88
|
+
})
|
|
89
|
+
}
|
|
90
|
+
// run parallel
|
|
91
|
+
await Promise.all([checkPublished, sendPacket()])
|
|
81
92
|
})
|
|
82
93
|
|
|
83
|
-
test('emit publish event with client - QoS 0',
|
|
84
|
-
t.plan(
|
|
94
|
+
test('emit publish event with client - QoS 0', async (t) => {
|
|
95
|
+
t.plan(4)
|
|
85
96
|
|
|
86
|
-
const
|
|
87
|
-
t.teardown(broker.close.bind(broker))
|
|
97
|
+
const s = await createAndConnect(t)
|
|
88
98
|
|
|
89
|
-
|
|
99
|
+
const checkPublished = async () => {
|
|
100
|
+
const [packet, client] = await once(s.broker, 'publish')
|
|
90
101
|
// for internal messages, client will be null
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
})
|
|
97
|
-
|
|
98
|
-
const s = connect(setup(broker))
|
|
102
|
+
t.assert.ok(client, 'client is present')
|
|
103
|
+
t.assert.equal(packet.qos, 0)
|
|
104
|
+
t.assert.equal(packet.topic, 'hello', 'topic matches')
|
|
105
|
+
t.assert.equal(packet.payload.toString(), 'world', 'payload matches')
|
|
106
|
+
}
|
|
99
107
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
108
|
+
const sendPacket = () => {
|
|
109
|
+
s.inStream.write({
|
|
110
|
+
cmd: 'publish',
|
|
111
|
+
topic: 'hello',
|
|
112
|
+
payload: Buffer.from('world'),
|
|
113
|
+
qos: 0
|
|
114
|
+
})
|
|
115
|
+
}
|
|
116
|
+
await Promise.all([checkPublished(), sendPacket()])
|
|
106
117
|
})
|
|
107
118
|
|
|
108
|
-
test('emit publish event with client - QoS 1',
|
|
109
|
-
t.plan(
|
|
119
|
+
test('emit publish event with client - QoS 1', async (t) => {
|
|
120
|
+
t.plan(5)
|
|
110
121
|
|
|
111
|
-
const
|
|
112
|
-
t.teardown(broker.close.bind(broker))
|
|
122
|
+
const s = await createAndConnect(t)
|
|
113
123
|
|
|
114
|
-
|
|
124
|
+
const checkPublished = async () => {
|
|
125
|
+
const [packet, client] = await once(s.broker, 'publish')
|
|
115
126
|
// for internal messages, client will be null
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
})
|
|
123
|
-
|
|
124
|
-
const s = connect(setup(broker))
|
|
127
|
+
t.assert.ok(client, 'client is present')
|
|
128
|
+
t.assert.equal(packet.messageId, 42)
|
|
129
|
+
t.assert.equal(packet.qos, 1)
|
|
130
|
+
t.assert.equal(packet.topic, 'hello', 'topic matches')
|
|
131
|
+
t.assert.equal(packet.payload.toString(), 'world', 'payload matches')
|
|
132
|
+
}
|
|
125
133
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
134
|
+
const sendPacket = () => {
|
|
135
|
+
s.inStream.write({
|
|
136
|
+
cmd: 'publish',
|
|
137
|
+
topic: 'hello',
|
|
138
|
+
payload: Buffer.from('world'),
|
|
139
|
+
qos: 1,
|
|
140
|
+
messageId: 42
|
|
141
|
+
})
|
|
142
|
+
}
|
|
143
|
+
await Promise.all([checkPublished(), sendPacket()])
|
|
133
144
|
})
|
|
134
145
|
|
|
135
|
-
test('emit subscribe event',
|
|
146
|
+
test('emit subscribe event', async (t) => {
|
|
136
147
|
t.plan(6)
|
|
137
148
|
|
|
138
|
-
const
|
|
139
|
-
t.teardown(broker.close.bind(broker))
|
|
140
|
-
|
|
141
|
-
const s = connect(setup(broker), { clientId: 'abcde' })
|
|
149
|
+
const s = await createAndConnect(t, { connect: { clientId: 'abcde' } })
|
|
142
150
|
|
|
143
|
-
|
|
144
|
-
|
|
151
|
+
const checkSubscribe = async () => {
|
|
152
|
+
const [subscriptions, client] = await once(s.broker, 'subscribe')
|
|
153
|
+
t.assert.deepEqual(subscriptions, [{
|
|
145
154
|
topic: 'hello',
|
|
146
155
|
qos: 0
|
|
147
156
|
}], 'topic matches')
|
|
148
|
-
t.equal(
|
|
149
|
-
|
|
157
|
+
t.assert.equal(subscriptions[0].qos, 0)
|
|
158
|
+
t.assert.equal(client.id, 'abcde', 'client matches')
|
|
159
|
+
}
|
|
150
160
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
161
|
+
// run parallel
|
|
162
|
+
await Promise.all([
|
|
163
|
+
checkSubscribe(),
|
|
164
|
+
subscribe(t, s, 'hello', 0)
|
|
165
|
+
])
|
|
154
166
|
})
|
|
155
167
|
|
|
156
|
-
test('emit subscribe event if unrecognized params in subscribe packet structure',
|
|
168
|
+
test('emit subscribe event if unrecognized params in subscribe packet structure', async (t) => {
|
|
157
169
|
t.plan(3)
|
|
158
170
|
|
|
159
|
-
const
|
|
160
|
-
t.teardown(broker.close.bind(broker))
|
|
171
|
+
const s = await createAndConnect(t)
|
|
161
172
|
|
|
162
|
-
const s = noError(connect(setup(broker)))
|
|
163
173
|
const subs = [{ topic: 'hello', qos: 0 }]
|
|
164
174
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
t.
|
|
168
|
-
|
|
175
|
+
const checkSubscribe = async () => {
|
|
176
|
+
const [subscriptions, client] = await once(s.broker, 'subscribe')
|
|
177
|
+
t.assert.equal(subscriptions, subs)
|
|
178
|
+
t.assert.deepEqual(client, s.client)
|
|
179
|
+
}
|
|
169
180
|
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
181
|
+
const doSubscribe = new Promise((resolve) => {
|
|
182
|
+
s.client.subscribe({
|
|
183
|
+
subscriptions: subs,
|
|
184
|
+
close: true
|
|
185
|
+
}, err => {
|
|
186
|
+
t.assert.ok(!err)
|
|
187
|
+
resolve()
|
|
188
|
+
})
|
|
175
189
|
})
|
|
176
|
-
})
|
|
177
190
|
|
|
178
|
-
|
|
179
|
-
|
|
191
|
+
// run parallel
|
|
192
|
+
await Promise.all([
|
|
193
|
+
checkSubscribe(),
|
|
194
|
+
doSubscribe
|
|
195
|
+
])
|
|
196
|
+
})
|
|
180
197
|
|
|
181
|
-
|
|
182
|
-
t.
|
|
198
|
+
test('emit unsubscribe event', async (t) => {
|
|
199
|
+
t.plan(5)
|
|
183
200
|
|
|
184
|
-
const s =
|
|
201
|
+
const s = await createAndConnect(t, { connect: { clean: true, clientId: 'abcde' } })
|
|
185
202
|
|
|
186
|
-
|
|
187
|
-
|
|
203
|
+
const checkUnsubscribe = async () => {
|
|
204
|
+
const [unsubscriptions, client] = await once(s.broker, 'unsubscribe')
|
|
205
|
+
t.assert.deepEqual(unsubscriptions, [
|
|
188
206
|
'hello'
|
|
189
207
|
], 'unsubscription matches')
|
|
190
|
-
t.equal(client.id, 'abcde', 'client matches')
|
|
191
|
-
}
|
|
208
|
+
t.assert.equal(client.id, 'abcde', 'client matches')
|
|
209
|
+
}
|
|
192
210
|
|
|
193
|
-
|
|
211
|
+
const doUnsubscribe = async () => {
|
|
212
|
+
await subscribe(t, s, 'hello', 0)
|
|
194
213
|
s.inStream.write({
|
|
195
214
|
cmd: 'unsubscribe',
|
|
196
215
|
messageId: 43,
|
|
197
216
|
unsubscriptions: ['hello']
|
|
198
217
|
})
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
218
|
+
}
|
|
219
|
+
// run parallel
|
|
220
|
+
await Promise.all([
|
|
221
|
+
checkUnsubscribe(),
|
|
222
|
+
doUnsubscribe()
|
|
223
|
+
])
|
|
204
224
|
})
|
|
205
225
|
|
|
206
|
-
|
|
226
|
+
// TODO unsubscribe event is not emitted
|
|
227
|
+
// remove { skip: true} once this is fixed
|
|
228
|
+
test('emit unsubscribe event if unrecognized params in unsubscribe packet structure', { skip: true }, async (t) => {
|
|
207
229
|
t.plan(3)
|
|
208
230
|
|
|
209
|
-
const
|
|
210
|
-
t.teardown(broker.close.bind(broker))
|
|
231
|
+
const s = await createAndConnect(t)
|
|
211
232
|
|
|
212
|
-
const s = noError(connect(setup(broker)))
|
|
213
233
|
const unsubs = [{ topic: 'hello', qos: 0 }]
|
|
214
234
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
t.
|
|
218
|
-
|
|
235
|
+
const checkUnsubscribe = async () => {
|
|
236
|
+
const [unsubscriptions, client] = await once(s.broker, 'unsubscribe')
|
|
237
|
+
t.assert.equal(unsubscriptions, unsubs)
|
|
238
|
+
t.assert.deepEqual(client, s.client)
|
|
239
|
+
}
|
|
219
240
|
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
241
|
+
const doUnsubscribe = new Promise((resolve) => {
|
|
242
|
+
s.client.unsubscribe({
|
|
243
|
+
unsubscriptions: unsubs,
|
|
244
|
+
close: true
|
|
245
|
+
}, err => {
|
|
246
|
+
t.assert.ok(!err)
|
|
247
|
+
resolve()
|
|
248
|
+
})
|
|
225
249
|
})
|
|
226
|
-
})
|
|
227
250
|
|
|
228
|
-
|
|
229
|
-
|
|
251
|
+
// run parallel
|
|
252
|
+
await Promise.all([
|
|
253
|
+
checkUnsubscribe(),
|
|
254
|
+
doUnsubscribe
|
|
255
|
+
])
|
|
256
|
+
})
|
|
230
257
|
|
|
231
|
-
|
|
232
|
-
|
|
258
|
+
// TODO: Aedes does emit an unsubscribe event on client close
|
|
259
|
+
// remove { skip: true} once this is fixed
|
|
260
|
+
test('dont emit unsubscribe event on client close', { skip: true }, async (t) => {
|
|
261
|
+
t.plan(5)
|
|
233
262
|
|
|
234
|
-
const s =
|
|
263
|
+
const s = await createAndConnect(t, { connect: { clientId: 'abcde' } })
|
|
235
264
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
265
|
+
const checkUnsubscribe = async () => {
|
|
266
|
+
const [result] = await withTimeout(once(s.broker, 'unsubscribe'), 100, ['timeout'])
|
|
267
|
+
t.assert.deepEqual(result, 'timeout', 'unsubscribe should not be emitted')
|
|
268
|
+
}
|
|
239
269
|
|
|
240
|
-
|
|
270
|
+
const doSubscribe = async () => {
|
|
271
|
+
await subscribe(t, s, 'hello', 0)
|
|
241
272
|
s.inStream.end({
|
|
242
273
|
cmd: 'disconnect'
|
|
243
274
|
})
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
275
|
+
const packet = await nextPacket(s)
|
|
276
|
+
t.assert.equal(packet, null, 'no packet')
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// run parallel
|
|
280
|
+
await Promise.all([
|
|
281
|
+
checkUnsubscribe(),
|
|
282
|
+
doSubscribe()
|
|
283
|
+
])
|
|
248
284
|
})
|
|
249
285
|
|
|
250
|
-
test('emit clientDisconnect event',
|
|
286
|
+
test('emit clientDisconnect event', async (t) => {
|
|
251
287
|
t.plan(1)
|
|
252
288
|
|
|
253
|
-
const
|
|
254
|
-
t.teardown(broker.close.bind(broker))
|
|
289
|
+
const s = await createAndConnect(t, { connect: { clientId: 'abcde' } })
|
|
255
290
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
291
|
+
const checkDisconnect = async () => {
|
|
292
|
+
const [client] = await once(s.broker, 'clientDisconnect')
|
|
293
|
+
t.assert.equal(client.id, 'abcde', 'client matches')
|
|
294
|
+
}
|
|
259
295
|
|
|
260
|
-
const
|
|
296
|
+
const disconnect = () => {
|
|
297
|
+
s.inStream.end({
|
|
298
|
+
cmd: 'disconnect'
|
|
299
|
+
})
|
|
300
|
+
}
|
|
261
301
|
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
302
|
+
// run parallel
|
|
303
|
+
await Promise.all([
|
|
304
|
+
checkDisconnect(),
|
|
305
|
+
disconnect()
|
|
306
|
+
])
|
|
266
307
|
})
|
|
267
308
|
|
|
268
|
-
test('emits client',
|
|
309
|
+
test('emits client', async (t) => {
|
|
269
310
|
t.plan(1)
|
|
270
311
|
|
|
271
|
-
const broker =
|
|
272
|
-
t.
|
|
312
|
+
const broker = await Aedes.createBroker()
|
|
313
|
+
t.after(() => broker.close())
|
|
273
314
|
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
315
|
+
const checkClient = async () => {
|
|
316
|
+
const [client] = await once(broker, 'client')
|
|
317
|
+
t.assert.equal(client.id, 'abcde', 'client matches')
|
|
318
|
+
}
|
|
277
319
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
320
|
+
const doConnect = async () => {
|
|
321
|
+
const s = setup(broker)
|
|
322
|
+
await connect(s, { connect: { clientId: 'abcde' } })
|
|
323
|
+
}
|
|
324
|
+
// run parallel
|
|
325
|
+
await Promise.all([
|
|
326
|
+
checkClient(),
|
|
327
|
+
doConnect()
|
|
328
|
+
])
|
|
281
329
|
})
|
|
282
330
|
|
|
283
|
-
test('get aedes version',
|
|
331
|
+
test('get aedes version', async (t) => {
|
|
284
332
|
t.plan(1)
|
|
285
333
|
|
|
286
|
-
const broker =
|
|
287
|
-
t.
|
|
334
|
+
const broker = await Aedes.createBroker()
|
|
335
|
+
t.after(() => broker.close())
|
|
288
336
|
|
|
289
|
-
t.equal(broker.version,
|
|
337
|
+
t.assert.equal(broker.version, version)
|
|
290
338
|
})
|
|
291
339
|
|
|
292
|
-
test('connect and connackSent event', { timeout: 50 },
|
|
340
|
+
test('connect and connackSent event', { timeout: 50 }, async (t) => {
|
|
293
341
|
t.plan(3)
|
|
294
342
|
|
|
295
|
-
const
|
|
296
|
-
|
|
343
|
+
const broker = await Aedes.createBroker()
|
|
344
|
+
const s = setup(broker)
|
|
345
|
+
t.after(() => broker.close())
|
|
297
346
|
|
|
298
347
|
const clientId = 'my-client'
|
|
299
348
|
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
t.equal(
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
s.inStream.write({
|
|
306
|
-
cmd: 'connect',
|
|
307
|
-
protocolId: 'MQTT',
|
|
308
|
-
protocolVersion: 4,
|
|
309
|
-
clean: true,
|
|
310
|
-
clientId,
|
|
311
|
-
keepalive: 0
|
|
312
|
-
})
|
|
349
|
+
const checkConnack = async () => {
|
|
350
|
+
const [packet, client] = await once(s.broker, 'connackSent')
|
|
351
|
+
t.assert.equal(packet.returnCode, 0)
|
|
352
|
+
t.assert.equal(client.id, clientId, 'connackSent event and clientId matches')
|
|
353
|
+
}
|
|
313
354
|
|
|
314
|
-
|
|
315
|
-
|
|
355
|
+
const doConnect = async () => {
|
|
356
|
+
const packet = await connect(s, { connect: { clientId, clean: true, keepalive: 0 } })
|
|
357
|
+
t.assert.deepEqual(structuredClone(packet), {
|
|
316
358
|
cmd: 'connack',
|
|
317
359
|
returnCode: 0,
|
|
318
360
|
length: 2,
|
|
@@ -323,5 +365,10 @@ test('connect and connackSent event', { timeout: 50 }, function (t) {
|
|
|
323
365
|
payload: null,
|
|
324
366
|
sessionPresent: false
|
|
325
367
|
}, 'successful connack')
|
|
326
|
-
}
|
|
368
|
+
}
|
|
369
|
+
// run parallel
|
|
370
|
+
await Promise.all([
|
|
371
|
+
checkConnack(),
|
|
372
|
+
doConnect()
|
|
373
|
+
])
|
|
327
374
|
})
|