Skip to content

Commit 0a328e8

Browse files
committed
feat(middleware-retry): add integration tests
1 parent 071e6b1 commit 0a328e8

File tree

10 files changed

+192
-0
lines changed

10 files changed

+192
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# Change Log
2+
3+
All notable changes to this project will be documented in this file.
4+
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
const base = require("../../jest.config.base.js");
2+
3+
module.exports = {
4+
...base,
5+
};
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
{
2+
"name": "@aws-sdk/aws-client-retry-test",
3+
"description": "Integration test suite for middleware-retry",
4+
"version": "3.0.0",
5+
"scripts": {
6+
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
7+
"build:cjs": "tsc -p tsconfig.cjs.json",
8+
"build:docs": "typedoc",
9+
"build:es": "tsc -p tsconfig.es.json",
10+
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
11+
"build:types": "tsc -p tsconfig.types.json",
12+
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
13+
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
14+
"test": "jest --coverage --passWithNoTests"
15+
},
16+
"main": "./dist-cjs/index.js",
17+
"types": "./dist-types/index.d.ts",
18+
"module": "./dist-es/index.js",
19+
"sideEffects": false,
20+
"dependencies": {
21+
"@aws-sdk/client-xray": "*",
22+
"tslib": "^2.3.1"
23+
},
24+
"devDependencies": {
25+
"@tsconfig/node14": "1.0.3",
26+
"@types/node": "^12.7.5",
27+
"concurrently": "7.0.0",
28+
"downlevel-dts": "0.10.1",
29+
"typedoc": "0.19.2",
30+
"typescript": "~4.6.2"
31+
},
32+
"overrides": {
33+
"typedoc": {
34+
"typescript": "~4.6.2"
35+
}
36+
},
37+
"engines": {
38+
"node": ">=14.0.0"
39+
},
40+
"typesVersions": {
41+
"<4.0": {
42+
"dist-types/*": [
43+
"dist-types/ts3.4/*"
44+
]
45+
}
46+
},
47+
"files": [
48+
"dist-*"
49+
],
50+
"author": {
51+
"name": "AWS SDK for JavaScript Team",
52+
"url": "https://aws.amazon.com/javascript/"
53+
},
54+
"license": "Apache-2.0",
55+
"private": true,
56+
"repository": {
57+
"type": "git",
58+
"url": "https://github.com/aws/aws-sdk-js-v3.git",
59+
"directory": "private/aws-client-api-test"
60+
}
61+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# @aws-sdk/aws-client-api-test
2+
3+
This is not a runtime or published package.
4+
5+
This is a test spec.
6+
7+
The purpose of this package is to perform integration tests on the retry-middleware.
8+
9+
If tests in this package fail, the author should either fix their changes such that the API contract
10+
is maintained, or appropriately announce and safely deprecate the interfaces affected by incoming changes.
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
import { GetInsightCommand, ThrottledException, XRayClient } from "@aws-sdk/client-xray";
2+
import { HttpResponse } from "@aws-sdk/protocol-http";
3+
import { RequestHandlerOutput } from "@aws-sdk/types";
4+
import { Readable } from "stream";
5+
6+
describe("Middleware-retry integration tests", () => {
7+
const mockThrottled: RequestHandlerOutput<HttpResponse> = {
8+
response: new HttpResponse({
9+
statusCode: 429,
10+
headers: { "x-amzn-errortype": "ThrottledException" },
11+
body: Readable.from([""]),
12+
}),
13+
};
14+
const mockSuccess: RequestHandlerOutput<HttpResponse> = {
15+
response: new HttpResponse({
16+
statusCode: 200,
17+
body: Readable.from(""),
18+
}),
19+
};
20+
const getInsightCommand = new GetInsightCommand({
21+
InsightId: "foo",
22+
});
23+
it("should not retry on 200", async () => {
24+
const client = new XRayClient({
25+
requestHandler: {
26+
handle: () => Promise.resolve(mockSuccess),
27+
},
28+
});
29+
const response = await client.send(getInsightCommand);
30+
expect(response.$metadata.httpStatusCode).toBe(200);
31+
expect(response.$metadata.attempts).toBe(1);
32+
expect(response.$metadata.totalRetryDelay).toBe(0);
33+
});
34+
it("should retry until success", async () => {
35+
const mockHandle = jest
36+
.fn()
37+
.mockResolvedValueOnce(mockThrottled)
38+
.mockResolvedValueOnce(mockThrottled)
39+
.mockResolvedValueOnce(mockSuccess);
40+
const client = new XRayClient({
41+
requestHandler: {
42+
handle: mockHandle,
43+
},
44+
});
45+
const response = await client.send(getInsightCommand);
46+
expect(response.$metadata.httpStatusCode).toBe(200);
47+
expect(mockHandle).toBeCalledTimes(3);
48+
expect(response.$metadata.attempts).toBe(3);
49+
expect(response.$metadata.totalRetryDelay).toBeGreaterThan(300);
50+
});
51+
it("should retry until attemps are exhausted", async () => {
52+
const expectedException = new ThrottledException({
53+
$metadata: {
54+
httpStatusCode: 429,
55+
},
56+
message: "UnknownError",
57+
});
58+
const client = new XRayClient({
59+
requestHandler: {
60+
handle: () => Promise.resolve(mockThrottled),
61+
},
62+
});
63+
try {
64+
await client.send(getInsightCommand);
65+
} catch (error) {
66+
expect(error).toStrictEqual(expectedException);
67+
expect(error.$metadata.httpStatusCode).toBe(429);
68+
expect(error.$metadata.attempts).toBe(4);
69+
expect(error.$metadata.totalRetryDelay).toBeGreaterThan(300);
70+
}
71+
});
72+
});
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"outDir": "dist-cjs"
5+
}
6+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"lib": ["dom"],
5+
"module": "esnext",
6+
"outDir": "dist-es"
7+
}
8+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"extends": "@tsconfig/node14/tsconfig.json",
3+
"compilerOptions": {
4+
"downlevelIteration": true,
5+
"importHelpers": true,
6+
"incremental": true,
7+
"removeComments": true,
8+
"resolveJsonModule": true,
9+
"rootDir": "src",
10+
"useUnknownInCatchVariables": false
11+
},
12+
"exclude": ["test/"]
13+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "./tsconfig",
3+
"compilerOptions": {
4+
"removeComments": false,
5+
"declaration": true,
6+
"declarationDir": "dist-types",
7+
"emitDeclarationOnly": true
8+
},
9+
"exclude": ["test/**/*", "dist-types/**/*"]
10+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "../../typedoc.client.json"
3+
}

0 commit comments

Comments
 (0)