Skip to content

Commit 7f19c17

Browse files
feat(util-waiter): include reason on waiter result (#3534)
* chore(util-waiter): add unit tests for reason * feat(util-waiter): include reason on waiter result Co-authored-by: Eduardo Rodrigues <[email protected]>
1 parent 90c6b11 commit 7f19c17

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/util-waiter/src/poller.spec.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,19 @@ describe(runPolling.name, () => {
1919
};
2020
const failureState = {
2121
state: WaiterState.FAILURE,
22+
reason: {
23+
mockedReason: "some-failure-value",
24+
},
2225
};
2326
const successState = {
2427
state: WaiterState.SUCCESS,
28+
reason: {
29+
mockedReason: "some-success-value",
30+
},
2531
};
2632
const retryState = {
2733
state: WaiterState.RETRY,
34+
reason: undefined,
2835
};
2936
const timeoutState = {
3037
state: WaiterState.TIMEOUT,
@@ -42,7 +49,7 @@ describe(runPolling.name, () => {
4249
jest.spyOn(global.Math, "random").mockRestore();
4350
});
4451

45-
it("should returns state in case of failure", async () => {
52+
it("should returns state and reason in case of failure", async () => {
4653
mockAcceptorChecks = jest.fn().mockResolvedValueOnce(failureState);
4754
await expect(runPolling(config, input, mockAcceptorChecks)).resolves.toStrictEqual(failureState);
4855

@@ -52,7 +59,7 @@ describe(runPolling.name, () => {
5259
expect(sleep).toHaveBeenCalledTimes(0);
5360
});
5461

55-
it("returns state in case of success", async () => {
62+
it("returns state and reason in case of success", async () => {
5663
mockAcceptorChecks = jest.fn().mockResolvedValueOnce(successState);
5764
await expect(runPolling(config, input, mockAcceptorChecks)).resolves.toStrictEqual(successState);
5865
expect(mockAcceptorChecks).toHaveBeenCalled();

packages/util-waiter/src/poller.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ export const runPolling = async <Client, Input>(
2525
input: Input,
2626
acceptorChecks: (client: Client, input: Input) => Promise<WaiterResult>
2727
): Promise<WaiterResult> => {
28-
const { state } = await acceptorChecks(client, input);
28+
const { state, reason } = await acceptorChecks(client, input);
2929
if (state !== WaiterState.RETRY) {
30-
return { state };
30+
return { state, reason };
3131
}
3232

3333
let currentAttempt = 1;
@@ -46,9 +46,9 @@ export const runPolling = async <Client, Input>(
4646
return { state: WaiterState.TIMEOUT };
4747
}
4848
await sleep(delay);
49-
const { state } = await acceptorChecks(client, input);
49+
const { state, reason } = await acceptorChecks(client, input);
5050
if (state !== WaiterState.RETRY) {
51-
return { state };
51+
return { state, reason };
5252
}
5353

5454
currentAttempt += 1;

0 commit comments

Comments
 (0)