forked from janus-idp/backstage-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(orchestrator): increase the number of attempts to fetch the insta…
…nce after execution (janus-idp#1301) fix(orchestrator): increase the number of attempts to fetch the instance
- Loading branch information
Showing
3 changed files
with
57 additions
and
10 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { retryAsyncFunction } from './Helper'; | ||
|
||
describe('retryAsyncFunction', () => { | ||
const successfulResponse = 'Success'; | ||
it('should be successful in the first attempt', async () => { | ||
const asyncFnSuccess = jest.fn().mockResolvedValueOnce(successfulResponse); | ||
|
||
const result = await retryAsyncFunction({ | ||
asyncFn: asyncFnSuccess, | ||
maxAttempts: 3, | ||
delayMs: 100, | ||
}); | ||
|
||
expect(result).toBe(successfulResponse); | ||
expect(asyncFnSuccess).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('should throw an error after maximum attempts', async () => { | ||
const asyncFnFailure = jest.fn().mockResolvedValue(undefined); | ||
|
||
await expect( | ||
retryAsyncFunction({ | ||
asyncFn: asyncFnFailure, | ||
maxAttempts: 5, | ||
delayMs: 100, | ||
}), | ||
).rejects.toThrow(); | ||
|
||
expect(asyncFnFailure).toHaveBeenCalledTimes(5); | ||
}); | ||
|
||
it('should retry until successful after getting some undefined responses', async () => { | ||
const asyncFns = jest | ||
.fn() | ||
.mockResolvedValueOnce(undefined) | ||
.mockResolvedValueOnce(undefined) | ||
.mockResolvedValueOnce(undefined) | ||
.mockResolvedValueOnce(successfulResponse); | ||
|
||
const result = await retryAsyncFunction({ | ||
asyncFn: asyncFns, | ||
maxAttempts: 5, | ||
delayMs: 100, | ||
}); | ||
|
||
expect(result).toBe(successfulResponse); | ||
expect(asyncFns).toHaveBeenCalledTimes(4); | ||
}); | ||
}); |
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
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