-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathretry.test.ts
43 lines (38 loc) · 1.17 KB
/
retry.test.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { Code, ConnectError } from "@connectrpc/connect";
import { Effect as E, pipe } from "effect";
import { describe, expect, it } from "vitest";
import { retryGrpcRequestIfRecoverable } from "#/vm/operation/retry-client";
describe("Client retry", () => {
it("should retry recoverable errors", async () => {
let succeedAfter = 3;
const operation = E.tryPromise(() => {
if (succeedAfter === 0) {
return Promise.resolve("success");
}
succeedAfter -= 1;
return Promise.reject(new ConnectError("test", Code.Unavailable));
});
const result = await pipe(
retryGrpcRequestIfRecoverable<string>("it should retry", operation),
E.runPromise,
);
expect(result).toBe("success");
});
it("should eventually fail", async () => {
const operation = E.tryPromise(() =>
Promise.reject(new ConnectError("test", Code.DataLoss)),
);
try {
await pipe(
retryGrpcRequestIfRecoverable<string>(
"it should eventually fail",
operation,
),
E.runPromise,
);
expect(false).toBeTruthy();
} catch (_error: unknown) {
expect(true).toBeTruthy();
}
});
});