-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
34 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/verified-fetch/test/fixtures/get-abortable-promise.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* we need to emulate signal handling (blockBrokers/dnsResolvers/etc should handle abort signals too) | ||
* this is a simplified version of what libs we depend on should do, and the | ||
* tests in this file verify how verified-fetch would handle the failure | ||
*/ | ||
export async function getAbortablePromise <T> (signal?: AbortSignal): Promise<T> { | ||
return new Promise((resolve, reject) => { | ||
const timeoutId = setTimeout(() => { | ||
reject(new Error('timeout while resolving')) | ||
}, 5000) | ||
|
||
signal?.addEventListener('abort', () => { | ||
clearTimeout(timeoutId) | ||
reject(new Error('aborted')) | ||
}) | ||
}) | ||
} |
14 changes: 14 additions & 0 deletions
14
packages/verified-fetch/test/fixtures/make-aborted-request.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import type { VerifiedFetch } from '../../src/verified-fetch.js' | ||
|
||
export async function makeAbortedRequest (verifiedFetch: VerifiedFetch, [resource, options = {}]: Parameters<typeof verifiedFetch.fetch>, promise: Promise<any>): Promise<Response> { | ||
const controller = new AbortController() | ||
const resultPromise = verifiedFetch.fetch(resource, { | ||
...options, | ||
signal: controller.signal | ||
}) | ||
|
||
void promise.then(() => { | ||
controller.abort() | ||
}) | ||
return resultPromise | ||
} |