-
Notifications
You must be signed in to change notification settings - Fork 0
fix(client): respect Retry-After before retrying #68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8346934
fix(client): respect Retry-After before retrying
aeitwoen 5356a15
fix(client): bound Retry-After delay
aeitwoen 22687a1
test(client): move live retry check to e2e
aeitwoen 714b319
fix(client): preserve retry error types
aeitwoen f7f83c7
test(client): clarify timer boundary
aeitwoen 821c1a1
test(client): explain e2e timer boundary
aeitwoen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,58 @@ | ||
| import { createServer } from "node:http"; | ||
| import { Client } from "../../src/core/client.ts"; | ||
| import { HTTPError } from "../../src/core/errors.ts"; | ||
|
|
||
| describe("Client", () => { | ||
| it("honors Retry-After without misclassifying server errors", async () => { | ||
| let requests = 0; | ||
| let responseStatus: number | null = 429; | ||
| let retryAfter = "1"; | ||
| const server = createServer((_request, response) => { | ||
| requests++; | ||
| if (responseStatus !== null) { | ||
| const status = responseStatus; | ||
| responseStatus = null; | ||
| response.writeHead(status, { Connection: "close", "Retry-After": retryAfter }); | ||
| response.end(); | ||
| return; | ||
| } | ||
|
|
||
| response.writeHead(200, { Connection: "close", "Content-Type": "application/json" }); | ||
| response.end('{"ok":true}'); | ||
| }); | ||
|
|
||
| await new Promise<void>((resolve, reject) => { | ||
| const onError = (error: Error) => reject(error); | ||
| server.once("error", onError); | ||
| server.listen(0, "127.0.0.1", () => { | ||
| server.off("error", onError); | ||
| resolve(); | ||
| }); | ||
| }); | ||
|
|
||
| try { | ||
| const address = server.address(); | ||
| if (!address || typeof address === "string") throw new Error("Expected TCP server address"); | ||
| const url = `http://127.0.0.1:${address.port}`; | ||
|
|
||
| const startedAt = performance.now(); | ||
| await new Client({ maxRetries: 1, baseDelay: 10 }).getJSON(url); | ||
| expect(performance.now() - startedAt).toBeGreaterThanOrEqual(900); | ||
| expect(requests).toBe(2); | ||
|
|
||
| responseStatus = 503; | ||
| // 2_147_484 seconds converts to 2_147_484_000 ms, just above Node's timer ceiling. | ||
| retryAfter = "2147484"; | ||
|
aeitwoen marked this conversation as resolved.
|
||
| const failure = new Client({ maxRetries: 1, baseDelay: 10 }).getJSON(url); | ||
| await expect(failure).rejects.toMatchObject({ | ||
| name: HTTPError.name, | ||
| statusCode: 503, | ||
| }); | ||
| expect(requests).toBe(3); | ||
| } finally { | ||
| await new Promise<void>((resolve, reject) => { | ||
| server.close((error) => (error ? reject(error) : resolve())); | ||
| }); | ||
| } | ||
| }); | ||
| }); | ||
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.