Skip to content

Commit

Permalink
fix(aws-client-retry-test): use s3 client in case x-ray is not built (#…
Browse files Browse the repository at this point in the history
…4276)

* fix(aws-client-retry-test): use s3 client in case x-ray is not built

* fix(aws-client-retry-test): fix variable name
  • Loading branch information
kuhe committed Dec 12, 2022
1 parent d99a65d commit 1fd4179
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions private/aws-client-retry-test/src/ClientRetryTest.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { GetInsightCommand, ThrottledException, XRayClient } from "@aws-sdk/client-xray";
import { HeadObjectCommand, S3Client, S3ServiceException } from "@aws-sdk/client-s3";
import { HttpResponse } from "@aws-sdk/protocol-http";
import { RequestHandlerOutput } from "@aws-sdk/types";
import { StandardRetryStrategy } from "@aws-sdk/util-retry";
Expand All @@ -18,17 +18,18 @@ describe("Middleware-retry integration tests", () => {
body: Readable.from(""),
}),
};
const getInsightCommand = new GetInsightCommand({
InsightId: "foo",
const headObjectCommand = new HeadObjectCommand({
Bucket: "TEST_BUCKET",
Key: "TEST_KEY",
});
it("should not retry on 200", async () => {
const client = new XRayClient({
const client = new S3Client({
requestHandler: {
handle: () => Promise.resolve(mockSuccess),
},
});
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
const response = await client.send(getInsightCommand);
const response = await client.send(headObjectCommand);
expect(response.$metadata.httpStatusCode).toBe(200);
expect(response.$metadata.attempts).toBe(1);
expect(response.$metadata.totalRetryDelay).toBe(0);
Expand All @@ -39,33 +40,38 @@ describe("Middleware-retry integration tests", () => {
.mockResolvedValueOnce(mockThrottled)
.mockResolvedValueOnce(mockThrottled)
.mockResolvedValueOnce(mockSuccess);
const client = new XRayClient({
const client = new S3Client({
requestHandler: {
handle: mockHandle,
},
});
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
const response = await client.send(getInsightCommand);
const response = await client.send(headObjectCommand);
expect(response.$metadata.httpStatusCode).toBe(200);
expect(mockHandle).toBeCalledTimes(3);
expect(response.$metadata.attempts).toBe(3);
expect(response.$metadata.totalRetryDelay).toBeGreaterThan(0);
});
it("should retry until attemps are exhausted", async () => {
const expectedException = new ThrottledException({
const expectedException = new S3ServiceException({
$metadata: {
httpStatusCode: 429,
},
$fault: "client",
$retryable: {
throttling: true,
},
message: "UnknownError",
name: "ThrottlingException",
});
const client = new XRayClient({
const client = new S3Client({
requestHandler: {
handle: () => Promise.resolve(mockThrottled),
},
});
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
try {
await client.send(getInsightCommand);
await client.send(headObjectCommand);
} catch (error) {
expect(error).toStrictEqual(expectedException);
expect(error.$metadata.httpStatusCode).toBe(429);
Expand Down

0 comments on commit 1fd4179

Please sign in to comment.