Skip to content

Commit

Permalink
fix: retry instance creation when the Cloud request fails (#31019)
Browse files Browse the repository at this point in the history
* fix: retry instance creation when the Cloud request fails

* cleanup defunct branches in circleci workflows.yml

* rm unintentional delta in system test snapshot
  • Loading branch information
cacieprins authored Feb 4, 2025
1 parent 37ad232 commit 46a473d
Show file tree
Hide file tree
Showing 5 changed files with 69 additions and 69 deletions.
4 changes: 1 addition & 3 deletions .circleci/workflows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ mainBuildFilters: &mainBuildFilters
- /^release\/\d+\.\d+\.\d+$/
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- 'update-v8-snapshot-cache-on-develop'
- 'cacie/30927/retry-error-codeframe'

# usually we don't build Mac app - it takes a long time
# but sometimes we want to really confirm we are doing the right thing
Expand All @@ -44,7 +43,6 @@ macWorkflowFilters: &darwin-workflow-filters
- equal: [ develop, << pipeline.git.branch >> ]
# use the following branch as well to ensure that v8 snapshot cache updates are fully tested
- equal: [ 'update-v8-snapshot-cache-on-develop', << pipeline.git.branch >> ]
- equal: [ 'cacie/30927/retry-error-codeframe', << pipeline.git.branch >> ]
- equal: [ 'chore/browser_spike', << pipeline.git.branch >> ]
- matches:
pattern: /^release\/\d+\.\d+\.\d+$/
Expand Down Expand Up @@ -155,7 +153,7 @@ commands:
name: Set environment variable to determine whether or not to persist artifacts
command: |
echo "Setting SHOULD_PERSIST_ARTIFACTS variable"
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* && "$CIRCLE_BRANCH" != "cacie/30927/retry-error-codeframe" ]]; then
echo 'if ! [[ "$CIRCLE_BRANCH" != "develop" && "$CIRCLE_BRANCH" != "release/"* ]]; then
export SHOULD_PERSIST_ARTIFACTS=true
fi' >> "$BASH_ENV"
# You must run `setup_should_persist_artifacts` command and be using bash before running this command
Expand Down
1 change: 1 addition & 0 deletions cli/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ _Released 2/11/2025 (PENDING)_
- Fixed a regression introduced in [`14.0.0`](https://docs.cypress.io/guides/references/changelog#14-0-0) where error codeframes in the runner UI were not populated with the correct data in failed retry attempts. Fixes [#30927](https://github.com/cypress-io/cypress/issues/30927).
- All commands performed in `after` and `afterEach` hooks will now correctly retry when a test fails. Commands that are actions like `.click()` and `.type()` will now perform the action in this situation also. Fixes [#2831](https://github.com/cypress-io/cypress/issues/2831).
- Fixed an issue in Cypress [`14.0.0`](https://docs.cypress.io/guides/references/changelog#14-0-0) where privileged commands did not run correctly when a spec file or support file contained characters that required encoding. Fixes [#30933](https://github.com/cypress-io/cypress/issues/30933).
- Re-enabled retrying Cloud instance creation for runs that are parallel or recorded. Fixes [#31002](https://github.com/cypress-io/cypress/issues/31002).

**Dependency Updates:**

Expand Down
24 changes: 13 additions & 11 deletions packages/server/lib/cloud/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -458,17 +458,19 @@ export default {
'platform',
])

return rp.post({
body,
url: recordRoutes.instances(runId),
json: true,
encrypt: preflightResult.encrypt,
timeout: timeout ?? SIXTY_SECONDS,
headers: {
'x-route-version': '5',
'x-cypress-run-id': runId,
'x-cypress-request-attempt': 0,
},
return retryWithBackoff((attemptIndex) => {
return rp.post({
body,
url: recordRoutes.instances(runId),
json: true,
encrypt: preflightResult.encrypt,
timeout: timeout ?? SIXTY_SECONDS,
headers: {
'x-route-version': '5',
'x-cypress-run-id': runId,
'x-cypress-request-attempt': attemptIndex,
},
})
})
.catch(RequestErrors.StatusCodeError, formatResponseBody)
.catch(tagError)
Expand Down
72 changes: 47 additions & 25 deletions system-tests/__snapshots__/record_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4385,7 +4385,7 @@ http://localhost:1234/capture-protocol/upload/?x-amz-credential=XXXXXXXX&x-amz-s
`

exports['e2e record api interaction errors api retries on error errors and does not create or update instances when parallel 1'] = `
exports['e2e record api interaction errors api retries on error warns and does not create or update instances 1'] = `
We encountered an unexpected error communicating with our servers.
StatusCodeError: 500 - "Internal Server Error"
Expand Down Expand Up @@ -4422,50 +4422,72 @@ We encountered an unexpected error communicating with our servers.
StatusCodeError: 500 - "Internal Server Error"
Because you passed the --parallel flag, this run cannot proceed since it requires a valid response from our servers.
We will retry 3 more times in X second(s)...
The --group flag you passed was: foo
The --ciBuildId flag you passed was: ciBuildId123
`
────────────────────────────────────────────────────────────────────────────────────────────────────
Running: record_pass.cy.js (1 of 1)
Estimated: X second(s)
exports['e2e record api interaction errors api retries on error errors and does not create or update instances when recording and not parallel 1'] = `
We encountered an unexpected error communicating with our servers.
StatusCodeError: 500 - "Internal Server Error"
record pass
✓ passes
- is pending
We will retry 3 more times in X second(s)...
We encountered an unexpected error communicating with our servers.
1 passing
1 pending
StatusCodeError: 500 - "Internal Server Error"
We will retry 2 more times in X second(s)...
(Results)
We encountered an unexpected error communicating with our servers.
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Tests: 2 │
│ Passing: 1 │
│ Failing: 0 │
│ Pending: 1 │
│ Skipped: 0 │
│ Screenshots: 1 │
│ Video: false │
│ Duration: X seconds │
│ Estimated: X second(s) │
│ Spec Ran: record_pass.cy.js │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
StatusCodeError: 500 - "Internal Server Error"
We will retry 1 more time in X second(s)...
(Screenshots)
- /XXX/XXX/XXX/cypress/screenshots/record_pass.cy.js/yay it passes.png (400x1022)
(Uploading Cloud Artifacts)
- Video - Nothing to upload
- Screenshot - 1 kB /XXX/XXX/XXX/cypress/screenshots/record_pass.cy.js/yay it passes.png
- Test Replay - Nothing to upload - Test Replay is disabled for this project. Enable Test Replay in Cloud project settings
Uploading Cloud Artifacts: . . . . .
(Uploaded Cloud Artifacts)
- Screenshot - Done Uploading 1 kB in Xm, Ys ZZ.ZZms 1/1 /XXX/XXX/XXX/cypress/screenshots/record_pass.cy.js/yay it passes.png
====================================================================================================
(Run Starting)
(Run Finished)
Spec Tests Passing Failing Pending Skipped
┌────────────────────────────────────────────────────────────────────────────────────────────────┐
│ Cypress: 1.2.3 │
│ Browser: FooBrowser 88 │
│ Specs: 1 found (record_pass.cy.js) │
│ Searched: cypress/e2e/record_pass* │
│ Params: Tag: nightly, Group: false, Parallel: false │
│ Run URL: https://dashboard.cypress.io/projects/cjvoj7/runs/12 │
│ ✔ record_pass.cy.js XX:XX 2 1 - 1 - │
└────────────────────────────────────────────────────────────────────────────────────────────────┘
✔ All specs passed! XX:XX 2 1 - 1 -
We encountered an unexpected error communicating with our servers.
StatusCodeError: 500 - "Internal Server Error"
───────────────────────────────────────────────────────────────────────────────────────────────────────
Recorded Run: https://dashboard.cypress.io/projects/cjvoj7/runs/12
Because you passed the --record flag, this run cannot proceed since it requires a valid response from our servers.
`
37 changes: 7 additions & 30 deletions system-tests/test/record_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -1615,11 +1615,7 @@ describe('e2e record', () => {

setupStubbedServer(routes)

beforeEach(() => {
count = 0
})

it('errors and does not create or update instances when parallel', function () {
it('warns and does not create or update instances', function () {
process.env.API_RETRY_INTERVALS = '1000,2000,3000'

return systemTests.exec(this, {
Expand All @@ -1632,7 +1628,6 @@ describe('e2e record', () => {
parallel: true,
snapshot: true,
ciBuildId: 'ciBuildId123',
expectedExitCode: 1,
})
.then(() => {
const urls = getRequestUrls()
Expand All @@ -1643,30 +1638,12 @@ describe('e2e record', () => {
'POST /runs',
'POST /runs',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
])
})
})

it('errors and does not create or update instances when recording and not parallel', function () {
process.env.API_RETRY_INTERVALS = '1000,2000,3000'

return systemTests.exec(this, {
key: 'f858a2bc-b469-4e48-be67-0876339ee7e1',
configFile: 'cypress-with-project-id.config.js',
spec: 'record_pass*',
tag: 'nightly',
record: true,
snapshot: true,
expectedExitCode: 1,
})
.then(() => {
const urls = getRequestUrls()

expect(urls).to.deep.eq([
'POST /runs',
'POST /runs',
'POST /runs',
'POST /runs',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
'POST /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/tests',
'POST /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/results',
'PUT /screenshots/1.png',
'PUT /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/artifacts',
'PUT /instances/e9e81b5e-cc58-4026-b2ff-8ae3161435a6/stdout',
'POST /runs/00748421-e035-4a3d-8604-8468cc48bdb5/instances',
])
})
Expand Down

5 comments on commit 46a473d

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46a473d Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.2/linux-arm64/develop-46a473dfafd55e426f6ac18e2e8393a83403c23b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46a473d Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the linux x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.2/linux-x64/develop-46a473dfafd55e426f6ac18e2e8393a83403c23b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46a473d Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin arm64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.2/darwin-arm64/develop-46a473dfafd55e426f6ac18e2e8393a83403c23b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46a473d Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the darwin x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.2/darwin-x64/develop-46a473dfafd55e426f6ac18e2e8393a83403c23b/cypress.tgz

@cypress-bot
Copy link
Contributor

@cypress-bot cypress-bot bot commented on 46a473d Feb 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Circle has built the win32 x64 version of the Test Runner.

Learn more about this pre-release build at https://on.cypress.io/advanced-installation#Install-pre-release-version

Run this command to install the pre-release locally:

npm install https://cdn.cypress.io/beta/npm/14.0.2/win32-x64/develop-46a473dfafd55e426f6ac18e2e8393a83403c23b/cypress.tgz

Please sign in to comment.