@libp2p/interface-compliance-tests 6.5.0-8484de8a2 → 6.5.0-87bc8d4fb

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 (131) hide show
  1. package/dist/src/connection-encryption/index.d.ts.map +1 -1
  2. package/dist/src/connection-encryption/index.js +15 -24
  3. package/dist/src/connection-encryption/index.js.map +1 -1
  4. package/dist/src/connection-encryption/utils/index.d.ts +3 -0
  5. package/dist/src/connection-encryption/utils/index.d.ts.map +1 -0
  6. package/dist/src/connection-encryption/utils/index.js +21 -0
  7. package/dist/src/connection-encryption/utils/index.js.map +1 -0
  8. package/dist/src/matchers.d.ts +12 -0
  9. package/dist/src/matchers.d.ts.map +1 -0
  10. package/dist/src/matchers.js +14 -0
  11. package/dist/src/matchers.js.map +1 -0
  12. package/dist/src/mocks/connection-manager.d.ts +27 -0
  13. package/dist/src/mocks/connection-manager.d.ts.map +1 -0
  14. package/dist/src/mocks/connection-manager.js +147 -0
  15. package/dist/src/mocks/connection-manager.js.map +1 -0
  16. package/dist/src/mocks/connection.d.ts +41 -0
  17. package/dist/src/mocks/connection.d.ts.map +1 -0
  18. package/dist/src/mocks/connection.js +236 -0
  19. package/dist/src/mocks/connection.js.map +1 -0
  20. package/dist/src/mocks/duplex.d.ts +4 -0
  21. package/dist/src/mocks/duplex.d.ts.map +1 -0
  22. package/dist/src/mocks/duplex.js +9 -0
  23. package/dist/src/mocks/duplex.js.map +1 -0
  24. package/dist/src/mocks/index.d.ts +12 -0
  25. package/dist/src/mocks/index.d.ts.map +1 -0
  26. package/dist/src/mocks/index.js +8 -0
  27. package/dist/src/mocks/index.js.map +1 -0
  28. package/dist/src/mocks/multiaddr-connection.d.ts +17 -0
  29. package/dist/src/mocks/multiaddr-connection.d.ts.map +1 -0
  30. package/dist/src/mocks/multiaddr-connection.js +64 -0
  31. package/dist/src/mocks/multiaddr-connection.js.map +1 -0
  32. package/dist/src/mocks/muxer.d.ts +36 -0
  33. package/dist/src/mocks/muxer.d.ts.map +1 -0
  34. package/dist/src/mocks/muxer.js +234 -0
  35. package/dist/src/mocks/muxer.js.map +1 -0
  36. package/dist/src/mocks/registrar.d.ts +16 -0
  37. package/dist/src/mocks/registrar.d.ts.map +1 -0
  38. package/dist/src/mocks/registrar.js +66 -0
  39. package/dist/src/mocks/registrar.js.map +1 -0
  40. package/dist/src/mocks/upgrader.d.ts +9 -0
  41. package/dist/src/mocks/upgrader.d.ts.map +1 -0
  42. package/dist/src/mocks/upgrader.js +46 -0
  43. package/dist/src/mocks/upgrader.js.map +1 -0
  44. package/dist/src/pubsub/api.d.ts +6 -0
  45. package/dist/src/pubsub/api.d.ts.map +1 -0
  46. package/dist/src/pubsub/api.js +88 -0
  47. package/dist/src/pubsub/api.js.map +1 -0
  48. package/dist/src/pubsub/connection-handlers.d.ts +6 -0
  49. package/dist/src/pubsub/connection-handlers.d.ts.map +1 -0
  50. package/dist/src/pubsub/connection-handlers.js +329 -0
  51. package/dist/src/pubsub/connection-handlers.js.map +1 -0
  52. package/dist/src/pubsub/emit-self.d.ts +6 -0
  53. package/dist/src/pubsub/emit-self.d.ts.map +1 -0
  54. package/dist/src/pubsub/emit-self.js +80 -0
  55. package/dist/src/pubsub/emit-self.js.map +1 -0
  56. package/dist/src/pubsub/index.d.ts +18 -0
  57. package/dist/src/pubsub/index.d.ts.map +1 -0
  58. package/dist/src/pubsub/index.js +17 -0
  59. package/dist/src/pubsub/index.js.map +1 -0
  60. package/dist/src/pubsub/messages.d.ts +6 -0
  61. package/dist/src/pubsub/messages.d.ts.map +1 -0
  62. package/dist/src/pubsub/messages.js +48 -0
  63. package/dist/src/pubsub/messages.js.map +1 -0
  64. package/dist/src/pubsub/multiple-nodes.d.ts +6 -0
  65. package/dist/src/pubsub/multiple-nodes.d.ts.map +1 -0
  66. package/dist/src/pubsub/multiple-nodes.js +350 -0
  67. package/dist/src/pubsub/multiple-nodes.js.map +1 -0
  68. package/dist/src/pubsub/two-nodes.d.ts +6 -0
  69. package/dist/src/pubsub/two-nodes.d.ts.map +1 -0
  70. package/dist/src/pubsub/two-nodes.js +216 -0
  71. package/dist/src/pubsub/two-nodes.js.map +1 -0
  72. package/dist/src/pubsub/utils.d.ts +5 -0
  73. package/dist/src/pubsub/utils.d.ts.map +1 -0
  74. package/dist/src/pubsub/utils.js +27 -0
  75. package/dist/src/pubsub/utils.js.map +1 -0
  76. package/dist/src/stream-muxer/base-test.d.ts.map +1 -1
  77. package/dist/src/stream-muxer/base-test.js +345 -62
  78. package/dist/src/stream-muxer/base-test.js.map +1 -1
  79. package/dist/src/stream-muxer/close-test.d.ts.map +1 -1
  80. package/dist/src/stream-muxer/close-test.js +320 -253
  81. package/dist/src/stream-muxer/close-test.js.map +1 -1
  82. package/dist/src/stream-muxer/index.js +2 -2
  83. package/dist/src/stream-muxer/index.js.map +1 -1
  84. package/dist/src/stream-muxer/{stream-test.d.ts → mega-stress-test.d.ts} +2 -2
  85. package/dist/src/stream-muxer/mega-stress-test.d.ts.map +1 -0
  86. package/dist/src/stream-muxer/mega-stress-test.js +11 -0
  87. package/dist/src/stream-muxer/mega-stress-test.js.map +1 -0
  88. package/dist/src/stream-muxer/spawner.d.ts +4 -0
  89. package/dist/src/stream-muxer/spawner.d.ts.map +1 -0
  90. package/dist/src/stream-muxer/spawner.js +39 -0
  91. package/dist/src/stream-muxer/spawner.js.map +1 -0
  92. package/dist/src/stream-muxer/stress-test.d.ts.map +1 -1
  93. package/dist/src/stream-muxer/stress-test.js +16 -70
  94. package/dist/src/stream-muxer/stress-test.js.map +1 -1
  95. package/dist/src/transport/index.d.ts.map +1 -1
  96. package/dist/src/transport/index.js +203 -232
  97. package/dist/src/transport/index.js.map +1 -1
  98. package/dist/src/transport/utils.js +2 -2
  99. package/dist/src/transport/utils.js.map +1 -1
  100. package/package.json +51 -23
  101. package/src/connection-encryption/index.ts +20 -27
  102. package/src/connection-encryption/utils/index.ts +27 -0
  103. package/src/matchers.ts +18 -0
  104. package/src/mocks/connection-manager.ts +216 -0
  105. package/src/mocks/connection.ts +309 -0
  106. package/src/mocks/duplex.ts +11 -0
  107. package/src/mocks/index.ts +11 -0
  108. package/src/mocks/multiaddr-connection.ts +80 -0
  109. package/src/mocks/muxer.ts +331 -0
  110. package/src/mocks/registrar.ts +86 -0
  111. package/src/mocks/upgrader.ts +65 -0
  112. package/src/pubsub/api.ts +116 -0
  113. package/src/pubsub/connection-handlers.ts +413 -0
  114. package/src/pubsub/emit-self.ts +99 -0
  115. package/src/pubsub/index.ts +34 -0
  116. package/src/pubsub/messages.ts +59 -0
  117. package/src/pubsub/multiple-nodes.ts +440 -0
  118. package/src/pubsub/two-nodes.ts +272 -0
  119. package/src/pubsub/utils.ts +34 -0
  120. package/src/stream-muxer/base-test.ts +413 -75
  121. package/src/stream-muxer/close-test.ts +343 -304
  122. package/src/stream-muxer/index.ts +2 -2
  123. package/src/stream-muxer/mega-stress-test.ts +14 -0
  124. package/src/stream-muxer/spawner.ts +57 -0
  125. package/src/stream-muxer/stress-test.ts +18 -92
  126. package/src/transport/index.ts +241 -280
  127. package/src/transport/utils.ts +2 -2
  128. package/dist/src/stream-muxer/stream-test.d.ts.map +0 -1
  129. package/dist/src/stream-muxer/stream-test.js +0 -289
  130. package/dist/src/stream-muxer/stream-test.js.map +0 -1
  131. package/src/stream-muxer/stream-test.ts +0 -380
