Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions packages/client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,6 @@ export class DefaultDelegatedRoutingV1HttpApiClient implements DelegatedRoutingV
} else {
throw new BadResponseError(`Unsupported Content-Type: ${contentType}`)
}
} catch (err) {
log.error('getProviders errored:', err)
} finally {
signal.clear()
onFinish.resolve()
Expand Down
34 changes: 34 additions & 0 deletions packages/client/test/routings.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,40 @@
})))
})

it('should respect abort signal when finding providers', async () => {
const routing = getContentRouting(client)

if (routing == null) {
throw new Error('ContentRouting not found')
}

Check warning on line 90 in packages/client/test/routings.spec.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/test/routings.spec.ts#L89-L90

Added lines #L89 - L90 were not covered by tests

const providers = [{
ID: (await generateKeyPair('Ed25519')).publicKey.toString(),
Addrs: ['/ip4/43.43.43.43/tcp/1234']
}]

const cid = CID.parse('QmawceGscqN4o8Y8Fv26UUmB454kn2bnkXV5tEQYc4jBd6')

// load providers for the router to fetch
await fetch(`${process.env.ECHO_SERVER}/add-providers/${cid.toString()}`, {
method: 'POST',
body: providers.map(prov => JSON.stringify(prov)).join('\n')
})

let findProvidersFinished = false
let error: any = new Error('temporary error that should be replaced')
try {
const controller = new AbortController()
controller.abort()
await all(routing.findProviders(cid, { signal: controller.signal }))
findProvidersFinished = true

Check warning on line 111 in packages/client/test/routings.spec.ts

View check run for this annotation

Codecov / codecov/patch

packages/client/test/routings.spec.ts#L111

Added line #L111 was not covered by tests
} catch (err: any) {
error = err
}
expect(findProvidersFinished).to.be.false()
expect(error).to.have.property('message').that.includes('abort', error.message)
})

it('should provide without error', async () => {
const routing = getContentRouting(client)

Expand Down