aedes 0.51.3 → 1.0.1

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.
Files changed (68) hide show
  1. package/.claude/settings.local.json +12 -0
  2. package/.github/actions/sticky-pr-comment/action.yml +55 -0
  3. package/.github/workflows/benchmark-compare-serial.yml +60 -0
  4. package/.github/workflows/ci.yml +12 -17
  5. package/.release-it.json +18 -0
  6. package/.taprc +15 -6
  7. package/README.md +6 -4
  8. package/aedes.d.ts +0 -6
  9. package/aedes.js +270 -242
  10. package/benchmarks/README.md +33 -0
  11. package/benchmarks/pingpong.js +94 -25
  12. package/benchmarks/receiver.js +77 -0
  13. package/benchmarks/report.js +150 -0
  14. package/benchmarks/runBenchmarks.js +118 -0
  15. package/benchmarks/sender.js +86 -0
  16. package/benchmarks/server.js +19 -18
  17. package/checkVersion.js +20 -0
  18. package/docs/Aedes.md +66 -8
  19. package/docs/Client.md +3 -4
  20. package/docs/Examples.md +39 -22
  21. package/docs/MIGRATION.md +50 -0
  22. package/eslint.config.js +8 -0
  23. package/example.js +51 -40
  24. package/examples/clusters/index.js +28 -23
  25. package/examples/clusters/package.json +10 -6
  26. package/lib/client.js +405 -306
  27. package/lib/handlers/connect.js +42 -38
  28. package/lib/handlers/index.js +9 -11
  29. package/lib/handlers/ping.js +2 -3
  30. package/lib/handlers/puback.js +5 -5
  31. package/lib/handlers/publish.js +29 -14
  32. package/lib/handlers/pubrec.js +9 -17
  33. package/lib/handlers/pubrel.js +34 -25
  34. package/lib/handlers/subscribe.js +47 -43
  35. package/lib/handlers/unsubscribe.js +16 -19
  36. package/lib/qos-packet.js +14 -17
  37. package/lib/utils.js +5 -12
  38. package/lib/write.js +4 -5
  39. package/package.json +139 -136
  40. package/test/auth.js +468 -804
  41. package/test/basic.js +613 -575
  42. package/test/bridge.js +44 -40
  43. package/test/client-pub-sub.js +531 -504
  44. package/test/close_socket_by_other_party.js +137 -102
  45. package/test/connect.js +487 -484
  46. package/test/drain-timeout.js +593 -0
  47. package/test/drain-toxiproxy.js +620 -0
  48. package/test/events.js +173 -145
  49. package/test/helper.js +351 -73
  50. package/test/keep-alive.js +40 -67
  51. package/test/meta.js +257 -210
  52. package/test/not-blocking.js +93 -197
  53. package/test/qos1.js +464 -554
  54. package/test/qos2.js +308 -393
  55. package/test/regr-21.js +39 -21
  56. package/test/require.cjs +22 -0
  57. package/test/retain.js +349 -398
  58. package/test/topics.js +176 -183
  59. package/test/types/aedes.test-d.ts +4 -8
  60. package/test/will.js +310 -428
  61. package/types/instance.d.ts +40 -35
  62. package/types/packet.d.ts +10 -10
  63. package/.coveralls.yml +0 -1
  64. package/benchmarks/bombing.js +0 -34
  65. package/benchmarks/bombingQoS1.js +0 -36
  66. package/benchmarks/throughputCounter.js +0 -23
  67. package/benchmarks/throughputCounterQoS1.js +0 -33
  68. package/types/.eslintrc.json +0 -47
package/test/regr-21.js CHANGED
@@ -1,15 +1,14 @@
1
- 'use strict'
1
+ import { test } from 'node:test'
2
+ import {
3
+ createAndConnect,
4
+ withTimeout
5
+ } from './helper.js'
2
6
 
3
- const { test } = require('tap')
4
- const { setup, connect } = require('./helper')
5
-
6
- test('after an error, outstanding packets are discarded', function (t) {
7
- t.plan(1)
8
-
9
- const s = connect(setup(), {
7
+ test('after an error, outstanding packets are discarded', async (t) => {
8
+ t.plan(2)
9
+ const s = await createAndConnect(t, {
10
10
  keepalive: 1000
11
11
  })
12
- t.teardown(s.broker.close.bind(s.broker))
13
12
 
14
13
  const packet = {
15
14
  cmd: 'publish',
@@ -17,18 +16,37 @@ test('after an error, outstanding packets are discarded', function (t) {
17
16
  payload: 'world'
18
17
  }
19
18
 
20
- s.broker.mq.on('hello', function (msg, cb) {
21
- t.pass('first msg received')
22
- s.inStream.destroy(new Error('something went wrong'))
23
- cb()
24
- setImmediate(() => {
25
- packet.topic = 'foo'
26
- s.inStream.write(packet)
27
- s.inStream.write(packet)
19
+ const checkFoo = async () => {
20
+ const result = await withTimeout(
21
+ new Promise(resolve => {
22
+ s.broker.mq.on('foo', (msg, cb) => {
23
+ resolve('msg received')
24
+ })
25
+ }),
26
+ 100,
27
+ 'timeout'
28
+ )
29
+ t.assert.equal(result, 'timeout', 'no msg received')
30
+ }
31
+
32
+ const processHello = new Promise(resolve => {
33
+ s.broker.mq.on('hello', (msg, cb) => {
34
+ t.assert.ok(true, 'first msg received')
35
+ s.inStream.destroy()
36
+ cb()
37
+ setImmediate(() => {
38
+ packet.topic = 'foo'
39
+ s.inStream.write(packet)
40
+ s.inStream.write(packet)
41
+ resolve()
42
+ })
28
43
  })
29
44
  })
30
- s.broker.mq.on('foo', function (msg, cb) {
31
- t.fail('msg received')
32
- })
33
- s.inStream.write(packet)
45
+
46
+ // run parallel
47
+ await Promise.all([
48
+ checkFoo(),
49
+ processHello,
50
+ s.inStream.write(packet)
51
+ ])
34
52
  })
@@ -0,0 +1,22 @@
1
+ // a test to see if CJS require still works
2
+ const { test } = require('node:test')
3
+ const { Aedes } = require('../aedes.js')
4
+ const defaultExport = require('../aedes.js')
5
+
6
+ test('test Aedes constructor', (t) => {
7
+ t.plan(1)
8
+ const aedes = new Aedes()
9
+ t.assert.equal(aedes instanceof Aedes, true, 'Aedes constructor works')
10
+ })
11
+
12
+ test('test warning on default export', (t) => {
13
+ t.plan(1)
14
+ t.assert.throws(() => defaultExport(), 'received expected error')
15
+ })
16
+
17
+ test('test aedes.createBroker', async (t) => {
18
+ t.plan(1)
19
+ const broker = await Aedes.createBroker()
20
+ t.after(() => broker.close())
21
+ t.assert.ok(true, 'Aedes.createBroker works')
22
+ })