Skip to content

Commit ff22f5e

Browse files
authored
test(aws-client-retry-test): use Lambda client for retry test (#7272)
1 parent b585daa commit ff22f5e

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

private/aws-client-retry-test/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"module": "./dist-es/index.js",
1919
"sideEffects": false,
2020
"dependencies": {
21-
"@aws-sdk/client-s3": "*",
21+
"@aws-sdk/client-lambda": "*",
2222
"@smithy/protocol-http": "^5.1.3",
2323
"@smithy/types": "^4.3.2",
2424
"@smithy/util-retry": "^4.0.7",

private/aws-client-retry-test/src/ClientRetryTest.spec.ts

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { HeadObjectCommand, S3, S3Client, S3ServiceException } from "@aws-sdk/client-s3";
1+
import { ListFunctionsCommand, Lambda, LambdaClient, LambdaServiceException } from "@aws-sdk/client-lambda";
22
import { HttpHandler, HttpResponse } from "@smithy/protocol-http";
33
import { AwsCredentialIdentity, RequestHandlerOutput } from "@smithy/types";
44
import { ConfiguredRetryStrategy, StandardRetryStrategy } from "@smithy/util-retry";
@@ -32,7 +32,7 @@ describe("util-retry integration tests", () => {
3232
const mockThrottled: RequestHandlerOutput<HttpResponse> = {
3333
response: new HttpResponse({
3434
statusCode: 429,
35-
headers: { "x-amzn-errortype": "ThrottledException" },
35+
headers: { "x-amzn-errortype": "ThrottlingException" },
3636
body: Readable.from([""]),
3737
}),
3838
};
@@ -42,13 +42,10 @@ describe("util-retry integration tests", () => {
4242
body: Readable.from(""),
4343
}),
4444
};
45-
const headObjectCommand = new HeadObjectCommand({
46-
Bucket: "TEST_BUCKET",
47-
Key: "TEST_KEY",
48-
});
45+
const command = new ListFunctionsCommand();
4946

5047
it("should not retry on 200", async () => {
51-
const client = new S3Client({
48+
const client = new LambdaClient({
5249
requestHandler: {
5350
handle: () => Promise.resolve(mockSuccess),
5451
updateHttpClientConfig: () => {},
@@ -58,7 +55,7 @@ describe("util-retry integration tests", () => {
5855
credentials,
5956
});
6057
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
61-
const response = await client.send(headObjectCommand);
58+
const response = await client.send(command);
6259
expect(response.$metadata.httpStatusCode).toBe(200);
6360
expect(response.$metadata.attempts).toBe(1);
6461
expect(response.$metadata.totalRetryDelay).toBe(0);
@@ -70,7 +67,7 @@ describe("util-retry integration tests", () => {
7067
.mockResolvedValueOnce(mockThrottled)
7168
.mockResolvedValueOnce(mockThrottled)
7269
.mockResolvedValueOnce(mockSuccess);
73-
const client = new S3Client({
70+
const client = new LambdaClient({
7471
requestHandler: {
7572
handle: mockHandle,
7673
httpHandlerConfigs: () => ({}),
@@ -80,17 +77,18 @@ describe("util-retry integration tests", () => {
8077
credentials,
8178
});
8279
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
83-
const response = await client.send(headObjectCommand);
80+
const response = await client.send(command);
8481
expect(response.$metadata.httpStatusCode).toBe(200);
8582
expect(mockHandle).toBeCalledTimes(3);
8683
expect(response.$metadata.attempts).toBe(3);
8784
expect(response.$metadata.totalRetryDelay).toBeGreaterThan(0);
8885
});
8986

9087
it("should retry until attempts are exhausted", async () => {
91-
const expectedException = new S3ServiceException({
88+
const expectedException = new LambdaServiceException({
9289
$metadata: {
9390
httpStatusCode: 429,
91+
attempts: 3,
9492
},
9593
$fault: "client",
9694
$retryable: {
@@ -99,7 +97,7 @@ describe("util-retry integration tests", () => {
9997
message: "UnknownError",
10098
name: "ThrottlingException",
10199
});
102-
const client = new S3Client({
100+
const client = new LambdaClient({
103101
requestHandler: {
104102
handle: () => Promise.resolve(mockThrottled),
105103
httpHandlerConfigs: () => ({}),
@@ -110,11 +108,13 @@ describe("util-retry integration tests", () => {
110108
});
111109
expect(await client.config.retryStrategy()).toBeInstanceOf(StandardRetryStrategy);
112110
try {
113-
await client.send(headObjectCommand);
111+
await client.send(command);
114112
} catch (error) {
115-
expect(error).toStrictEqual(expectedException);
116-
expect(error.$metadata.httpStatusCode).toBe(429);
117-
expect(error.$metadata.attempts).toBe(3);
113+
expect(error.name).toBe(expectedException.name);
114+
expect(error.message).toBe(expectedException.message);
115+
expect(error.$fault).toBe(expectedException.$fault);
116+
expect(error.$metadata.httpStatusCode).toBe(expectedException.$metadata.httpStatusCode);
117+
expect(error.$metadata.attempts).toBe(expectedException.$metadata.attempts);
118118
expect(error.$metadata.totalRetryDelay).toBeGreaterThan(0);
119119
}
120120
});
@@ -131,7 +131,7 @@ describe("util-retry integration tests", () => {
131131
expectedInitialCapacity - expectedDrainPerAttempt * expectedRetryAttemptsPerRequest * expectedRequests;
132132

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

143143
await Promise.all([
144-
s3.headBucket({ Bucket: "undefined" }),
145-
s3.headBucket({ Bucket: "undefined" }),
146-
s3.headBucket({ Bucket: "undefined" }),
147-
s3.headBucket({ Bucket: "undefined" }),
144+
client.listFunctions(),
145+
client.listFunctions(),
146+
client.listFunctions(),
147+
client.listFunctions(),
148148
]).catch((e) => {
149149
expect(e.$metadata.attempts).toBe(1 + expectedRetryAttemptsPerRequest);
150150
expect(e.$metadata.totalRetryDelay).toBe(expectedRetryAttemptsPerRequest * delayPerRetry);

yarn.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ __metadata:
146146
version: 0.0.0-use.local
147147
resolution: "@aws-sdk/aws-client-retry-test@workspace:private/aws-client-retry-test"
148148
dependencies:
149-
"@aws-sdk/client-s3": "npm:*"
149+
"@aws-sdk/client-lambda": "npm:*"
150150
"@smithy/protocol-http": "npm:^5.1.3"
151151
"@smithy/types": "npm:^4.3.2"
152152
"@smithy/util-retry": "npm:^4.0.7"

0 commit comments

Comments
 (0)