diff --git a/doc/DIALER.md b/doc/DIALER.md index 10f4cab1..920372b1 100644 --- a/doc/DIALER.md +++ b/doc/DIALER.md @@ -5,7 +5,7 @@ * The number of tokens requested should be between 1 and the MAX_PER_PEER_DIALS max set in the Dialer. * If the number of available tokens is less than requested, the Dialer may return less than requested. * The number of tokens a DialRequest obtains reflects the maximum number of parallel Multiaddr Dials it can make. -* If no tokens are available a DialRequest should immediately end and throw. This deviates from the existing queue system to avoid queue congestion. +* If no tokens are available a DialRequest should immediately end and throw. * As tokens are limited, DialRequests should be given a prioritized list of Multiaddrs to minimize the potential request time. * Once a Multiaddr Dial has succeeded, all pending dials in that Dial Request should be aborted. * If DIAL_TIMEOUT time has elapsed before any one Multiaddr Dial succeeds, all remaining dials in the DialRequest should be aborted. diff --git a/src/dialer/index.js b/src/dialer/index.js index 58ea3835..b44364a8 100644 --- a/src/dialer/index.js +++ b/src/dialer/index.js @@ -72,6 +72,7 @@ class Dialer { try { const dialResult = await dialRequest.run({ ...options, signal }) clearTimeout(timeoutId) + log('dial succeeded to %s', dialResult.remoteAddr) return dialResult } catch (err) { // Error is a timeout diff --git a/test/dialing/direct.node.js b/test/dialing/direct.node.js index 6df08cd6..fd4ec73b 100644 --- a/test/dialing/direct.node.js +++ b/test/dialing/direct.node.js @@ -27,6 +27,7 @@ const Protector = require('../../src/pnet') const swarmKeyBuffer = Buffer.from(require('../fixtures/swarm.key')) const mockUpgrader = require('../utils/mockUpgrader') +const createMockConnection = require('../utils/mockConnection') const Peers = require('../fixtures/peers') const listenAddr = multiaddr('/ip4/127.0.0.1/tcp/0') @@ -160,9 +161,7 @@ describe('Dialing (direct, TCP)', () => { expect(dialer.tokens).to.have.length(2) const deferredDial = pDefer() - sinon.stub(localTM, 'dial').callsFake(async () => { - await deferredDial.promise - }) + sinon.stub(localTM, 'dial').callsFake(() => deferredDial.promise) // Perform 3 multiaddr dials dialer.connectToMultiaddr([remoteAddr, remoteAddr, remoteAddr]) @@ -173,7 +172,7 @@ describe('Dialing (direct, TCP)', () => { // We should have 2 in progress, and 1 waiting expect(dialer.tokens).to.have.length(0) - deferredDial.resolve() + deferredDial.resolve(await createMockConnection()) // Let the call stack run await delay(0) diff --git a/test/dialing/direct.spec.js b/test/dialing/direct.spec.js index a601c8c4..155b6dbe 100644 --- a/test/dialing/direct.spec.js +++ b/test/dialing/direct.spec.js @@ -27,6 +27,7 @@ const Libp2p = require('../../src') const Peers = require('../fixtures/peers') const { MULTIADDRS_WEBSOCKETS } = require('../fixtures/browser') const mockUpgrader = require('../utils/mockUpgrader') +const createMockConnection = require('../utils/mockConnection') const unsupportedAddr = multiaddr('/ip4/127.0.0.1/tcp/9999/ws') const remoteAddr = MULTIADDRS_WEBSOCKETS[0] @@ -158,9 +159,7 @@ describe('Dialing (direct, WebSockets)', () => { expect(dialer.tokens).to.have.length(2) const deferredDial = pDefer() - sinon.stub(localTM, 'dial').callsFake(async () => { - await deferredDial.promise - }) + sinon.stub(localTM, 'dial').callsFake(() => deferredDial.promise) // Perform 3 multiaddr dials dialer.connectToMultiaddr([remoteAddr, remoteAddr, remoteAddr]) @@ -171,7 +170,7 @@ describe('Dialing (direct, WebSockets)', () => { // We should have 2 in progress, and 1 waiting expect(dialer.tokens).to.have.length(0) - deferredDial.resolve() + deferredDial.resolve(await createMockConnection()) // Let the call stack run await delay(0)