-
Notifications
You must be signed in to change notification settings - Fork 587
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(middleware-retry): add integration tests
- Loading branch information
Showing
10 changed files
with
192 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
const base = require("../../jest.config.base.js"); | ||
|
||
module.exports = { | ||
...base, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
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).toBe(1); | ||
expect(response.$metadata.totalRetryDelay).toBe(0); | ||
}); | ||
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); | ||
expect(response.$metadata.httpStatusCode).toBe(200); | ||
expect(mockHandle).toBeCalledTimes(3); | ||
expect(response.$metadata.attempts).toBe(3); | ||
expect(response.$metadata.totalRetryDelay).toBeGreaterThan(300); | ||
}); | ||
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(4); | ||
expect(error.$metadata.totalRetryDelay).toBeGreaterThan(300); | ||
} | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"extends": "./tsconfig", | ||
"compilerOptions": { | ||
"outDir": "dist-cjs" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"extends": "./tsconfig", | ||
"compilerOptions": { | ||
"lib": ["dom"], | ||
"module": "esnext", | ||
"outDir": "dist-es" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/**/*"] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"extends": "../../typedoc.client.json" | ||
} |