@@ -1,6 +1,6 @@
1
1
  import baseTest from './base-test.js'
2
2
  import closeTest from './close-test.js'
3
- import steamTest from './stream-test.js'
3
+ import megaStressTest from './mega-stress-test.js'
4
4
  import stressTest from './stress-test.js'
5
5
  import type { TestSetup } from '../index.js'
6
6
  import type { StreamMuxerFactory } from '@libp2p/interface'
@@ -9,7 +9,7 @@ export default (common: TestSetup<StreamMuxerFactory>): void => {
9
9
  describe('interface-stream-muxer', () => {
10
10
  baseTest(common)
11
11
  closeTest(common)
12
- steamTest(common)
13
12
  stressTest(common)
13
+ megaStressTest(common)
14
14
  })
15
15
  }
@@ -0,0 +1,14 @@
1
+ import spawn from './spawner.js'
2
+ import type { TestSetup } from '../index.js'
3
+ import type { StreamMuxer, StreamMuxerFactory, StreamMuxerInit } from '@libp2p/interface'
4
+
5
+ export default (common: TestSetup<StreamMuxerFactory>): void => {
6
+ const createMuxer = async (init?: StreamMuxerInit): Promise<StreamMuxer> => {
7
+ const factory = await common.setup()
8
+ return factory.createStreamMuxer(init)
9
+ }
10
+
11
+ describe.skip('mega stress test', function () {
12
+ it('10,000 streams with 10,000 msg', async () => { await spawn(createMuxer, 10000, 10000, 5000) })
13
+ })
14
+ }
@@ -0,0 +1,57 @@
1
+ import { expect } from 'aegir/chai'
2
+ import all from 'it-all'
3
+ import drain from 'it-drain'
4
+ import { duplexPair } from 'it-pair/duplex'
5
+ import { pipe } from 'it-pipe'
6
+ import pLimit from 'p-limit'
7
+ import { Uint8ArrayList } from 'uint8arraylist'
8
+ import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
9
+ import type { StreamMuxer, StreamMuxerInit } from '@libp2p/interface'
10
+
11
+ export default async (createMuxer: (init?: StreamMuxerInit) => Promise<StreamMuxer>, nStreams: number, nMsg: number, limit?: number): Promise<void> => {
12
+ const [dialerSocket, listenerSocket] = duplexPair<Uint8Array | Uint8ArrayList>()
13
+
14
+ const msg = new Uint8ArrayList(uint8ArrayFromString('simple msg'))
15
+
16
+ const listener = await createMuxer({
17
+ direction: 'inbound',
18
+ onIncomingStream: (stream) => {
19
+ void pipe(
20
+ stream,
21
+ drain
22
+ ).then(async () => {
23
+ await stream.close()
24
+ })
25
+ .catch(err => { stream.abort(err) })
26
+ }
27
+ })
28
+ const dialer = await createMuxer({
29
+ direction: 'outbound'
30
+ })
31
+
32
+ void pipe(listenerSocket, listener, listenerSocket)
33
+ void pipe(dialerSocket, dialer, dialerSocket)
34
+
35
+ const spawnStream = async (): Promise<void> => {
36
+ const stream = await dialer.newStream()
37
+ expect(stream).to.exist // eslint-disable-line
38
+
39
+ const res = await pipe(
40
+ (async function * () {
41
+ for (let i = 0; i < nMsg; i++) {
42
+ yield msg
43
+ }
44
+ }()),
45
+ stream,
46
+ async (source) => all(source)
47
+ )
48
+
49
+ expect(res).to.be.eql([])
50
+ }
51
+
52
+ const limiter = pLimit(limit ?? Infinity)
53
+
54
+ await Promise.all(
55
+ Array.from(Array(nStreams), async () => { await limiter(async () => { await spawnStream() }) })
56
+ )
57
+ }
@@ -1,101 +1,27 @@
1
- import { multiaddrConnectionPair, echo } from '@libp2p/utils'
2
- import { expect } from 'aegir/chai'
3
- import { pEvent } from 'p-event'
4
- import { fromString as uint8ArrayFromString } from 'uint8arrays/from-string'
5
- import { toString as uint8ArrayToString } from 'uint8arrays/to-string'
1
+ import spawn from './spawner.js'
6
2
  import type { TestSetup } from '../index.js'
