Skip to content

Commit

Permalink
fix: infinite loop with additional options without rateLimit (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
pashidlos authored Mar 8, 2021
1 parent 05e7e20 commit c45a2ff
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 16 deletions.
2 changes: 0 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
name: CI

on:
push:
branches: [master]
pull_request:
branches: [master]

Expand Down
4 changes: 1 addition & 3 deletions cypress/integration/regression.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ describe("Regression suite", () => {
cy.stub().as("trackFn").resolves(testRunResponce),
cy.stub().as("shouldStopFn").returns(false),
cy.stub().as("checkResult"),
{
retryLimit: 5,
}
5
);

cy.get("@trackFn").should("have.callCount", 6);
Expand Down
2 changes: 1 addition & 1 deletion lib/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export const addVrtTrackCommand = () =>
() => trackImage(subject, name, options),
(result) => shouldStopRetry(result),
(result) => checkResult(result),
options
options.retryLimit
);
}
);
14 changes: 4 additions & 10 deletions lib/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,16 @@ export const trackWithRetry = (
trackFn: () => Cypress.Chainable<TestRunResponse>,
shouldStopFn: (result: TestRunResponse) => boolean,
onStopFn: (result: TestRunResponse) => Cypress.Chainable<unknown>,
options: {
retryLimit: number;
} = {
retryLimit: 2,
}
retryLimit: number = 2
): Cypress.Chainable<unknown> => {
return trackFn().then((result) => {
if (options.retryLimit <= 0 || shouldStopFn(result)) {
if (retryLimit <= 0 || shouldStopFn(result)) {
onStopFn(result);
return;
}

log(`Diff found... Remaining retry attempts **${options.retryLimit}**`);
return trackWithRetry(trackFn, shouldStopFn, onStopFn, {
retryLimit: options.retryLimit - 1,
});
log(`Diff found... Remaining retry attempts **${retryLimit}**`);
return trackWithRetry(trackFn, shouldStopFn, onStopFn, retryLimit - 1);
});
};

Expand Down

0 comments on commit c45a2ff

Please sign in to comment.