From fad7ef270e36953bcde46085ea3367baa23b8cfa Mon Sep 17 00:00:00 2001 From: Russell Dempsey <1173416+SgtPooki@users.noreply.github.com> Date: Thu, 16 May 2024 16:17:14 -0700 Subject: [PATCH] test: add test that shows abort signals are not respected --- packages/utils/test/abstract-session.spec.ts | 21 ++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/packages/utils/test/abstract-session.spec.ts b/packages/utils/test/abstract-session.spec.ts index 43228ff21..0b3c5f7a3 100644 --- a/packages/utils/test/abstract-session.spec.ts +++ b/packages/utils/test/abstract-session.spec.ts @@ -233,4 +233,25 @@ describe('abstract-session', () => { })).to.eventually.be.rejected() .with.property('code', 'ABORT_ERR') }) + + it('should respect signals', async () => { + const signal = AbortSignal.timeout(10) + const session = new Session() + + const cid = CID.parse('bafybeifaymukvfkyw6xgh4th7tsctiifr4ea2btoznf46y6b2fnvikdczi') + + session.findNewProviders.callsFake(async function * () { + yield { + id: await createEd25519PeerId() + } + }) + session.queryProvider.callsFake(async () => { + throw new Error('Urk!') + }) + + await expect(session.retrieve(cid, { + signal + })).to.eventually.be.rejected() + .with.property('code', 'ABORT_ERR') + }) })