0

我正在尝试使用 ember 考试并行运行我的 ember 测试。但是,当我运行测试时,我经常遇到浏览器断开连接问题,并带有以下日志:

[16:41:10][Step 6/6] not ok 561 Firefox - error
[16:41:10][Step 6/6]     ---
[16:41:10][Step 6/6]         message: >
[16:41:10][Step 6/6]             Error: Browser disconnected
[16:41:10][Step 6/6]             Stderr: 
[16:41:10][Step 6/6]              *** You are running in headless mode.
[16:41:10][Step 6/6]             [Parent 12706, Gecko_IOThread] WARNING: pipe error (45): Connection reset by peer: file /build/firefox-8HKHfQ/firefox-57.0+build4/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353
[16:41:10][Step 6/6]             
[16:41:10][Step 6/6]             ###!!! [Parent][MessageChannel] Error: (msgtype=0x24001F,name=PContent::Msg_PreferenceUpdate) Channel error: cannot send/recv
[16:41:10][Step 6/6]             
[16:41:10][Step 6/6]             
[16:41:10][Step 6/6]             ###!!! [Parent][MessageChannel] Error: (msgtype=0x150083,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv
[16:41:10][Step 6/6]             
[16:41:10][Step 6/6]             
[16:41:10][Step 6/6]             ###!!! [Parent][MessageChannel] Error: (msgtype=0x150083,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv
[16:41:10][Step 6/6]             
[16:41:10][Step 6/6]             
[16:41:10][Step 6/6]             
[16:41:10][Step 6/6]         Log: |
[16:41:10][Step 6/6]             { type: 'error', text: 'Error: Browser disconnected' }
[16:41:10][Step 6/6]             { type: 'error',
[16:41:10][Step 6/6]               text: '*** You are running in headless mode.\n[Parent 12706, Gecko_IOThread] WARNING: pipe error (45): Connection reset by peer: file /build/firefox-8HKHfQ/firefox-57.0+build4/ipc/chromium/src/chrome/common/ipc_channel_posix.cc, line 353\n\n###!!! [Parent][MessageChannel] Error: (msgtype=0x24001F,name=PContent::Msg_PreferenceUpdate) Channel error: cannot send/recv\n\n\n###!!! [Parent][MessageChannel] Error: (msgtype=0x150083,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv\n\n\n###!!! [Parent][MessageChannel] Error: (msgtype=0x150083,name=PBrowser::Msg_Destroy) Channel error: cannot send/recv\n\n' }
[16:41:10][Step 6/6]     ...

我正在运行 Firefox 57 版,59 版更好,但即使在那里我也经常看到这个问题,但 chrome 似乎表现不错,但有时它也会失败。最初我以为是因为我在无头模式下运行,但即使在非无头模式下,情况也没有好转。我的 testem.js 文件是:

let today = new Date();
const testWindowWidth = 1920;
const testWindowHeight = 1080;

/**
 * Exports configuration to run tests via testem.
 * There are issues with running the test in firefox in headless mode.
 * Chrome however works fine with the provided configuration.
 * @see : https://github.com/testem/testem/issues/1117
 * */
module.exports = {
    'framework': 'qunit',
    'test_page': [
        'tests/index.html?hidepassed&nojshint'
    ],
    'disable_watching': true,
    'parallel': -1,//sky is the limit
    'launch_in_ci': [
        'Firefox'
    ],
    'launch_in_dev': [
        'Chrome'
    ],
    'browser_args': {
        'Firefox': [
            `-headless`,//comment this line out for debugging purpose
            `-width ${testWindowWidth}`,
            `-height ${testWindowHeight}`
        ],
        'Chrome': [
            '--headless',//comment this line out for debugging purpose
            '--disable-gpu',
            '--remote-debugging-port=9222',
            '--remote-debugging-address=0.0.0.0',
            '--no-sandbox',
            '--user-data-dir=/tmp',
            `--window-size=${testWindowWidth},${testWindowHeight}`
        ]
    },
    'browser_start_timeout': 2 * 60,
    'report_file': `tests/logs/${today.getFullYear()}-${today.getMonth() + 1}-${today.getDate()}/${today}.txt`,
    'browser_disconnect_timeout': 2 * 60
};

我不知道问题出在 testem 配置还是浏览器本身!非常感谢您的帮助/建议,谢谢。

4

1 回答 1

0

我无法解决这个问题,但我能够通过 ember-exam 避免浏览器断开连接问题。诀窍是找出分区的数量来拆分测试并并行运行它的子集,这样每次 ember 运行都有大约 200 个测试。我们有相当大的 ember 应用程序,测试次数超过 3k,所以我最终创建了 shell 脚本来管理拆分。

//run-tests.sh 
const exec = require('child_process').exec;
var split = 100;//total no of partitions to split the tests into
var parallelRuns = 4;//total no of partitions to run in parallel at a time
var runTestModule = function(partitionNo) {
    if (partitionNo > split) {
        return;
    }
    var _partitions = [];
    for (var i = 0; i < parallelRuns; i++) {
        _partitions.push(++partitionNo);
    }
    var partitions = _partitions.map(function(index) {
        return "--partition=" + index;
    }).join(" ");
    var command = "./node_modules/.bin/ember exam --path=./dist --split=" + split + " " + partitions + " --parallel";
    console.log(
        "\n===============================================RUNNING COMMAND===============================================================\n" +
        command +
        "\n=============================================================================================================================\n");

    exec(command, function(e, stdout, stderr) {
        if (e instanceof Error) {
            console.error(e);
            //throw e;
        }
        console.log('stdout ', stdout);
        console.log('stderr ', stderr);
        runTestModule(partitionNo);
    });
};

runTestModule(0); 
于 2018-03-07T17:26:45.687 回答