Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import { S3 } from "@aws-sdk/client-s3";
import { HttpResponse } from "@smithy/protocol-http";
import { describe, expect, test as it } from "vitest";

import { flexibleChecksumsMiddleware } from "./flexibleChecksumsMiddleware";

describe("middleware-flexible-checksums.retry", () => {
it("retry reuses the checksum", async () => {
const maxAttempts = 3;
const client = new S3({
maxAttempts,
requestHandler: {
handle: async () => ({
response: new HttpResponse({
statusCode: 500, // Fake Trasient Error
}),
}),
},
});

let flexChecksCallCount = 0;
const flexChecksCallCountMiddleware = (next: any) => async (args: any) => {
console.log("after flexChecks");
flexChecksCallCount++;
return await next(args);
};
client.middlewareStack.addRelativeTo(flexChecksCallCountMiddleware, {
name: flexChecksCallCountMiddleware.name,
toMiddleware: flexibleChecksumsMiddleware.name,
relation: "after",
override: true,
});

client.middlewareStack.identifyOnResolve(true);

await client
.putObject({
Bucket: "b",
Key: "k",
Body: "hello",
})
.catch((err) => {
console.log({ err, flexChecksCallCount });
// Expected, since we're faking transient error which is retried.

// Validate that flexibleChecksumsMiddleware is called once.
expect(flexChecksCallCount).toEqual(1);
// Validate that retryMiddleware is called maxAttempts times.
expect(err.$metadata.attempts).toEqual(maxAttempts);
});

expect.assertions(2);
});
});
Loading