7
- import type { StreamMuxerFactory, StreamMuxer, MultiaddrConnection } from '@libp2p/interface'
8
-
9
- async function * messages (nMsg: number): AsyncGenerator<Uint8Array> {
10
- for (let i = 0; i < nMsg; i++) {
11
- yield uint8ArrayFromString(`message ${i + 1}/${nMsg}`)
12
- }
13
- }
14
-
15
- async function spawn (createMuxer: (maConn: MultiaddrConnection) => Promise<StreamMuxer>, nStreams: number, nMsg: number): Promise<void> {
16
- const [outboundConnection, inboundConnection] = multiaddrConnectionPair()
17
-
18
- const listener = await createMuxer(inboundConnection)
19
- listener.addEventListener('stream', function echoStreamHandler (evt) {
20
- echo(evt.detail)
21
- .catch(err => {
22
- evt.detail.abort(err)
23
- })
24
- })
25
-
26
- const dialer = await createMuxer(outboundConnection)
27
-
28
- const spawnStream = async (): Promise<void> => {
29
- let receivedBytes = 0
30
- let sentBytes = 0
31
-
32
- for await (const buf of messages(nMsg)) {
33
- sentBytes += buf.byteLength
34
- }
35
-
36
- const receivedAllMessagesPromise = Promise.withResolvers<void>()
37
- const outboundStream = await dialer.createStream()
38
-
39
- outboundStream.addEventListener('message', function countMessages (evt) {
40
- receivedBytes += evt.data.byteLength
41
-
42
- outboundStream.log('%s - echoed bytes %d/%d', uint8ArrayToString(evt.data.subarray()), receivedBytes, sentBytes)
43
-
44
- if (receivedBytes === sentBytes) {
45
- outboundStream.log('received all bytes')
46
- receivedAllMessagesPromise.resolve()
47
- }
48
- })
49
-
50
- for await (const buf of messages(nMsg)) {
51
- const sendMore = outboundStream.send(buf)
52
-
53
- if (sendMore === false) {
54
- await pEvent(outboundStream, 'drain', {
55
- rejectionEvents: ['close']
56
- })
57
- }
58
- }
59
-
60
- await receivedAllMessagesPromise.promise
61
- outboundStream.log('sent and received all messages %d/%d', receivedBytes, sentBytes)
62
-
63
- await Promise.all([
64
- pEvent(outboundStream, 'close'),
65
- outboundStream.close()
66
- ])
67
-
68
- expect(receivedBytes).to.equal(sentBytes)
69
- }
70
-
71
- await Promise.all(
72
- Array.from(Array(nStreams), async () => {
73
- await spawnStream()
74
- })
75
- )
76
-
77
- await listener.close()
78
- await dialer.close()
79
- }
3
+ import type { StreamMuxerFactory, StreamMuxerInit, StreamMuxer } from '@libp2p/interface'
80
4
 
