Skip to content

Commit

Permalink
feat: add retries for hard failures
Browse files Browse the repository at this point in the history
  • Loading branch information
agoldis committed Aug 31, 2024
1 parent bfb735d commit d5bbdbb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
5 changes: 4 additions & 1 deletion examples/webapp/currents.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,8 @@ module.exports = {
? "Ij0RfK"
: "Ij0RfK",
// cloudServiceUrl: "http://localhost:1234",
userAgent: "custom",
// userAgent: "custom",
retry: {
hardFailureMaxRetries: 2,
},
};
5 changes: 5 additions & 0 deletions packages/cypress-cloud/lib/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ export type E2EConfig = {
export type ComponentConfig = {
batchSize: number;
};

type RetryConfig = {
hardFailureMaxRetries: number;
};
export type CurrentsConfig = {
projectId?: string;
recordKey?: string;
cloudServiceUrl: string;
e2e: E2EConfig;
component: ComponentConfig;
networkHeaders?: Record<string, string>;
retry?: RetryConfig;
};

let _config: CurrentsConfig | null = null;
Expand Down
35 changes: 33 additions & 2 deletions packages/cypress-cloud/lib/cypress/cypress.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
} from "cypress-cloud/types";
import Debug from "debug";
import _ from "lodash";
import { getCypressRunAPIParams } from "../config";
import { getCurrentsConfig, getCypressRunAPIParams } from "../config";
import { safe } from "../lang";
import { warn } from "../log";
import { getWSSPort } from "../ws";
Expand Down Expand Up @@ -53,8 +53,38 @@ export async function runSpecFile(
},
spec,
};

debug("running cypress with options %o", options);
const result = await cypress.run(options);
let result = await cypress.run(options);

let retries = 0;
const currentsConfig = await getCurrentsConfig();
while (
currentsConfig.retry &&
retries < currentsConfig.retry.hardFailureMaxRetries &&
result.status === "failed"
) {
warn("Cypress runner failed with message: %s", result.message);
warn(
"[retry %d/%d] Retrying the following spec files because of retry config: %s",
retries + 1,
currentsConfig.retry.hardFailureMaxRetries,
spec
.split(",")
.map((i) => `\n - ${i}`)
.join("")
);
result = await cypress.run(options);
retries++;
}

if (currentsConfig.retry && retries > 0) {
warn(
"Exhausted max retries: %d/%d",
retries,
currentsConfig.retry.hardFailureMaxRetries
);
}

if (result.status === "failed") {
warn('Cypress runner failed with message: "%s"', result.message);
Expand All @@ -66,6 +96,7 @@ export async function runSpecFile(
.join("")
);
}

debug("cypress run result %o", result);
return result;
}
Expand Down

0 comments on commit d5bbdbb

Please sign in to comment.