Formatting
This commit is contained in:
@@ -1,6 +1,10 @@
|
||||
import { expect, test, vi } from 'vitest';
|
||||
import { ExponentialBackoff } from '../source/exponential-backoff.ts';
|
||||
import { ExponentialBackoffMaxRetriesHitError, ExponentialBackoffNumberNotFiniteError, ExponentialBackoffStoppedRetriesError } from '../source/errors.ts';
|
||||
import {
|
||||
ExponentialBackoffMaxRetriesHitError,
|
||||
ExponentialBackoffNumberNotFiniteError,
|
||||
ExponentialBackoffStoppedRetriesError,
|
||||
} from '../source/errors.ts';
|
||||
|
||||
/**
|
||||
* A valid options object that satisfies {@link ExponentialBackoff.validateOptions}.
|
||||
@@ -589,13 +593,16 @@ const testExponentialBackoffCalculateDelayDoesNotResultInNaN = (): void => {
|
||||
const largeNumber = 1_000_000_000_000;
|
||||
|
||||
// Test the calculateDelay function
|
||||
const result = ExponentialBackoff.calculateDelay({
|
||||
baseDelay: 10000,
|
||||
growthRate: largeNumber,
|
||||
jitter: 0,
|
||||
maxDelay: 10_000,
|
||||
maxAttempts: largeNumber,
|
||||
}, largeNumber);
|
||||
const result = ExponentialBackoff.calculateDelay(
|
||||
{
|
||||
baseDelay: 10000,
|
||||
growthRate: largeNumber,
|
||||
jitter: 0,
|
||||
maxDelay: 10_000,
|
||||
maxAttempts: largeNumber,
|
||||
},
|
||||
largeNumber,
|
||||
);
|
||||
|
||||
// Test to ensure it was bounded to the max delay
|
||||
expect(result).toBe(10_000);
|
||||
@@ -615,6 +622,7 @@ const testExponentialBackoffConstructorDoesNotCauseErrorDuringSpread = async ():
|
||||
// @ts-expect-error - Passing undefined is allowed if the exactOptionalPropertyTypes option is set to false in TS Compiler options.
|
||||
expect(() => new ExponentialBackoff(options)).toThrow(ExponentialBackoffNumberNotFiniteError);
|
||||
};
|
||||
|
||||
const runTests = async (): Promise<void> => {
|
||||
test('ExponentialBackoff.run: delegates to a new instance using default options', testExponentialBackoffRunUsesDefaultOptions);
|
||||
test('ExponentialBackoff.run: retries and succeeds with partial options', testExponentialBackoffRunWithPartialOptions);
|
||||
@@ -641,7 +649,10 @@ const runTests = async (): Promise<void> => {
|
||||
test('ExponentialBackoff.validateOptions: rejects Infinity', testExponentialBackoffValidateOptionsRejectsNonFiniteValues);
|
||||
test('ExponentialBackoff.validateOptions: rejects non-integer values', testExponentialBackoffValidateOptionsRejectsNonIntegerValues);
|
||||
test('ExponentialBackoff.validateOptions: rejects NaN', testExponentialBackoffValidateOptionsRejectsNaN);
|
||||
test('ExponentialBackoff: calculateDelay does not result in NaN from extremely large growth rates and attempts', testExponentialBackoffCalculateDelayDoesNotResultInNaN);
|
||||
test(
|
||||
'ExponentialBackoff: calculateDelay does not result in NaN from extremely large growth rates and attempts',
|
||||
testExponentialBackoffCalculateDelayDoesNotResultInNaN,
|
||||
);
|
||||
test('ExponentialBackoff: constructor does not cause an error during spread', testExponentialBackoffConstructorDoesNotCauseErrorDuringSpread);
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user