Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion private/aws-client-retry-test/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"module": "./dist-es/index.js",
"sideEffects": false,
"dependencies": {
"@aws-sdk/client-s3": "*",
"@aws-sdk/client-lambda": "*",
"@smithy/protocol-http": "^5.1.3",
"@smithy/types": "^4.3.2",
"@smithy/util-retry": "^4.0.7",
Expand Down
42 changes: 21 additions & 21 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 { HeadObjectCommand, S3, S3Client, S3ServiceException } from "@aws-sdk/client-s3";
import { ListFunctionsCommand, Lambda, LambdaClient, LambdaServiceException } from "@aws-sdk/client-lambda";
import { HttpHandler, HttpResponse } from "@smithy/protocol-http";
import { AwsCredentialIdentity, RequestHandlerOutput } from "@smithy/types";
import { ConfiguredRetryStrategy, StandardRetryStrategy } from "@smithy/util-retry";
Expand Down Expand Up @@ -32,7 +32,7 @@ describe("util-retry integration tests", () => {
const mockThrottled: RequestHandlerOutput<HttpResponse> = {
response: new HttpResponse({
statusCode: 429,
headers: { "x-amzn-errortype": "ThrottledException" },
headers: { "x-amzn-errortype": "ThrottlingException" },
body: Readable.from([""]),
}),
};
Expand All @@ -42,13 +42,10 @@ describe("util-retry integration tests", () => {
body: Readable.from(""),
}),
};
const headObjectCommand = new HeadObjectCommand({
Bucket: "TEST_BUCKET",
Key: "TEST_KEY",
});
const command = new ListFunctionsCommand();

it("should not retry on 200", async () => {
const client = new S3Client({
const client = new LambdaClient({
requestHandler: {
handle: () => Promise.resolve(mockSuccess),
updateHttpClientConfig: () => {},
Expand All @@ -58,7 +55,7 @@ describe("util-retry integration tests", () => {
credentials,
});
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
const response = await client.send(headObjectCommand);
const response = await client.send(command);
expect(response.$metadata.httpStatusCode).toBe(200);
expect(response.$metadata.attempts).toBe(1);
expect(response.$metadata.totalRetryDelay).toBe(0);
Expand All @@ -70,7 +67,7 @@ describe("util-retry integration tests", () => {
.mockResolvedValueOnce(mockThrottled)
.mockResolvedValueOnce(mockThrottled)
.mockResolvedValueOnce(mockSuccess);
const client = new S3Client({
const client = new LambdaClient({
requestHandler: {
handle: mockHandle,
httpHandlerConfigs: () => ({}),
Expand All @@ -80,17 +77,18 @@ describe("util-retry integration tests", () => {
credentials,
});
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
const response = await client.send(headObjectCommand);
const response = await client.send(command);
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 attempts are exhausted", async () => {
const expectedException = new S3ServiceException({
const expectedException = new LambdaServiceException({
$metadata: {
httpStatusCode: 429,
attempts: 3,
},
$fault: "client",
$retryable: {
Expand All @@ -99,7 +97,7 @@ describe("util-retry integration tests", () => {
message: "UnknownError",
name: "ThrottlingException",
});
const client = new S3Client({
const client = new LambdaClient({
requestHandler: {
handle: () => Promise.resolve(mockThrottled),
httpHandlerConfigs: () => ({}),
Expand All @@ -110,11 +108,13 @@ describe("util-retry integration tests", () => {
});
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
try {
await client.send(headObjectCommand);
await client.send(command);
} catch (error) {
expect(error).toStrictEqual(expectedException);
expect(error.$metadata.httpStatusCode).toBe(429);
expect(error.$metadata.attempts).toBe(3);
expect(error.name).toBe(expectedException.name);
expect(error.message).toBe(expectedException.message);
expect(error.$fault).toBe(expectedException.$fault);
expect(error.$metadata.httpStatusCode).toBe(expectedException.$metadata.httpStatusCode);
expect(error.$metadata.attempts).toBe(expectedException.$metadata.attempts);
expect(error.$metadata.totalRetryDelay).toBeGreaterThan(0);
}
});
Expand All @@ -131,7 +131,7 @@ describe("util-retry integration tests", () => {
expectedInitialCapacity - expectedDrainPerAttempt * expectedRetryAttemptsPerRequest * expectedRequests;

const retryStrategy = new ConfiguredRetryStrategy(maxAttempts, delayPerRetry);
const s3 = new S3({
const client = new Lambda({
requestHandler: new MockRequestHandler(),
retryStrategy,
region: MOCK_REGION,
Expand All @@ -141,10 +141,10 @@ describe("util-retry integration tests", () => {
expect(retryStrategy.getCapacity()).toEqual(expectedInitialCapacity);

await Promise.all([
s3.headBucket({ Bucket: "undefined" }),
s3.headBucket({ Bucket: "undefined" }),
s3.headBucket({ Bucket: "undefined" }),
s3.headBucket({ Bucket: "undefined" }),
client.listFunctions(),
client.listFunctions(),
client.listFunctions(),
client.listFunctions(),
]).catch((e) => {
expect(e.$metadata.attempts).toBe(1 + expectedRetryAttemptsPerRequest);
expect(e.$metadata.totalRetryDelay).toBe(expectedRetryAttemptsPerRequest * delayPerRetry);
Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@aws-sdk/aws-client-retry-test@workspace:private/aws-client-retry-test"
dependencies:
"@aws-sdk/client-s3": "npm:*"
"@aws-sdk/client-lambda": "npm:*"
"@smithy/protocol-http": "npm:^5.1.3"
"@smithy/types": "npm:^4.3.2"
"@smithy/util-retry": "npm:^4.0.7"
Expand Down
Loading