Created
November 16, 2022 16:30
-
-
Save lydemann/0411ec663d068c25ed3fe25b21f730a4 to your computer and use it in GitHub Desktop.
exponential-backoff-retry.spec.ts
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
import { fakeAsync, tick } from '@angular/core/testing'; | |
import { of, throwError } from 'rxjs'; | |
import { mergeMap } from 'rxjs/operators'; | |
import { | |
exponentialBackoffRetry, | |
RETRY_COUNT, | |
RETRY_TIME, | |
} from './exponential-backoff-retry'; | |
describe('exponentialBackoffRetry', () => { | |
it('should retry http GET with exponential backoff', fakeAsync(() => { | |
let callCount = 0; | |
of(() => {}) | |
.pipe( | |
mergeMap(() => { | |
callCount = callCount + 1; | |
return throwError(() => new Error('Some error')); | |
}), | |
exponentialBackoffRetry(RETRY_COUNT, RETRY_TIME), | |
) | |
.subscribe({ | |
error: () => { | |
// silence error in test | |
}, | |
}); | |
tick(RETRY_TIME); | |
tick(RETRY_TIME * 4); | |
tick(RETRY_TIME * 9); | |
expect(callCount).toBe(RETRY_COUNT + 1); | |
})); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment