Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Xvfb is completely ruining my life and job. #98

Open
ChaseBig opened this issue Nov 21, 2019 · 12 comments
Open

Xvfb is completely ruining my life and job. #98

ChaseBig opened this issue Nov 21, 2019 · 12 comments

Comments

@ChaseBig
Copy link

How does one use this reuse option? Where do I set that? Do I create a new file or edit an existing one? The readme instructions are not very detailed. I am working in a monorepo that is simultaneously running three webApp environments each with their own cypress instances -- all running at the same time. I want to set each cypress instance to a different DISPLAY and then kill Xvfb after it's done. We are using CircleCi in a javascript/node.js codebase. We use a circle.yml file to tell circleci what to do and when.

This friggin' Xvfb stuff has literally wasted thousands of dollars worth of my time trying to fix.

Can anyone help me?

I get all kinds of random errors related to Xvfb failures.

Your system is missing the dependency: Xvfb

Install Xvfb and run Cypress again.

Read our documentation on dependencies for more information:

https://on.cypress.io/required-dependencies

If you are using Docker, we provide containers with all required dependencies installed.

----------

Error: Display :99 is already in use and the "reuse" option is false.
Error: (EE) 
Fatal server error:
(EE) Server is already active for display 100
If this server is no longer running, remove /tmp/.X100-lock
and start again.
(EE)
@flotwig
Copy link

flotwig commented Nov 21, 2019

First of all, I love the passion. Excellent use of rhetoric to communicate emotion.

Second of all, to make sure I understand, you want to run 3 Cypress instances simultaneously in the same CI container? And Xvfb is blocking that?

If that's the case, have you tried initializing Xvfb yourself? You can use xvfb-run like this to do that:

cd packages/webApp1 && xvfb-run -a npm run cypress:run ...
cd packages/webApp2 && xvfb-run -a npm run cypress:run ...
cd packages/webApp3 && xvfb-run -a npm run cypress:run ...

This should work, because:

  • Cypress only starts Xvfb if it detects that there is no DISPLAY set, and
  • Using xvfb-run with -a makes it automatically use the next free server number, so you won't get the Error: Display :99 is already in use and the "reuse" option is false. error.

Let me know how this goes for you, I think it should work.


IMO, a better option would just be to create 3 parallel Circle jobs to run each test suite, then you wouldn't need to worry about any of this.


A long-term goal for Cypress is to reduce/remove the dependency on Xvfb, but that will require these things to be done first:

@ChaseBig
Copy link
Author

@flotwig Hi Zach!

Thank you so much for the quick and understanding reply (and for not calling me a complaining whiny baby lol).

As for your troubleshooting tips, I'm going to give the solutions a shot and will let you know how it goes!

I 100% agree on the parallel jobs, I'm working on getting that up-and-running as I learn more about how to do that. I really look forward to being able to do that!

Seriously, though, thank you for these suggestions! I'll keep ya posted.

@ChaseBig
Copy link
Author

If that's the case, have you tried initializing Xvfb yourself? You can use xvfb-run like this to do that:

So when I run $ cd packages/web.app-browser && xvfb-run -a yarn cypress run, I get a bash: xvfb-run: command not found error.

I have every xvfb related module I could find in every package.json of each package and in the project root.

@flotwig
Copy link

flotwig commented Nov 21, 2019

xvfb isn't a node module, it's a package for the X windowing system. Have you installed the dependencies required for Cypress? https://docs.cypress.io/guides/guides/continuous-integration.html#Dependencies

Specifically, apt install xvfb will give you the xvfb-run command.

@ChaseBig
Copy link
Author

Ahh, maybe that's my issue. I'm on macOS. i also cant get apt, apt-get, sudo apt-get, yum, or sudo yum to work locally or on circleCi.

@bahmutov
Copy link
Contributor

Since you are on CircleCI, can you try using either:

We run 1000s of tests per day on Circle, so it should be the simplest thing to do, in general.

@flotwig
Copy link

flotwig commented Nov 21, 2019