81
5
  export default (common: TestSetup<StreamMuxerFactory>): void => {
82
- const createMuxer = async (maConn: MultiaddrConnection): Promise<StreamMuxer> => {
6
+ const createMuxer = async (init?: StreamMuxerInit): Promise<StreamMuxer> => {
83
7
  const factory = await common.setup()
84
- return factory.createStreamMuxer(maConn)
8
+ return factory.createStreamMuxer(init)
85
9
  }
86
10
 
87
- const streams = [1, 10, 100, 1000]
88
- const messages = [1, 10, 100]
89
-
90
11
  describe('stress test', function () {
91
- this.timeout(1_600_000)
92
-
93
- for (let i = 0; i < streams.length; i++) {
94
- for (let j = 0; j < messages.length; j++) {
95
- it(`${streams[i]} stream(s) with ${messages[j]} msg(s)`, async () => {
96
- await spawn(createMuxer, streams[i], messages[j])
97
- })
98
- }
99
- }
12
+ this.timeout(1600000)
13
+
14
+ it('1 stream with 1 msg', async () => { await spawn(createMuxer, 1, 1) })
15
+ it('1 stream with 10 msg', async () => { await spawn(createMuxer, 1, 10) })
16
+ it('1 stream with 100 msg', async () => { await spawn(createMuxer, 1, 100) })
17
+ it('10 streams with 1 msg', async () => { await spawn(createMuxer, 10, 1) })
18
+ it('10 streams with 10 msg', async () => { await spawn(createMuxer, 10, 10) })
19
+ it('10 streams with 100 msg', async () => { await spawn(createMuxer, 10, 100) })
20
+ it('100 streams with 1 msg', async () => { await spawn(createMuxer, 100, 1) })
21
+ it('100 streams with 10 msg', async () => { await spawn(createMuxer, 100, 10) })
22
+ it('100 streams with 100 msg', async () => { await spawn(createMuxer, 100, 100) })
23
+ it('1000 streams with 1 msg', async () => { await spawn(createMuxer, 1000, 1) })
24
+ it('1000 streams with 10 msg', async () => { await spawn(createMuxer, 1000, 10) })
25
+ it('1000 streams with 100 msg', async () => { await spawn(createMuxer, 1000, 100) })
100
26
  })
101
27
  }