6
votes

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.

4

4 Answers

6
votes

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

2
votes

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!!!
   ],
0
votes

You might want to check the console output before Karma attempts to launch the browser. I got stuck for hours on constant timeouts when there were invalid import paths in my Angular application. Karma prints such errors in the console but continues by launching the browsers as if the errors had no importance. This is a bit misleading, but worth checking before blaming the browsers.

Second, machine performance: Every once in a while you might get a timeout at the first launch attempt, but the next attempt will then liekly succeed. Dockerization might decrease your performance, but not much. A headless Chrome should run fast even with minimal setup.

If your browser would not be installed or addressable, then there should be some output regarding that as well.

0
votes

Hi i solved this issue this way:

In my case the client had a proxy-blocker to manage the networking configurations. So i provided the proxy as server in the customLauncher flag and works perfectly, but only in the pipeline, locally the tests stopped. but it's just take off the proxy that runs locally.

Before: This way the tests runs locally, but do not works in the jenkins pipeline (npm run test)


browsers: ['MyChromeHeadless'], 
    customLaunchers: {
    MyChromeHeadless: {
        base: 'ChromeHeadless',
        flags: [
          '--no-sandbox',
          '--proxy-auto-detect'
        ]
      }
    }

After: This way the tests runs in the pipeline, but do not works locally cuz i'm not under the client networking with access to the proxy provied, if you are, should work.


browsers: ['MyChromeHeadless'], 
    customLaunchers: {
    MyChromeHeadless: {
        base: 'ChromeHeadless',
        flags: [
          '--no-sandbox',
          '--proxy-bypass-list=*',
          '--proxy-server=http://proxy.your.company'
        ]
      }
    }