在Jenkins代理docker映像(带有Kubernetes插件)中运行业力测试时,ChromeHeadless挂起

时间:2019-09-04 16:46:29

标签: docker jenkins karma-jasmine

我有一个使用默认测试套件运行的角度应用程序(使用业力启动无头chrome)。 Jenkins与kubernetes插件一起运行,以在每次提交作业时启动jenkins代理的新实例。 (如果此错误已修复,我将在stackoverflow中创建一篇文章,内容涉及在Docker容器中运行无头chrome测试,因为这似乎是一个常见问题。)

我基于this的构建(减去量角器部分,因为不使用量角器)。

一切都可以构建并正常运行,直到浏览器测试完成。

+ npm run test:vt --watch=false --progress=false --browsers=ChromeHeadless --headless --disable-gpu --window-size=800x600 --disable-dev-shm-usage --no-sandbox

> {my_company}/{my_project}docs@0.0.0-PLACEHOLDER test:vt /home/jenkins/agent/workspace/UI_{my_project}_PR-192
> ng test {my_project}

[33m04 09 2019 16:00:58.826:WARN [karma]: [39mNo captured browser, open http://localhost:9876/
[32m04 09 2019 16:00:58.832:INFO [karma-server]: [39mKarma v3.1.4 server started at http://0.0.0.0:9876/
[32m04 09 2019 16:00:58.832:INFO [launcher]: [39mLaunching browsers ChromeHeadlessNoSandbox with concurrency unlimited
[32m04 09 2019 16:00:58.839:INFO [launcher]: [39mStarting browser ChromeHeadless
[33m04 09 2019 16:01:16.236:WARN [karma]: [39mNo captured browser, open http://localhost:9876/
[32m04 09 2019 16:01:16.432:INFO [HeadlessChrome 76.0.3809 (Linux 0.0.0)]: [39mConnected on socket FcDILSSqmJFawfnrAAAA with id 26860248
HeadlessChrome 76.0.3809 (Linux 0.0.0): Executed 0 of 863 SUCCESS (0 secs / 0 secs)
...{bunches 'o lines}...
[1A[2KHeadlessChrome 76.0.3809 (Linux 0.0.0): Executed 796 of 863 (skipped 67) SUCCESS (0 secs / 32.499 secs)
[1A[2KHeadlessChrome 76.0.3809 (Linux 0.0.0): Executed 796 of 863 (skipped 67) SUCCESS (33.59 secs / 32.499 secs)
TOTAL: 796 SUCCESS
TOTAL: 796 SUCCESS

然后终端似乎就挂在这里了。我让它静置24小时。

我在内存和CPU使用率上放置了一个监视器。 CPU下降到噪声水平(<10mcpu),就好像它在等待输入一样。因此,我添加了标志“ --password-store = basic”,以防止ChromeHeadless在等待输入时挂起(我尝试查找推荐此操作的业力github错误报告,但找不到。)不幸的是,这没有成功。

关于如何解决或解决该问题的任何想法?

docker镜像是这样构建的(最后两个RUN命令用于设置Chrome二进制文件):

FROM jenkins/jnlp-slave:3.29-1

ARG DOCKER_VERSION=18.06.1~ce~3-0~debian
ARG DC_VERSION=1.24.1

USER root
RUN apt-get update && \
    apt-get install -qq -y --no-install-recommends \
      apt-transport-https \
      ca-certificates \
      curl \
      gnupg2 \
      software-properties-common && \
    curl -fsSL https://download.docker.com/linux/debian/gpg | apt-key add - && \
    apt-key fingerprint 0EBFCD88 && \
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable" && \
    add-apt-repository "deb [arch=amd64] https://download.docker.com/linux/debian stretch stable" && \
    apt-get update && \
    apt-get install -qq -y --no-install-recommends docker-ce=${DOCKER_VERSION} && \
    curl -L https://github.com/docker/compose/releases/download/${DC_VERSION}/docker-compose-`uname -s`-`uname -m` -o /usr/local/bin/docker-compose && \
    chmod +x /usr/local/bin/docker-compose && \
        curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
        apt-get install nodejs && \
    rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
RUN apt-get install -qq -y --no-install-recommends nodejs npm

# Set the Chrome repo.
RUN wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - \
    && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
# Install Chrome.
RUN apt-get update && apt-get -y install google-chrome-stable

ENTRYPOINT ["jenkins-slave"]

我的karama.conf设置如下:

module.exports = function (config) {
  config.set({
    basePath: '',
    frameworks: ['jasmine', '@angular-devkit/build-angular'],
    plugins: [
      require('karma-jasmine'),
      require('karma-chrome-launcher'),
      require('karma-jasmine-html-reporter'),
      require('karma-coverage-istanbul-reporter'),
      require('@angular-devkit/build-angular/plugins/karma')
    ],
    client: {
      clearContext: false // leave Jasmine Spec Runner output visible in browser
    },
    coverageIstanbulReporter: {
      dir: require('path').join(__dirname, '../../coverage'),
      reports: ['html', 'lcovonly'],
      fixWebpackSourcePaths: true
    },
    reporters: ['progress', 'kjhtml'],
    port: 9876,
    colors: true,
    logLevel: config.LOG_INFO,
    autoWatch: true,
        browsers: ['ChromeHeadlessNoSandbox'],
        customLaunchers: {
            ChromeHeadlessNoSandbox: {
                base: 'ChromeHeadless',
                flags: [
            "--no-sandbox",
             // required to run without privileges in Docker
            "--disable-web-security",
            "--disable-gpu",
            "--remote-debugging-port=9222"
                ]
            }
        },
    singleRun: false,
        junitReporter:{
           outputDir:'test-reports',
           // results will be saved as $outputDir/$browserName.xml
                outputFile:'junit-report.xml',
           // if included, results will be saved as $outputDir/$browserName/$outputFile
                suite:'',
           // suite will become the package name attribute in xml testsuite element
                useBrowserName:false,
           // add browser name to report and classes names
                nameFormatter:undefined,
           // function (browser, result) to customize the name attribute in xml testcase element
                classNameFormatter:undefined,
           // function (browser, result) to customize the classname attribute in xml testcase element
                properties:{
           }   // key value pair of properties to add to the section of the report
        }
  });
};

运行测试的Jenkinsfile部分是:

  stage('Test') {
    echo "Running tests"
    sh 'npm run test:vt --watch=false --progress=false --browsers=ChromeHeadless  --headless --disable-gpu --window-size=800x600 --disable-dev-shm-usage --no-sandbox --password-store=basic'
  }

1 个答案:

答案 0 :(得分:1)

我使用与Jenkins安装在同一台机器上的karma和CromeHeadless(小型项目和站点)。有了这种配置,我就再也不会看到Chrome实例在测试完成后仍能正常工作。您可以尝试将其添加到您的karma.conf:

    browsers: ['ChromeHeadless'],
    singleRun: true,
    restartOnFileChange: true

例如,我的karma.conf如下所示(仅发送重要行):

    customLaunchers: {
      ChromeHeadless: {
        base: 'Chrome',
        flags: [
          '--headless',
          '--disable-gpu',
          '--no-sandbox',
          '--remote-debugging-port=9222',
        ]
      }
    },
    browsers: ['ChromeHeadless'],
    singleRun: true,
    restartOnFileChange: true

单个运行选项表示“如果为true,则Karma将启动并捕获所有已配置的浏览器,运行测试,然后以退出代码0或1退出,具体取决于所有测试是否通过或失败。” (来自业力配置文件site

相关问题