diff --git a/packages/utils/src/abstract-session.ts b/packages/utils/src/abstract-session.ts index a8fcd048c..41718411b 100644 --- a/packages/utils/src/abstract-session.ts +++ b/packages/utils/src/abstract-session.ts @@ -188,7 +188,7 @@ export abstract class AbstractSession this.equals(prov, provider)) + return this.evictionFilter.has(this.toEvictionKey(provider)) } hasProvider (provider: Provider): boolean { diff --git a/packages/utils/test/abstract-session.spec.ts b/packages/utils/test/abstract-session.spec.ts index 43228ff21..0ee419452 100644 --- a/packages/utils/test/abstract-session.spec.ts +++ b/packages/utils/test/abstract-session.spec.ts @@ -233,4 +233,27 @@ describe('abstract-session', () => { })).to.eventually.be.rejected() .with.property('code', 'ABORT_ERR') }) + + it('should not make multiple requests to the only found provider', async function () { + this.timeout(1000) + const session: Session | null = new Session() + + const cid = CID.parse('bafybeifaymukvfkyw6xgh4th7tsctiifr4ea2btoznf46y6b2fnvikdczi') + const id = await createEd25519PeerId() // same provider + session.findNewProviders.callsFake(async function * () { + yield { + id + } + }) + + session.queryProvider.callsFake(async () => { + // always fails + throw new Error('Urk!') + }) + + await expect(session.retrieve(cid)).to.eventually.be.rejected() + + expect(session.findNewProviders).to.have.property('callCount', 2) + expect(session.queryProvider).to.have.property('callCount', 1) + }) })