mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-02 18:31:35 +00:00
fix: emit peer:connect after all (#1171)
**Motivation** In lodestar, when we handle "peer:connect" event, we dial the peer which gives another "peer:connect" event and it causes other issues **Motivation** In `onConnect` function, "peer:connect" event should be emitted after we add connection to the `connections` map so that when app dial the peer in "peer:connect" event handler, it uses the same/existing connection
This commit is contained in:
@ -496,9 +496,12 @@ describe('Identify', () => {
|
||||
|
||||
const identityServiceIdentifySpy = sinon.spy(libp2p.identifyService, 'identify')
|
||||
const identityServicePushSpy = sinon.spy(libp2p.identifyService, 'push')
|
||||
|
||||
const connectionPromise = pEvent(libp2p.connectionManager, 'peer:connect')
|
||||
const connection = await libp2p.dial(remoteAddr)
|
||||
|
||||
expect(connection).to.exist()
|
||||
// Wait for connection event to be emitted
|
||||
await connectionPromise
|
||||
|
||||
// Wait for identify to finish
|
||||
await identityServiceIdentifySpy.firstCall.returnValue
|
||||
@ -560,9 +563,12 @@ describe('Identify', () => {
|
||||
|
||||
const identityServiceIdentifySpy = sinon.spy(libp2p.identifyService, 'identify')
|
||||
const identityServicePushSpy = sinon.spy(libp2p.identifyService, 'push')
|
||||
|
||||
const connectionPromise = pEvent(libp2p.connectionManager, 'peer:connect')
|
||||
const connection = await libp2p.dial(remoteAddr)
|
||||
|
||||
expect(connection).to.exist()
|
||||
// Wait for connection event to be emitted
|
||||
await connectionPromise
|
||||
|
||||
// Wait for identify to finish
|
||||
await identityServiceIdentifySpy.firstCall.returnValue
|
||||
|
Reference in New Issue
Block a user