Set timeout in the main process

This commit is contained in:
Antonio Scandurra
2015-10-09 08:55:11 +02:00
parent 43d0241685
commit 4863b71fd7
4 changed files with 10 additions and 23 deletions

View File

@@ -497,6 +497,13 @@ class AtomApplication
if resourcePath isnt @resourcePath and not fs.existsSync(resourcePath)
resourcePath = @resourcePath
timeout = Number.parseFloat(timeout)
unless Number.isNaN(timeout)
timeoutHandler = ->
console.log "The test suite has timed out because it has been running for more than #{timeout} minutes."
process.exit(124) # Use the same exit code as the UNIX timeout util.
setTimeout(timeoutHandler, timeout * 60 * 1000)
try
windowInitializationScript = require.resolve(path.resolve(@devResourcePath, 'src', 'initialize-test-window'))
catch error
@@ -516,7 +523,7 @@ class AtomApplication
isSpec = true
devMode = true
safeMode ?= false
new AtomWindow({windowInitializationScript, resourcePath, headless, isSpec, devMode, testRunnerPath, legacyTestRunnerPath, testPaths, logFile, safeMode, timeout})
new AtomWindow({windowInitializationScript, resourcePath, headless, isSpec, devMode, testRunnerPath, legacyTestRunnerPath, testPaths, logFile, safeMode})
resolveTestRunnerPath: (testPath) ->
FindParentDir ?= require 'find-parent-dir'

View File

@@ -19,7 +19,7 @@ class AtomWindow
isSpec: null
constructor: (settings={}) ->
{@resourcePath, pathToOpen, locationsToOpen, @isSpec, @headless, @safeMode, @devMode, timeout} = settings
{@resourcePath, pathToOpen, locationsToOpen, @isSpec, @headless, @safeMode, @devMode} = settings
locationsToOpen ?= [{pathToOpen}] if pathToOpen
locationsToOpen ?= []

View File

@@ -5,7 +5,6 @@ try
path = require 'path'
ipc = require 'ipc'
remote = require 'remote'
app = remote.require('app')
{getWindowLoadSettings} = require './window-load-settings-helpers'
AtomEnvironment = require '../src/atom-environment'
@@ -33,11 +32,6 @@ try
document.title = "Spec Suite"
if timeout = getWindowLoadSettings().timeout
ChildProcess = remote.require("child_process")
timeoutCop = ChildProcess.fork(require.resolve('./timeout-cop'), [remote.process.pid, timeout])
app.on "will-exit", -> timeoutCop.kill()
legacyTestRunner = require(getWindowLoadSettings().legacyTestRunnerPath)
testRunner = require(getWindowLoadSettings().testRunnerPath)
testRunner({
@@ -50,7 +44,7 @@ try
catch error
if getWindowLoadSettings().headless
console.error(error.stack ? error)
app.emit('will-exit')
remote.require('app').emit('will-exit')
remote.process.exit(status)
else
throw error

View File

@@ -1,14 +0,0 @@
'use strict'
let parentProcessId = process.argv[2]
let timeoutInMinutes = process.argv[3]
let timeoutInMilliseconds = timeoutInMinutes * 1000 * 60
function exitTestRunner () {
process.kill(parentProcessId, 'SIGINT')
let errorMessage = 'The test suite has timed out because it has been running'
errorMessage += ' for more than ' + timeoutInMinutes + ' minutes.'
console.log(errorMessage)
}
setTimeout(exitTestRunner, timeoutInMilliseconds)