diff options
| author | pack <pack@packgekko.xyz> | 2026-08-09 10:37:07 +0000 |
|---|---|---|
| committer | pack <pack@packgekko.xyz> | 2026-08-09 10:37:07 +0000 |
| commit | 55a4f1fc869e41aca748c63d3018f0448b1606e0 (patch) | |
| tree | d132d1d01772b6d53faee3e63c534dea5706b78a /node_modules/exponential-backoff/src/delay/always | |
| download | crud-55a4f1fc869e41aca748c63d3018f0448b1606e0.tar.gz | |
first commit
Diffstat (limited to 'node_modules/exponential-backoff/src/delay/always')
| -rw-r--r-- | node_modules/exponential-backoff/src/delay/always/always.delay.spec.ts | 65 | ||||
| -rw-r--r-- | node_modules/exponential-backoff/src/delay/always/always.delay.ts | 3 |
2 files changed, 68 insertions, 0 deletions
diff --git a/node_modules/exponential-backoff/src/delay/always/always.delay.spec.ts b/node_modules/exponential-backoff/src/delay/always/always.delay.spec.ts new file mode 100644 index 0000000..8a08cd8 --- /dev/null +++ b/node_modules/exponential-backoff/src/delay/always/always.delay.spec.ts @@ -0,0 +1,65 @@ +import { AlwaysDelay } from "./always.delay"; +import { IBackOffOptions, getSanitizedOptions } from "../../options"; + +describe(AlwaysDelay.name, () => { + let options: IBackOffOptions; + let delay: AlwaysDelay; + + function initClass() { + delay = new AlwaysDelay(options); + } + + beforeEach(() => { + options = getSanitizedOptions({}); + initClass(); + jest.useFakeTimers(); + }); + + it(`when calling #apply, the delay is equal to the starting delay`, async () => { + const spy = jest.fn(); + delay.apply().then(spy); + jest.runTimersToTime(options.startingDelay); + await Promise.resolve(); + + expect(spy).toHaveBeenCalledTimes(1); + }); + + it(`when the attempt number is 1, when calling #apply, + the delay is equal to the starting delay multiplied by the time multiple`, async () => { + delay.setAttemptNumber(1); + + const spy = jest.fn(); + delay.apply().then(spy); + jest.runTimersToTime(options.startingDelay * options.timeMultiple); + await Promise.resolve(); + + expect(spy).toHaveBeenCalledTimes(1); + }); + + it(`when the attempt number is 2, when calling #apply, + the delay is equal to the starting delay multiplied by the time multiple raised by the attempt number`, async () => { + const attemptNumber = 2; + delay.setAttemptNumber(attemptNumber); + + const spy = jest.fn(); + delay.apply().then(spy); + jest.runTimersToTime( + options.startingDelay * Math.pow(options.timeMultiple, attemptNumber) + ); + await Promise.resolve(); + + expect(spy).toHaveBeenCalledTimes(1); + }); + + it(`when the #maxDelay is less than #startingDelay, when calling #apply, + the delay is equal to the #maxDelay`, async () => { + options.maxDelay = options.startingDelay - 1; + + const spy = jest.fn(); + delay.apply().then(spy); + jest.runTimersToTime(options.maxDelay); + await Promise.resolve(); + + expect(spy).toHaveBeenCalledTimes(1); + }); +}); diff --git a/node_modules/exponential-backoff/src/delay/always/always.delay.ts b/node_modules/exponential-backoff/src/delay/always/always.delay.ts new file mode 100644 index 0000000..ec86c62 --- /dev/null +++ b/node_modules/exponential-backoff/src/delay/always/always.delay.ts @@ -0,0 +1,3 @@ +import { Delay } from "../delay.base"; + +export class AlwaysDelay extends Delay {}
\ No newline at end of file |