Skip to content

Commit a2957af

Browse files
committed
test
1 parent a96c951 commit a2957af

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
// If no initial interval is provided, the default must be 5 seconds.
19+
expect(retryDelay(0, undefined)).toBe(5000);
20+
// If the error is a slow down error, the interval should increase by 5 seconds
21+
// for this and all subsequent requests, and by 5 seconds extra delay for this
22+
// request.
23+
expect(retryDelay(1, slowDownError)).toBe(15000);
24+
expect(retryDelay(1, slowDownError)).toBe(15000);
25+
expect(retryDelay(2, undefined)).toBe(10000);
26+
27+
// Like previous request.
28+
expect(retryDelay(3, slowDownError)).toBe(20000);
29+
expect(retryDelay(3, undefined)).toBe(15000);
30+
// If the error is not a slow down error, the interval should not increase.
31+
expect(retryDelay(4, new AxiosError("other", "500"))).toBe(15000);
32+
33+
// If the initial interval is provided, it should be used.
34+
const retryDelayWithInitialInterval = newRetryDelay(1);
35+
expect(retryDelayWithInitialInterval(0, undefined)).toBe(1000);
36+
expect(retryDelayWithInitialInterval(1, slowDownError)).toBe(11000);
37+
expect(retryDelayWithInitialInterval(2, undefined)).toBe(6000);
38+
});

0 commit comments

Comments
 (0)