Skip to content

Commit

Permalink
fix(util-retry): remove deprecated parts of StandardRetryToken
Browse files Browse the repository at this point in the history
  • Loading branch information
kuhe committed May 25, 2023
1 parent 7de64e2 commit 2bd3423
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 140 deletions.
22 changes: 0 additions & 22 deletions packages/types/src/retry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,28 +98,6 @@ export interface StandardRetryToken extends RetryToken {
* @returns the cost of the last retry attempt.
*/
getLastRetryCost(): number | undefined;

/**
* @deprecated StandardRetryStrategy will track retry capacity.
*
* @param errorType - derives the cost of the retry to check whether capacity remains.
* @returns wheather there is enough remaining capacity to retry the given error.
*/
hasRetryTokens(errorType: RetryErrorType): boolean;

/**
* @deprecated StandardRetryStrategy will track retry capacity.
* @returns the number of available tokens.
*/
getRetryTokenCount(errorInfo: RetryErrorInfo): number;

/**
* @deprecated use \@aws-sdk/util-retry's StandardRetryStrategy#recordSuccess.
*
* Warning: this method is no-op on StandardRetryTokens provided by
* StandardRetryStrategy in \@aws-sdk/util-retry.
*/
releaseRetryTokens(amount?: number): void;
}

/**
Expand Down
5 changes: 1 addition & 4 deletions packages/util-retry/src/AdaptiveRetryStrategy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { RetryErrorInfo, RetryErrorType, StandardRetryToken } from "@aws-sdk/types";
import { RetryErrorInfo, StandardRetryToken } from "@aws-sdk/types";

import { AdaptiveRetryStrategy } from "./AdaptiveRetryStrategy";
import { RETRY_MODES } from "./config";
Expand All @@ -17,10 +17,7 @@ describe(AdaptiveRetryStrategy.name, () => {
updateClientSendingRate: jest.fn(),
};
const mockRetryToken: StandardRetryToken = {
hasRetryTokens: (errorType: RetryErrorType) => true,
getLastRetryCost: () => 1,
getRetryTokenCount: (errorInfo?: RetryErrorInfo) => 1,
releaseRetryTokens: (amount: number) => {},
getRetryCount: () => 1,
getRetryDelay: () => 1,
};
Expand Down
87 changes: 1 addition & 86 deletions packages/util-retry/src/defaultRetryToken.spec.ts
Original file line number Diff line number Diff line change
@@ -1,80 +1,9 @@
import { RetryErrorType } from "@aws-sdk/types";

import {
DEFAULT_RETRY_DELAY_BASE,
INITIAL_RETRY_TOKENS,
MAXIMUM_RETRY_DELAY,
NO_RETRY_INCREMENT,
RETRY_COST,
} from "./constants";
import { DEFAULT_RETRY_DELAY_BASE, INITIAL_RETRY_TOKENS, MAXIMUM_RETRY_DELAY } from "./constants";
import { createDefaultRetryToken } from "./defaultRetryToken";

jest.mock("./defaultRetryBackoffStrategy");

describe("defaultRetryToken", () => {
const transientErrorType = "TRANSIENT" as RetryErrorType;
const nonTransientErrorType = "THROTTLING" as RetryErrorType;

const getDrainedRetryToken = (targetCapacity: number) => {
const retryToken = createDefaultRetryToken({
availableCapacity: targetCapacity,
retryDelay: DEFAULT_RETRY_DELAY_BASE,
retryCount: 0,
});
return retryToken;
};

describe("custom initial retry tokens", () => {
it("hasRetryTokens returns false if capacity is not available", () => {
const customRetryTokens = 5;
const retryToken = createDefaultRetryToken({
availableCapacity: customRetryTokens,
retryDelay: DEFAULT_RETRY_DELAY_BASE,
retryCount: 0,
});

expect(retryToken.hasRetryTokens(transientErrorType)).toBe(false);
});
});

describe("hasRetryTokens", () => {
describe("returns true if capacity is available", () => {
it("when it's transient error", () => {
const retryToken = createDefaultRetryToken({
availableCapacity: INITIAL_RETRY_TOKENS,
retryDelay: DEFAULT_RETRY_DELAY_BASE,
retryCount: 0,
});
expect(retryToken.hasRetryTokens(transientErrorType)).toBe(true);
});

it("when it's not transient error", () => {
const retryToken = createDefaultRetryToken({
availableCapacity: INITIAL_RETRY_TOKENS,
retryDelay: DEFAULT_RETRY_DELAY_BASE,
retryCount: 0,
});
expect(retryToken.hasRetryTokens(nonTransientErrorType)).toBe(true);
});
});

it("returns false if capacity is not available", () => {
const retryToken = getDrainedRetryToken(0);
expect(retryToken.hasRetryTokens(nonTransientErrorType)).toBe(false);
});
});

describe("getRetryTokenCount", () => {
it("returns retry tokens amount", () => {
const retryToken = createDefaultRetryToken({
availableCapacity: 123,
retryDelay: DEFAULT_RETRY_DELAY_BASE,
retryCount: 0,
});
expect(retryToken.getRetryTokenCount({ errorType: "TRANSIENT" })).toBe(123);
});
});

describe("getLastRetryCost", () => {
it("is undefined before an error is encountered", () => {
const retryToken = createDefaultRetryToken({
Expand Down Expand Up @@ -129,18 +58,4 @@ describe("defaultRetryToken", () => {
});
});
});

describe("releaseRetryToken", () => {
it("ensures availableCapacity is maxed at INITIAL_RETRY_TOKENS", () => {
const retryToken = createDefaultRetryToken({
availableCapacity: INITIAL_RETRY_TOKENS,
retryDelay: DEFAULT_RETRY_DELAY_BASE,
retryCount: 0,
});

retryToken.releaseRetryTokens();

expect(retryToken.getRetryTokenCount({ errorType: "TRANSIENT" })).toBe(INITIAL_RETRY_TOKENS);
});
});
});
30 changes: 2 additions & 28 deletions packages/util-retry/src/defaultRetryToken.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { RetryErrorInfo, RetryErrorType, StandardRetryToken } from "@aws-sdk/types";
import { StandardRetryToken } from "@aws-sdk/types";

import { MAXIMUM_RETRY_DELAY, RETRY_COST, TIMEOUT_RETRY_COST } from "./constants";
import { MAXIMUM_RETRY_DELAY } from "./constants";

/**
* @internal
*/
export const createDefaultRetryToken = ({
availableCapacity,
retryDelay,
retryCount,
lastRetryCost,
Expand All @@ -16,38 +15,13 @@ export const createDefaultRetryToken = ({
retryCount: number;
lastRetryCost?: number;
}): StandardRetryToken => {
const getCapacityAmount = (errorType: RetryErrorType) =>
errorType === "TRANSIENT" ? TIMEOUT_RETRY_COST : RETRY_COST;

const getRetryCount = (): number => retryCount;
const getRetryDelay = (): number => Math.min(MAXIMUM_RETRY_DELAY, retryDelay);
const getLastRetryCost = (): number | undefined => lastRetryCost;

/**
* @deprecated managed by StandardRetryStrategy.
*/
const hasRetryTokens = (errorType: RetryErrorType): boolean => {
return getCapacityAmount(errorType) <= availableCapacity;
};

/**
* @deprecated managed by StandardRetryStrategy.
*/
const getRetryTokenCount = (errorInfo?: RetryErrorInfo) => {
return availableCapacity;
};

/**
* @deprecated this is done in StandardRetryStrategy.recordSuccess.
*/
const releaseRetryTokens = (releaseAmount?: number) => {};

return {
getRetryCount,
getRetryDelay,
getLastRetryCost,
hasRetryTokens,
getRetryTokenCount,
releaseRetryTokens,
};
};

0 comments on commit 2bd3423

Please sign in to comment.