move close too quick check into CLI (#4186)

This commit is contained in:
Gleb Bahmutov
2019-05-13 17:08:33 -04:00
committed by GitHub
parent d25cfacc6f
commit b21918921b
4 changed files with 45 additions and 38 deletions
+22 -2
View File
@@ -1,4 +1,6 @@
const _ = require('lodash')
const la = require('lazy-ass')
const is = require('check-more-types')
const os = require('os')
const cp = require('child_process')
const path = require('path')
@@ -46,6 +48,18 @@ function getStdio (needsXvfb) {
return 'inherit'
}
/**
* Returns true if DISPLAY is set for Linux platform
* and the application exits really quickly.
*/
const isPotentialDisplayProblem = (platform, display, code, elapsedMs) => {
la(is.unemptyString(platform), 'missing platform', platform)
la(is.number(code), 'expected exit code to be a number', code)
la(elapsedMs >= 0, 'elapsed ms should be >= 0', elapsedMs)
return platform === 'linux' && display && code === 1 && elapsedMs < 1000
}
module.exports = {
start (args, options = {}) {
const needsXvfb = xvfb.isNeeded()
@@ -168,11 +182,17 @@ module.exports = {
debug('DISPLAY is %s', process.env.DISPLAY)
}
const electronStarted = Number(new Date())
return spawn()
.then((code) => {
const POTENTIAL_DISPLAY_PROBLEM_EXIT_CODE = 234
const electronFinished = Number(new Date())
const elapsed = electronFinished - electronStarted
if (shouldRetryOnDisplayProblem && code === POTENTIAL_DISPLAY_PROBLEM_EXIT_CODE) {
debug('electron open returned %d after %d ms', code, elapsed)
if (shouldRetryOnDisplayProblem &&
isPotentialDisplayProblem(os.platform(), process.env.DISPLAY, code, elapsed)) {
debug('Cypress thinks there is a potential display or OS problem')
debug('retrying the command with our XVFB')