github-action icon indicating copy to clipboard operation
github-action copied to clipboard

Cypress action consistently maxing out runner CPU on single test

Open Pearce-Ropion opened this issue 3 years ago • 1 comments

We are currently working on migrating our CI to Github actions and are having trouble getting cypress to run efficiently.

When running cypress, our tests consistently max out the CPU on github's default action runner. Attempting to run the full test suite regularly causes timeouts. The runner will often randomly freeze while running a test and proceed to not process anything else until the end of the step timeout.

In order to diagnose this, I tried only running a single spec (a simple one with 3 it statements) with DEBUG enabled to see what was going on and the total CPU usage got to 103%. Raw logs

Our specs have no issues on our existing CI (semaphore CI) nor in local dev environments.

Node: 16.13.0 Specs are running in Electron 100 (headless)

Cypress version and plugins

"cypress": "10.3.0",
"cypress-multi-reporters": "^1.5.0",
"cypress-terminal-report": "^1.4.1",

Here is the relevant action. The node_modules and cypress binary are installed and verified correctly in a separate step. The server is just a simple proxy that serves html/assets from the build directory and proxies all API requests to our staging servers.

 - name: Run cypress
   uses: cypress-io/github-action@v4
   with:
     project: packages/slate
     start: node packages/slate/internal/scripts/localExpress
     wait-on: "http://127.0.0.1:3000"
     install: false
     spec: packages/slate/cypress/e2e/guest_invite_spec.ts
     config-file: cypress.config.ts
   env:
     DEBUG: cypress:server:util:process_profiler
     GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
     NODE_OPTIONS: --max-old-space-size=6144
   timeout-minutes: 20

cypress.config.ts

import { defineConfig } from 'cypress';
const cypressConfig = defineConfig({
  defaultCommandTimeout: 45000,
  video: true,
  videoUploadOnPasses: false,
  viewportWidth: 1280,
  viewportHeight: 800,
  blockHosts: [
    '*.googletagmanager.com',
    '*.hs-scripts.com',
    'js.intercomcdn.com',
    '*.litix.io',
  ],
  projectId: '***',
  e2e: {
    setupNodeEvents: (config, on) => {
      require('cypress-terminal-report/src/installLogsPrinter')(on);
      on(
        'before:browser:launch',
        (browser: Cypress.Browser, launchOptions: Cypress.BrowserLaunchOptions) => {
          if (browser.name === 'chromium') {
            // needed to address issues related to tests hanging in the CI
            // https://github.com/cypress-io/cypress/issues/8206
            launchOptions.args.push('--disable-dev-shm-usage');
          }
          return launchOptions;
        },
      );
    },
    baseUrl: 'http://127.0.0.1:3000',
    specPattern: 'cypress/e2e/**/*.{js,jsx,ts,tsx}',
  },
});
export default cypressConfig;

Pearce-Ropion avatar Jul 25 '22 21:07 Pearce-Ropion

@Pearce-Ropion have you tried turning on logs to see where the test is hanging? Maybe there's a specific spot it hangs each time?

admah avatar Jul 27 '22 20:07 admah