mirror of
https://github.com/fluencelabs/js-libp2p
synced 2025-07-23 12:31:57 +00:00
Compare commits
2 Commits
v0.27.0-pr
...
chore/use-
Author | SHA1 | Date | |
---|---|---|---|
|
4dbc6a4dd8 | ||
|
c44e6e33ed |
@@ -90,7 +90,7 @@
|
||||
"libp2p-delegated-content-routing": "^0.4.1",
|
||||
"libp2p-delegated-peer-routing": "^0.4.0",
|
||||
"libp2p-floodsub": "^0.20.0",
|
||||
"libp2p-gossipsub": "^0.2.0",
|
||||
"libp2p-gossipsub": "ChainSafe/gossipsub-js#fix/bind-is-not-needed",
|
||||
"libp2p-kad-dht": "^0.18.2",
|
||||
"libp2p-mdns": "^0.13.0",
|
||||
"libp2p-mplex": "^0.9.1",
|
||||
|
@@ -218,7 +218,14 @@ class Libp2p extends EventEmitter {
|
||||
log('libp2p is stopping')
|
||||
|
||||
try {
|
||||
for (const service of this._discovery.values()) {
|
||||
service.removeListener('peer', this._onDiscoveryPeer)
|
||||
}
|
||||
|
||||
await Promise.all(Array.from(this._discovery.values(), s => s.stop()))
|
||||
|
||||
this.connectionManager.stop()
|
||||
|
||||
await Promise.all([
|
||||
this.pubsub && this.pubsub.stop(),
|
||||
this._dht && this._dht.stop(),
|
||||
|
@@ -65,6 +65,32 @@ describe('peer discovery', () => {
|
||||
|
||||
expect(discoverySpy.called).to.eql(false)
|
||||
})
|
||||
|
||||
it('should stop discovery on libp2p start/stop', async () => {
|
||||
const mockDiscovery = {
|
||||
tag: 'mock',
|
||||
start: () => {},
|
||||
stop: () => {},
|
||||
on: () => {},
|
||||
removeListener: () => {}
|
||||
}
|
||||
const startSpy = sinon.spy(mockDiscovery, 'start')
|
||||
const stopSpy = sinon.spy(mockDiscovery, 'stop')
|
||||
|
||||
libp2p = new Libp2p(mergeOptions(baseOptions, {
|
||||
peerInfo,
|
||||
modules: {
|
||||
peerDiscovery: [mockDiscovery]
|
||||
}
|
||||
}))
|
||||
|
||||
await libp2p.start()
|
||||
expect(startSpy).to.have.property('callCount', 1)
|
||||
expect(stopSpy).to.have.property('callCount', 0)
|
||||
await libp2p.stop()
|
||||
expect(startSpy).to.have.property('callCount', 1)
|
||||
expect(stopSpy).to.have.property('callCount', 1)
|
||||
})
|
||||
})
|
||||
|
||||
describe('discovery modules from transports', () => {
|
||||
|
Reference in New Issue
Block a user