Xvfb is only for running on Linux, you shouldn't need it for macOS. I'm not sure what your CI environment is like, but you can use our docker images that have all the dependencies preinstalled.

@ChaseBig
Copy link
Author

Okay sounds good. I will investigate that avenue instead of doing sketchy workarounds.

Thanks so much guys!

@csvan
Copy link

csvan commented May 7, 2020

FWIW I think I solved this on a CentOS 8 box by spinning up the xvfb server externally:

/usr/bin/Xvfb :99 -screen 0 1920x1080x24+32 &
export DISPLAY=:99

At any rate, I have not had the issue since doing so.

@hvaandres
Copy link

I'm using a pipeline through bitbucket and I'm getting the same issue. Even if run the dependency from cypress:

apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb

It is telling me that I have the same issue as the one that you have above with the xvfb package. Does anyone know a workaround?

@ChaseBig
Copy link
Author

ChaseBig commented Jan 7, 2021

I'm using a pipeline through bitbucket and I'm getting the same issue. Even if run the dependency from cypress:

apt-get install libgtk2.0-0 libgtk-3-0 libgbm-dev libnotify-dev libgconf-2-4 libnss3 libxss1 libasound2 libxtst6 xauth xvfb

It is telling me that I have the same issue as the one that you have above with the xvfb package. Does anyone know a workaround?

I had to set the XVFB port for each individual package I was running tests against. They were all trying to use the same port on a single machine when running in parallel so i had to manually pass in a different port assignment because XVFB wasn't automatically assigning a new port if the port was already in use. I no longer work for the company I was building this for so I dont have code examples to show you, unfortunately.

@carlos0202
Copy link

Hi guys,

Sorry for jumping into this thread with a question that might be tagged as unrelated. I'm trying to run cypress in headed mode on CircleCI so that an extension I have installed (Metamask to be controlled using puppeteer) can be used but I have not found a single example or documentation to make my tests run xvfb which might be what my setup needs to run the tests in the same way they're running fine in my local machine runs.

Current CircleCI config is as follows:

version: 2.1
orbs:
  cypress: cypress-io/cypress@1.28.0
  codecov: codecov/codecov@1.1.3

executors:
  with-chrome:
    docker:
      - image: "cypress/browsers:node14.16.0-chrome89-ff86"
    resource_class: medium+

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Commands ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
commands:
  report-coverage:
    description: |
      Store coverage report as an artifact and send it to Codecov service.
    steps:
      - store_artifacts:
          path: coverage
      - run: npx nyc report --reporter=text || true
      - codecov/upload:
          file: coverage/coverage-final.json

# ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Workflows ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ #
linux-workflow: &linux-workflow
  jobs:
    # Setup
    #  1. Install Cypress
    #  2. Validate types
    - cypress/install:
        name: "Setup Linux"
        yarn: true
        build: "yarn"
        executor: with-chrome
        post-checkout:
          - restore_cache:
              keys: 
                - yarn-packages-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}
                - yarn-packages-v2-{{ .Branch }}-
                - yarn-packages-v2-
        cache-key: >-
            cache-{{ checksum "package.json" }}
        post-steps:
          - save_cache:
              key: yarn-packages-v2-{{ .Branch }}-{{ checksum "yarn.lock" }}
              paths:
                - ~/.cache/yarn
                - node_modules
          - run:
              name: Print cache information
              command: yarn cypress cache list
          - run:
              name: Check Types
              command: yarn type-check:ci
    
    # Run E2E tests in Chrome
    - cypress/run:
        command: yarn run cy:run:ci --ci-build-id ${CIRCLE_SHA1:0:8}
        name: "UI Tests - Chrome"
        executor: with-chrome
        attach-workspace: true
        start: yarn dev
        wait-on: "http://localhost:8000"
        yarn: true
        parallelism: 5
        cache-key: >-
            cache-{{ checksum "package.json" }}
        requires:
          - Setup Linux
        post-steps:
          - report-coverage

workflows:
  linux:
    <<: *linux-workflow

Any help is truly appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants