Skip to content
Closed
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
1 change: 0 additions & 1 deletion packages/middleware-retry/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"license": "Apache-2.0",
"dependencies": {
"@aws-sdk/protocol-http": "1.0.0-gamma.2",
"@aws-sdk/retry-config-provider": "1.0.0-gamma.1",
"@aws-sdk/service-error-classification": "1.0.0-gamma.2",
"@aws-sdk/types": "1.0.0-gamma.2",
"react-native-get-random-values": "^1.4.0",
Expand Down
41 changes: 0 additions & 41 deletions packages/middleware-retry/src/defaultStrategy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import { StandardRetryStrategy, RetryQuota } from "./defaultStrategy";
import { getDefaultRetryQuota } from "./defaultRetryQuota";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { v4 } from "uuid";
import { DEFAULT_MAX_ATTEMPTS } from "@aws-sdk/retry-config-provider";

jest.mock("@aws-sdk/service-error-classification");
jest.mock("./delayDecider");
Expand Down Expand Up @@ -477,44 +476,4 @@ describe("defaultStrategy", () => {
((isInstance as unknown) as jest.Mock).mockReturnValue(false);
});
});

describe("defaults maxAttempts to DEFAULT_MAX_ATTEMPTS", () => {
it("when maxAttemptsProvider throws error", async () => {
const { isInstance } = HttpRequest;
((isInstance as unknown) as jest.Mock).mockReturnValue(true);

next = jest.fn((args) => {
expect(args.request.headers["amz-sdk-request"]).toBe(`attempt=1; max=${DEFAULT_MAX_ATTEMPTS}`);
return Promise.resolve({
response: "mockResponse",
output: { $metadata: {} },
});
});

const retryStrategy = new StandardRetryStrategy(() => Promise.reject("ERROR"));
await retryStrategy.retry(next, { request: { headers: {} } } as any);

expect(next).toHaveBeenCalledTimes(1);
((isInstance as unknown) as jest.Mock).mockReturnValue(false);
});

it("when parseInt fails on maxAttemptsProvider", async () => {
const { isInstance } = HttpRequest;
((isInstance as unknown) as jest.Mock).mockReturnValue(true);

next = jest.fn((args) => {
expect(args.request.headers["amz-sdk-request"]).toBe(`attempt=1; max=${DEFAULT_MAX_ATTEMPTS}`);
return Promise.resolve({
response: "mockResponse",
output: { $metadata: {} },
});
});

const retryStrategy = new StandardRetryStrategy(() => Promise.resolve("not-a-number"));
await retryStrategy.retry(next, { request: { headers: {} } } as any);

expect(next).toHaveBeenCalledTimes(1);
((isInstance as unknown) as jest.Mock).mockReturnValue(false);
});
});
});
14 changes: 1 addition & 13 deletions packages/middleware-retry/src/defaultStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { FinalizeHandler, MetadataBearer, FinalizeHandlerArguments, RetryStrateg
import { getDefaultRetryQuota } from "./defaultRetryQuota";
import { HttpRequest } from "@aws-sdk/protocol-http";
import { v4 } from "uuid";
import { DEFAULT_MAX_ATTEMPTS } from "@aws-sdk/retry-config-provider";

/**
* Determines whether an error is retryable based on the number of retries
Expand Down Expand Up @@ -74,17 +73,6 @@ export class StandardRetryStrategy implements RetryStrategy {
return attempts < maxAttempts && this.retryDecider(error) && this.retryQuota.hasRetryTokens(error);
}

private async getMaxAttempts() {
let maxAttemptsStr: string;
try {
maxAttemptsStr = await this.maxAttemptsProvider();
} catch (error) {
maxAttemptsStr = DEFAULT_MAX_ATTEMPTS;
}
const maxAttempts = parseInt(maxAttemptsStr);
return Number.isNaN(maxAttempts) ? parseInt(DEFAULT_MAX_ATTEMPTS) : maxAttempts;
}

async retry<Input extends object, Ouput extends MetadataBearer>(
next: FinalizeHandler<Input, Ouput>,
args: FinalizeHandlerArguments<Input>
Expand All @@ -93,7 +81,7 @@ export class StandardRetryStrategy implements RetryStrategy {
let attempts = 0;
let totalDelay = 0;

const maxAttempts = await this.getMaxAttempts();
const maxAttempts = parseInt(await this.maxAttemptsProvider());

const { request } = args;
if (HttpRequest.isInstance(request)) {
Expand Down