From d5bbdbb8b2273645716a1902484fbdb825dd859c Mon Sep 17 00:00:00 2001 From: Andrew Goldis Date: Sat, 31 Aug 2024 13:03:49 -0700 Subject: [PATCH 1/3] feat: add retries for hard failures --- examples/webapp/currents.config.js | 5 ++- packages/cypress-cloud/lib/config/config.ts | 5 +++ packages/cypress-cloud/lib/cypress/cypress.ts | 35 +++++++++++++++++-- 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/examples/webapp/currents.config.js b/examples/webapp/currents.config.js index 332fe16b..c6fe8fc0 100644 --- a/examples/webapp/currents.config.js +++ b/examples/webapp/currents.config.js @@ -9,5 +9,8 @@ module.exports = { ? "Ij0RfK" : "Ij0RfK", // cloudServiceUrl: "http://localhost:1234", - userAgent: "custom", + // userAgent: "custom", + retry: { + hardFailureMaxRetries: 2, + }, }; diff --git a/packages/cypress-cloud/lib/config/config.ts b/packages/cypress-cloud/lib/config/config.ts index e1d0cf82..08c2317a 100644 --- a/packages/cypress-cloud/lib/config/config.ts +++ b/packages/cypress-cloud/lib/config/config.ts @@ -14,6 +14,10 @@ export type E2EConfig = { export type ComponentConfig = { batchSize: number; }; + +type RetryConfig = { + hardFailureMaxRetries: number; +}; export type CurrentsConfig = { projectId?: string; recordKey?: string; @@ -21,6 +25,7 @@ export type CurrentsConfig = { e2e: E2EConfig; component: ComponentConfig; networkHeaders?: Record; + retry?: RetryConfig; }; let _config: CurrentsConfig | null = null; diff --git a/packages/cypress-cloud/lib/cypress/cypress.ts b/packages/cypress-cloud/lib/cypress/cypress.ts index 5ad3c30e..24a18194 100644 --- a/packages/cypress-cloud/lib/cypress/cypress.ts +++ b/packages/cypress-cloud/lib/cypress/cypress.ts @@ -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"; @@ -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); @@ -66,6 +96,7 @@ export async function runSpecFile( .join("") ); } + debug("cypress run result %o", result); return result; } From 7cf85746133a42f9cec3d66113c4fab52c690938 Mon Sep 17 00:00:00 2001 From: Andrew Goldis Date: Sat, 31 Aug 2024 13:05:52 -0700 Subject: [PATCH 2/3] chore: use default 0 for currentsConfig.retry.hardFailureMaxRetries --- packages/cypress-cloud/lib/cypress/cypress.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/packages/cypress-cloud/lib/cypress/cypress.ts b/packages/cypress-cloud/lib/cypress/cypress.ts index 24a18194..c9dfce9e 100644 --- a/packages/cypress-cloud/lib/cypress/cypress.ts +++ b/packages/cypress-cloud/lib/cypress/cypress.ts @@ -59,9 +59,10 @@ export async function runSpecFile( let retries = 0; const currentsConfig = await getCurrentsConfig(); + while ( currentsConfig.retry && - retries < currentsConfig.retry.hardFailureMaxRetries && + retries < (currentsConfig.retry.hardFailureMaxRetries ?? 0) && result.status === "failed" ) { warn("Cypress runner failed with message: %s", result.message); From f89a51c785d41446ebb5d9109e23cfe6aad5a604 Mon Sep 17 00:00:00 2001 From: Andrew Goldis Date: Sat, 31 Aug 2024 13:10:53 -0700 Subject: [PATCH 3/3] chore: add retries to README --- .github/README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/README.md b/.github/README.md index 918d1a8a..739d40d6 100644 --- a/.github/README.md +++ b/.github/README.md @@ -118,7 +118,7 @@ module.exports = { // Additional headers for network requests, undefined by default networkHeaders: { "User-Agent": "Custom", - "x-ms-blob-type": "BlockBlob" + "x-ms-blob-type": "BlockBlob", }, e2e: { batchSize: 3, // orchestration batch size for e2e tests (Currents only, read below) @@ -126,6 +126,9 @@ module.exports = { component: { batchSize: 5, // orchestration batch size for component tests (Currents only, read below) }, + retry: { + hardFailureMaxRetries: 2, // max retries for hard Cypress failures, a hard failure is when Cyrpess crashes and doesn't report back any results (see https://docs.cypress.io/guides/guides/module-api#Handling-errors) + }, }; ``` @@ -162,7 +165,7 @@ The configuration variables will resolve as follows: ## Batched Orchestration -This package uses its own orchestration and reporting protocol that is independent of cypress native implementation. The new [orchestration protocol]([https://currents.dev/readme/integration-with-cypress/cypress-cloud#batched-orchestration](https://currents.dev/readme/integration-with-cypress/cypress-cloud/batched-orchestration)) uses cypress in "offline" mode and allows batching multiple spec files for better efficiency. You can adjust the batching configuration in `currents.config.js` and use different values for e2e and component tests. +This package uses its own orchestration and reporting protocol that is independent of cypress native implementation. The new [orchestration protocol](<[https://currents.dev/readme/integration-with-cypress/cypress-cloud#batched-orchestration](https://currents.dev/readme/integration-with-cypress/cypress-cloud/batched-orchestration)>) uses cypress in "offline" mode and allows batching multiple spec files for better efficiency. You can adjust the batching configuration in `currents.config.js` and use different values for e2e and component tests. ## API