Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ChromeHeadless giving timeout when running GitLab CI pipeline with Docker Centos 7.5 image

So I am trying to run Karma tests for an Angular 6 application on a docker image with Centos 7.5 using a pipeline for GitLab CI.

The problem is

30 08 2018 07:09:55.222:WARN [launcher]: ChromeHeadless have not captured in 60000 ms, killing. 30 08 2018 07:09:55.244:INFO [launcher]: Trying to start ChromeHeadless again (1/2). 30 08 2018 07:10:55.264:WARN [launcher]: ChromeHeadless have not captured in 60000 ms, killing. 30 08 2018 07:10:55.277:INFO [launcher]: Trying to start ChromeHeadless again (2/2). 30 08 2018 07:11:55.339:WARN [launcher]: ChromeHeadless have not captured in 60000 ms, killing. 30 08 2018 07:11:55.355:ERROR [launcher]: ChromeHeadless failed 2 times (timeout). Giving up. ERROR: Job failed: exit code 1

I run the tests with ng test --browsers ChromeHeadlessNoSandbox --watch=false --code-coverage

Karma conf :

browsers: ['Chrome', 'ChromeHeadlessNoSandbox'],
    customLaunchers: {
      ChromeHeadlessNoSandbox: {
        base: 'ChromeHeadless',
        flags: [
          '--no-sandbox',
          '--disable-setuid-sandbox',
          '--disable-gpu',
          '--remote-debugging-port=9222',
        ],
      },
    },

Also on the Image the docker file I install the latest chrome stable:

RUN wget https://dl.google.com/linux/direct/google-chrome-stable_current_x86_64.rpm
RUN yum -y localinstall google-chrome-stable_current_x86_64.rpm && yum clean all

Do you have any idea about why its giving timeout? In the local environment, it runs perfectly.

like image 782
Andrei Macavei Avatar asked Aug 30 '18 08:08

Andrei Macavei


2 Answers

I have resolved the same issue. My test suits runs perfectly in my local machine but when running these tests in a docker container, it fails due to connection timeout. (i'm using Gitlab runner also, and My docker image is based on circleci/node:8.9.2-browsers)

After investigating this issue, i found that the chrome bin variable path was missed in the docker file. so i fixed the issue by adding: export CHROME_BIN=/usr/bin/google-chrome to my .gitlab-ci.yml in before_script

# TESTING
unit_test_client:
  stage: test
  before_script:
    - export CHROME_BIN=/usr/bin/google-chrome
  script:
    - npm run test:client

You can also fix your issue by setting the CHROME_BIN by process.env.CHROME_BIN='/usr/bin/google-chrome' in the top of your karma config file. In this case, you need to handle the case that you are running the test in your local machine, probably it should match the same chrome path

like image 64
Saif Jerbi Avatar answered Sep 29 '22 11:09

Saif Jerbi


We had the same issue and resolved it by adding the following flag in the karma.config.js

headlessChrome: {
   base: "ChromeHeadless",
   flags: [
          "--no-sandbox",
          "--no-proxy-server",
          "--disable-web-security",
          "--disable-gpu",
          "--js-flags=--max-old-space-size=8196", // THIS LINE FIXED IT!!!
   ],
like image 27
Carlo Bos Avatar answered Sep 29 '22 12:09

Carlo Bos