diff --git a/src/content-routing/index.js b/src/content-routing/index.js index bd961849..ee836c8d 100644 --- a/src/content-routing/index.js +++ b/src/content-routing/index.js @@ -91,7 +91,11 @@ module.exports = (dht) => { // All done if (out.length >= n) { - return out.toArray() + // yield values + for (const pInfo of out.toArray()) { + yield pInfo + } + return } // need more, query the network diff --git a/test/kad-dht.spec.js b/test/kad-dht.spec.js index 187a1a8d..36d3050f 100644 --- a/test/kad-dht.spec.js +++ b/test/kad-dht.spec.js @@ -484,6 +484,23 @@ describe('KadDHT', () => { return tdht.teardown() }) + + it('find one provider locally', async function () { + this.timeout(20 * 1000) + const val = values[0] + const tdht = new TestDHT() + const [dht] = await tdht.spawn(1) + + sinon.stub(dht.providers, 'getProviders').returns([dht.peerInfo.id]) + + // Find provider + const res = await all(dht.findProviders(val.cid, { maxNumProviders: 1 })) + + expect(res).to.exist() + expect(res).to.have.length(1) + + return tdht.teardown() + }) }) describe('peer routing', () => {