Skip to content

Commit

Permalink
feat(middleware-retry): add integration tests
Browse files Browse the repository at this point in the history
  • Loading branch information
srchase committed Dec 9, 2022
1 parent 071e6b1 commit a8d783d
Show file tree
Hide file tree
Showing 10 changed files with 191 additions and 0 deletions.
4 changes: 4 additions & 0 deletions private/aws-client-retry-test/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Change Log

All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5 changes: 5 additions & 0 deletions private/aws-client-retry-test/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const base = require("../../jest.config.base.js");

module.exports = {
...base,
};
61 changes: 61 additions & 0 deletions private/aws-client-retry-test/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"name": "@aws-sdk/aws-client-retry-test",
"description": "Integration test suite for middleware-retry",
"version": "3.0.0",
"scripts": {
"build": "concurrently 'yarn:build:cjs' 'yarn:build:es' 'yarn:build:types'",
"build:cjs": "tsc -p tsconfig.cjs.json",
"build:docs": "typedoc",
"build:es": "tsc -p tsconfig.es.json",
"build:include:deps": "lerna run --scope $npm_package_name --include-dependencies build",
"build:types": "tsc -p tsconfig.types.json",
"build:types:downlevel": "downlevel-dts dist-types dist-types/ts3.4",
"clean": "rimraf ./dist-* && rimraf *.tsbuildinfo",
"test": "jest --coverage --passWithNoTests"
},
"main": "./dist-cjs/index.js",
"types": "./dist-types/index.d.ts",
"module": "./dist-es/index.js",
"sideEffects": false,
"dependencies": {
"@aws-sdk/client-xray": "*",
"tslib": "^2.3.1"
},
"devDependencies": {
"@tsconfig/node14": "1.0.3",
"@types/node": "^12.7.5",
"concurrently": "7.0.0",
"downlevel-dts": "0.10.1",
"typedoc": "0.19.2",
"typescript": "~4.6.2"
},
"overrides": {
"typedoc": {
"typescript": "~4.6.2"
}
},
"engines": {
"node": ">=14.0.0"
},
"typesVersions": {
"<4.0": {
"dist-types/*": [
"dist-types/ts3.4/*"
]
}
},
"files": [
"dist-*"
],
"author": {
"name": "AWS SDK for JavaScript Team",
"url": "https://aws.amazon.com/javascript/"
},
"license": "Apache-2.0",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/aws/aws-sdk-js-v3.git",
"directory": "private/aws-client-api-test"
}
}
10 changes: 10 additions & 0 deletions private/aws-client-retry-test/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# @aws-sdk/aws-client-api-test

This is not a runtime or published package.

This is a test spec.

The purpose of this package is to perform integration tests on the retry-middleware.

If tests in this package fail, the author should either fix their changes such that the API contract
is maintained, or appropriately announce and safely deprecate the interfaces affected by incoming changes.
71 changes: 71 additions & 0 deletions private/aws-client-retry-test/src/ClientRetryTest.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { GetInsightCommand, ThrottledException, XRayClient } from "@aws-sdk/client-xray";
import { HttpResponse } from "@aws-sdk/protocol-http";
import { RequestHandlerOutput } from "@aws-sdk/types";
import { Readable } from "stream";

describe("Middleware-retry integration tests", () => {
const mockThrottled: RequestHandlerOutput<HttpResponse> = {
response: new HttpResponse({
statusCode: 429,
headers: { "x-amzn-errortype": "ThrottledException" },
body: Readable.from([""]),
}),
};
const mockSuccess: RequestHandlerOutput<HttpResponse> = {
response: new HttpResponse({
statusCode: 200,
body: Readable.from(""),
}),
};
const getInsightCommand = new GetInsightCommand({
InsightId: "foo",
});
it("should not retry on 200", async () => {
const client = new XRayClient({
requestHandler: {
handle: () => Promise.resolve(mockSuccess),
},
});
const response = await client.send(getInsightCommand);
expect(response.$metadata.httpStatusCode).toBe(200);
expect(response.$metadata.attempts).toBeUndefined();
expect(response.$metadata.totalRetryDelay).toBeUndefined();
});
it("should retry until success", async () => {
const mockHandle = jest
.fn()
.mockResolvedValueOnce(mockThrottled)
.mockResolvedValueOnce(mockThrottled)
.mockResolvedValueOnce(mockSuccess);
const client = new XRayClient({
requestHandler: {
handle: mockHandle,
},
});
const response = await client.send(getInsightCommand);
console.log(response);
expect(response.$metadata.httpStatusCode).toBe(200);
expect(mockHandle).toBeCalledTimes(3);
});
it("should retry until attemps are exhausted", async () => {
const expectedException = new ThrottledException({
$metadata: {
httpStatusCode: 429,
},
message: "UnknownError",
});
const client = new XRayClient({
requestHandler: {
handle: () => Promise.resolve(mockThrottled),
},
});
try {
await client.send(getInsightCommand);
} catch (error) {
expect(error).toStrictEqual(expectedException);
expect(error.$metadata.httpStatusCode).toBe(429);
expect(error.$metadata.attempts).toBe(3);
expect(error.$metadata.totalRetryDelay).toBeGreaterThan(300);
}
});
});
6 changes: 6 additions & 0 deletions private/aws-client-retry-test/tsconfig.cjs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"outDir": "dist-cjs"
}
}
8 changes: 8 additions & 0 deletions private/aws-client-retry-test/tsconfig.es.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"lib": ["dom"],
"module": "esnext",
"outDir": "dist-es"
}
}
13 changes: 13 additions & 0 deletions private/aws-client-retry-test/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "@tsconfig/node14/tsconfig.json",
"compilerOptions": {
"downlevelIteration": true,
"importHelpers": true,
"incremental": true,
"removeComments": true,
"resolveJsonModule": true,
"rootDir": "src",
"useUnknownInCatchVariables": false
},
"exclude": ["test/"]
}
10 changes: 10 additions & 0 deletions private/aws-client-retry-test/tsconfig.types.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "./tsconfig",
"compilerOptions": {
"removeComments": false,
"declaration": true,
"declarationDir": "dist-types",
"emitDeclarationOnly": true
},
"exclude": ["test/**/*", "dist-types/**/*"]
}
3 changes: 3 additions & 0 deletions private/aws-client-retry-test/typedoc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "../../typedoc.client.json"
}

0 comments on commit a8d783d

Please sign in to comment.