feat: abort all pending dials on stop

This commit is contained in:
Jacob Heun
2019-12-06 17:45:29 +01:00
parent 404fa69513
commit ba02764c5f
4 changed files with 41 additions and 3 deletions

View File

@ -169,6 +169,7 @@ describe('Dialing (direct, WebSockets)', () => {
// We should have 2 in progress, and 1 waiting
expect(dialer.tokens).to.have.length(0)
expect(dialer.pendingDials.size).to.equal(1) // 1 dial request
deferredDial.resolve(await createMockConnection())
@ -178,6 +179,7 @@ describe('Dialing (direct, WebSockets)', () => {
// Only two dials will be run, as the first two succeeded
expect(localTM.dial.callCount).to.equal(2)
expect(dialer.tokens).to.have.length(2)
expect(dialer.pendingDials.size).to.equal(0)
})
describe('libp2p.dialer', () => {
@ -278,5 +280,23 @@ describe('Dialing (direct, WebSockets)', () => {
await libp2p.hangUp(connection.remotePeer)
expect(connection.stat.timeline.close).to.exist()
})
it('should abort pending dials on stop', async () => {
libp2p = new Libp2p({
peerInfo,
modules: {
transport: [Transport],
streamMuxer: [Muxer],
connEncryption: [Crypto]
}
})
const abort = sinon.stub()
const dials = [{ abort }, { abort }, { abort }]
sinon.stub(libp2p.dialer, 'pendingDials').value(new Set(dials))
await libp2p.stop()
expect(abort).to.have.property('callCount', 3)
})
})
})

View File

@ -29,7 +29,9 @@ describe('peer discovery scenarios', () => {
remotePeerInfo2.multiaddrs.add(multiaddr('/ip4/127.0.0.1/tcp/0'))
})
afterEach(async () => {
afterEach(async function () {
// Increase timeout until abort support for dht queries is in place
this.timeout(10e3)
libp2p && await libp2p.stop()
})