Azure Pipeline "ChromeHeadless have not captured in 60000 ms, killing.",在第二次尝试时有效,但有时会以非零退出

Azure Pipeline "ChromeHeadless have not captured in 60000 ms, killing.", works on second try but sometimes exits with non zero

我在 ng 测试中遇到间歇性构建失败,我 认为 与 ChromeHeadless 实例在无法正确连接后挂起有关。我的 Azure 管道 总是 发出一个 ChromeHeadless have not captured in 60000 ms, killing. 的提示音(例如 this 问题),然后 运行 单元测试就好了。测试将在构建变为绿色的大约一半时间内通过。另一半我得到一个节点非零退出代码错误。

命令:ng test --code-coverage --browsers=ChromeHeadless --watch=false

成功记录:

2021-11-15T22:59:09.9297050Z > ng test --code-coverage --browsers=ChromeHeadless --watch=false
2021-11-15T22:59:09.9297547Z 
2021-11-15T22:59:09.9298696Z 15 11 2021 22:55:02.738:WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead.
2021-11-15T22:59:09.9300540Z 15 11 2021 22:55:53.494:INFO [karma-server]: Karma v6.3.4 server started at http://localhost:9876/
2021-11-15T22:59:09.9302562Z 15 11 2021 22:55:53.495:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
2021-11-15T22:59:09.9305118Z 15 11 2021 22:55:53.501:INFO [launcher]: Starting browser ChromeHeadless
2021-11-15T22:59:09.9306242Z 15 11 2021 22:56:53.528:WARN [launcher]: ChromeHeadless have not captured in 60000 ms, killing.
2021-11-15T22:59:09.9307283Z 15 11 2021 22:56:56.344:INFO [launcher]: Trying to start ChromeHeadless again (1/2).
2021-11-15T22:59:09.9308355Z 15 11 2021 22:57:08.714:INFO [Chrome Headless 95.0.4638.69 (Windows 10)]: Connected on socket 7GsL_H9cLK7nNS-0AAAB with id 24622884
2021-11-15T22:59:09.9309742Z Chrome Headless 95.0.4638.69 (Windows 10): Executed 0 of 5191[32m SUCCESS[39m (0 secs / 0 secs)
2021-11-15T22:59:09.9311289Z [1A[2KChrome Headless 95.0.4638.69 (Windows 10): Executed 1 of 5191[32m SUCCESS[39m (0 secs / 0.09 secs)

...snip a bunch of test lines...

2021-11-15T22:59:10.4682949Z [1A[2KChrome Headless 95.0.4638.69 (Windows 10): Executed 5191 of 5191[32m SUCCESS[39m (1 min 48.797 secs / 40.407 secs)
2021-11-15T22:59:10.4683432Z [32mTOTAL: 5191 SUCCESS[39m
2021-11-15T22:59:10.4683751Z TOTAL: 5191 SUCCESS
2021-11-15T22:59:10.4685421Z ##[debug]rm -rf D:\a\npm08514.npmrc
2021-11-15T22:59:10.4686006Z ##[debug]removing file D:\a\npm08514.npmrc
2021-11-15T22:59:10.4687970Z ##[debug]Agent.BuildDirectory=D:\a
2021-11-15T22:59:10.4688686Z ##[debug]rm -rf D:\a\npm
2021-11-15T22:59:10.4690143Z ##[debug]removing directory D:\a\npm
2021-11-15T22:59:10.4694691Z ##[section]Finishing: Running Unit Tests

失败记录:

2021-11-15T23:00:13.5726081Z > ng test --code-coverage --browsers=ChromeHeadless --watch=false
2021-11-15T23:00:13.5726931Z 
2021-11-15T23:00:13.5728815Z 15 11 2021 22:55:00.157:WARN [karma-server]: Passing raw CLI options to `new Server(config, done)` is deprecated. Use `parseConfig(configFilePath, cliOptions, {promiseConfig: true, throwErrors: true})` to prepare a processed `Config` instance and pass that as the `config` argument instead.
2021-11-15T23:00:13.5731137Z 15 11 2021 22:56:23.079:INFO [karma-server]: Karma v6.3.4 server started at http://localhost:9876/
2021-11-15T23:00:13.5733401Z 15 11 2021 22:56:23.081:INFO [launcher]: Launching browsers ChromeHeadless with concurrency unlimited
2021-11-15T23:00:13.5735288Z 15 11 2021 22:56:23.087:INFO [launcher]: Starting browser ChromeHeadless
2021-11-15T23:00:13.5736548Z 15 11 2021 22:57:24.479:WARN [launcher]: ChromeHeadless have not captured in 60000 ms, killing.
2021-11-15T23:00:13.5737814Z 15 11 2021 22:57:34.284:INFO [launcher]: Trying to start ChromeHeadless again (1/2).
2021-11-15T23:00:13.5739190Z 15 11 2021 22:58:00.870:INFO [Chrome Headless 95.0.4638.69 (Windows 10)]: Connected on socket C0MkTPwSkT-fXggHAAAB with id 78277967
2021-11-15T23:00:13.5740882Z Chrome Headless 95.0.4638.69 (Windows 10): Executed 0 of 5191[32m SUCCESS[39m (0 secs / 0 secs)
2021-11-15T23:00:13.5743230Z [1A[2KChrome Headless 95.0.4638.69 (Windows 10): Executed 1 of 5191[32m SUCCESS[39m (0 secs / 0.103 secs)

...snip a bunch of test lines...

2021-11-15T23:00:14.2929797Z [1A[2KChrome Headless 95.0.4638.69 (Windows 10): Executed 5191 of 5191[32m SUCCESS[39m (0 secs / 48.607 secs)
2021-11-15T23:00:14.2930731Z 15 11 2021 23:00:12.864:WARN [Chrome Headless 95.0.4638.69 (Windows 10)]: Disconnected (0 times) reconnect failed before timeout of 2000ms (ping timeout)
2021-11-15T23:00:14.2931733Z [1A[2K[31mChrome Headless 95.0.4638.69 (Windows 10) ERROR[39m
2021-11-15T23:00:14.2932881Z   Disconnected reconnect failed before timeout of 2000ms (ping timeout)
2021-11-15T23:00:14.2933725Z Chrome Headless 95.0.4638.69 (Windows 10): Executed 5191 of 5191[31m DISCONNECTED[39m (2 mins 1.613 secs / 48.607 secs)
2021-11-15T23:00:14.2934480Z Chrome Headless 95.0.4638.69 (Windows 10) ERROR
2021-11-15T23:00:14.2935136Z   Disconnected reconnect failed before timeout of 2000ms (ping timeout)
2021-11-15T23:00:14.2935937Z [1A[2KChrome Headless 95.0.4638.69 (Windows 10): Executed 5191 of 5191[31m DISCONNECTED[39m (2 mins 1.613 secs / 48.607 secs)

... snip some config output...

2021-11-15T23:00:14.3395972Z ##[debug]pattern: '*-debug.log'
2021-11-15T23:00:14.3396710Z ##[debug]findPath: 'C:\npm\cache\_logs'
2021-11-15T23:00:14.3397422Z ##[debug]statOnly: 'false'
2021-11-15T23:00:14.3398156Z ##[debug]findPath: 'C:\npm\cache\_logs'
2021-11-15T23:00:14.3399116Z ##[debug]findOptions.allowBrokenSymbolicLinks: 'false'
2021-11-15T23:00:14.3399977Z ##[debug]findOptions.followSpecifiedSymbolicLink: 'true'
2021-11-15T23:00:14.3400817Z ##[debug]findOptions.followSymbolicLinks: 'true'
2021-11-15T23:00:14.3401559Z ##[debug]0 results
2021-11-15T23:00:14.3402490Z ##[debug]found 0 paths
2021-11-15T23:00:14.3404014Z ##[debug]applying include pattern
2021-11-15T23:00:14.3405865Z ##[debug]adjustedPattern: 'C:\npm\cache\_logs\*-debug.log'
2021-11-15T23:00:14.3407657Z ##[debug]0 matches
2021-11-15T23:00:14.3409050Z ##[debug]0 final results
2021-11-15T23:00:14.3410115Z ##[debug]Trying debug log location: D:\a\s\npm-debug.log
2021-11-15T23:00:14.3457007Z ##[warning]Couldn't find a debug log in the cache or working directory
2021-11-15T23:00:14.3478105Z ##[debug]Processed: ##vso[task.issue type=warning;]Couldn't find a debug log in the cache or working directory
2021-11-15T23:00:14.3479818Z ##[debug]Agent.BuildDirectory=D:\a
2021-11-15T23:00:14.3480813Z ##[debug]rm -rf D:\a\npm
2021-11-15T23:00:14.3482353Z ##[debug]removing directory D:\a\npm
2021-11-15T23:00:14.3483408Z ##[debug]task result: Failed
2021-11-15T23:00:14.3485013Z ##[error]Error: Npm failed with return code: 1
2021-11-15T23:00:14.3486527Z ##[debug]Processed: ##vso[task.issue type=error;]Error: Npm failed with return code: 1
2021-11-15T23:00:14.3496428Z ##[debug]Processed: ##vso[task.complete result=Failed;]Error: Npm failed with return code: 1
2021-11-15T23:00:14.3500802Z ##[section]Finishing: Running Unit Tests

认为 正在发生的是单元测试的多个实例由于顶部的错误而被剥离,然后我们有一个竞争条件:有时“断开连接”的单元测试首先完成并且构建保持绿色。有时,第二个“实时”集首先完成,当“断开连接”的集试图终止并清理时,它发现日志文件夹已被删除或出现错误,代码 1。不过,我对如何验证该假设感到困惑。我尝试将 karma 的 retryLimit 设置为 1(默认值为 2),但这似乎不会影响初始启动。

我注意到在这两种情况下您都遇到了 ChromeHeadless have not captured in 问题。成功的是它在启动前花了大约 1 分 15 秒。 我要做一些假设

  • 您有相当多的代码被编译为 运行
  • 你正在管道中使用代理(我想说它并不过分强大)

好消息是 karma 的 captureTimeout 默认为 60,000。我相信如果您将此设置添加到 karma.conf 并将其加倍,您将为 chrome 留出时间来处理您正在加载的所有测试。

您可能有第二个问题,您可能有一个非常激烈的测试,以至于 chrome 有时停止响应的时间超过 browserDisconnectTimeout