mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-04-25 10:32:14 +00:00
chore: fix close for ConnectionManager (#861)
This commit is contained in:
parent
67067c97d5
commit
a28c878f4a
@ -160,7 +160,7 @@ class ConnectionManager extends EventEmitter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
await tasks
|
await Promise.all(tasks)
|
||||||
this.connections.clear()
|
this.connections.clear()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
const { expect } = require('aegir/utils/chai')
|
const { expect } = require('aegir/utils/chai')
|
||||||
const sinon = require('sinon')
|
const sinon = require('sinon')
|
||||||
|
const { CLOSED } = require('libp2p-interfaces/src/connection/status')
|
||||||
|
|
||||||
const delay = require('delay')
|
const delay = require('delay')
|
||||||
const pWaitFor = require('p-wait-for')
|
const pWaitFor = require('p-wait-for')
|
||||||
@ -268,5 +269,40 @@ describe('libp2p.connections', () => {
|
|||||||
|
|
||||||
await libp2p.stop()
|
await libp2p.stop()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should be closed status once immediately stopping', async () => {
|
||||||
|
const [libp2p] = await peerUtils.createPeer({
|
||||||
|
config: {
|
||||||
|
peerId: peerIds[0],
|
||||||
|
addresses: {
|
||||||
|
listen: ['/ip4/127.0.0.1/tcp/15003/ws']
|
||||||
|
},
|
||||||
|
modules: baseOptions.modules
|
||||||
|
}
|
||||||
|
})
|
||||||
|
const [remoteLibp2p] = await peerUtils.createPeer({
|
||||||
|
config: {
|
||||||
|
peerId: peerIds[1],
|
||||||
|
addresses: {
|
||||||
|
listen: ['/ip4/127.0.0.1/tcp/15004/ws']
|
||||||
|
},
|
||||||
|
modules: baseOptions.modules
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
libp2p.peerStore.addressBook.set(remoteLibp2p.peerId, remoteLibp2p.multiaddrs)
|
||||||
|
await libp2p.dial(remoteLibp2p.peerId)
|
||||||
|
|
||||||
|
const totalConns = Array.from(libp2p.connections.values())
|
||||||
|
expect(totalConns.length).to.eql(1)
|
||||||
|
const conns = totalConns[0]
|
||||||
|
expect(conns.length).to.eql(1)
|
||||||
|
const conn = conns[0]
|
||||||
|
|
||||||
|
await libp2p.stop()
|
||||||
|
expect(conn.stat.status).to.eql(CLOSED)
|
||||||
|
|
||||||
|
await remoteLibp2p.stop()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user