Skip to content

Commit 6ea0de0

Browse files
committed
chore(middleware-flexible-checksums): previous attempt of test
1 parent dec0722 commit 6ea0de0

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import { S3 } from "@aws-sdk/client-s3";
2+
import { HttpResponse } from "@smithy/protocol-http";
3+
import { describe, expect, test as it } from "vitest";
4+
5+
import { flexibleChecksumsMiddleware } from "./flexibleChecksumsMiddleware";
6+
7+
describe("middleware-flexible-checksums.retry", () => {
8+
it("retry reuses the checksum", async () => {
9+
const maxAttempts = 3;
10+
const client = new S3({
11+
maxAttempts,
12+
requestHandler: {
13+
handle: async () => ({
14+
response: new HttpResponse({
15+
statusCode: 500, // Fake Trasient Error
16+
}),
17+
}),
18+
},
19+
});
20+
21+
let flexChecksCallCount = 0;
22+
const flexChecksCallCountMiddleware = (next: any) => async (args: any) => {
23+
console.log("after flexChecks");
24+
flexChecksCallCount++;
25+
return await next(args);
26+
};
27+
client.middlewareStack.addRelativeTo(flexChecksCallCountMiddleware, {
28+
name: flexChecksCallCountMiddleware.name,
29+
toMiddleware: flexibleChecksumsMiddleware.name,
30+
relation: "after",
31+
override: true,
32+
});
33+
34+
client.middlewareStack.identifyOnResolve(true);
35+
36+
await client
37+
.putObject({
38+
Bucket: "b",
39+
Key: "k",
40+
Body: "hello",
41+
})
42+
.catch((err) => {
43+
console.log({ err, flexChecksCallCount });
44+
// Expected, since we're faking transient error which is retried.
45+
46+
// Validate that flexibleChecksumsMiddleware is called once.
47+
expect(flexChecksCallCount).toEqual(1);
48+
// Validate that retryMiddleware is called maxAttempts times.
49+
expect(err.$metadata.attempts).toEqual(maxAttempts);
50+
});
51+
52+
expect.assertions(2);
53+
});
54+
});

0 commit comments

Comments
 (0)