Skip to content

Commit 454488b

Browse files
committed
test
1 parent a96c951 commit 454488b

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { newRetryDelay } from "./GitDeviceAuth";
2+
import { AxiosError, type AxiosResponse } from "axios";
3+
4+
test("device auth retry delay", async () => {
5+
const slowDownError = new AxiosError(
6+
"slow_down",
7+
"500",
8+
undefined,
9+
undefined,
10+
{
11+
data: {
12+
detail: "slow_down",
13+
},
14+
} as AxiosResponse,
15+
);
16+
const retryDelay = newRetryDelay(undefined);
17+
18+
expect(retryDelay(0, undefined)).toBe(5000);
19+
// If the error is a slow down error, the interval should increase by 5 seconds
20+
// for this and all subsequent requests, and by 5 seconds extra delay for this
21+
// request.
22+
expect(retryDelay(1, slowDownError)).toBe(15000);
23+
expect(retryDelay(1, slowDownError)).toBe(15000);
24+
expect(retryDelay(2, undefined)).toBe(10000);
25+
26+
// Like previous request.
27+
expect(retryDelay(3, slowDownError)).toBe(20000);
28+
expect(retryDelay(3, undefined)).toBe(15000);
29+
// If the error is not a slow down error, the interval should not increase.
30+
expect(retryDelay(4, new AxiosError("other", "500"))).toBe(15000);
31+
32+
// If the initial interval is provided, it should be used.
33+
const retryDelayWithInitialInterval = newRetryDelay(1);
34+
expect(retryDelayWithInitialInterval(0, undefined)).toBe(1000);
35+
expect(retryDelayWithInitialInterval(1, slowDownError)).toBe(11000);
36+
expect(retryDelayWithInitialInterval(2, undefined)).toBe(6000);
37+
});

0 commit comments

Comments
 (0)