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

别说谁变了你拦得住时间么 提交于 2020-02-03 23:40:33

问题


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.


回答1:


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:


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.




回答3:


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'
        ]
      }
    }




回答4:


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


来源:https://stackoverflow.com/questions/52092596/chromeheadless-giving-timeout-when-running-gitlab-ci-pipeline-with-docker-centos

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!