Skip to content

Commit 99a1d48

Browse files
committed
fix(runner): Test process kill timeout config
Add new unit test for processKillTimeout configuration Closes #2447
1 parent a128e5c commit 99a1d48

File tree

1 file changed

+52
-1
lines changed

1 file changed

+52
-1
lines changed

Diff for: test/unit/launchers/process.spec.js

+52-1
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ describe('launchers/process.js', () => {
135135
})
136136
})
137137

138-
// when the browser fails to get captured in given timeout, it should restart
138+
// when the browser fails to get captured in default timeout, it should restart
139139
it('start -> timeout -> restart', (done) => {
140140
// start
141141
launcher.start('http://localhost/')
@@ -245,4 +245,55 @@ describe('launchers/process.js', () => {
245245
})
246246
})
247247
})
248+
249+
// higher level tests - process kill timeout
250+
describe('process-kill-timeout', () => {
251+
var failureSpy
252+
var mockTimer = null
253+
254+
beforeEach(() => {
255+
mockTimer = createMockTimer()
256+
CaptureTimeoutLauncher.call(launcher, mockTimer, 100)
257+
ProcessLauncher.call(launcher, mockSpawn, mockTempDir, mockTimer, 300)
258+
RetryLauncher.call(launcher, 2)
259+
260+
launcher._getCommand = () => BROWSER_PATH
261+
262+
failureSpy = sinon.spy()
263+
emitter.on('browser_process_failure', failureSpy)
264+
})
265+
266+
// when the browser fails to get captured in default timeout, it should restart
267+
it('start -> capture_timeout -> kill -> process_kill_timeout -> sigkill', () => {
268+
// start
269+
launcher.start('http://localhost/')
270+
271+
// expect starting the process
272+
expect(mockSpawn).to.have.been.calledWith(BROWSER_PATH, ['http://localhost/?id=fake-id'])
273+
var browserProcess = mockSpawn._processes.shift()
274+
275+
// timeout
276+
mockTimer.wind(101)
277+
278+
// expect killing browser
279+
expect(browserProcess.kill).to.have.been.called
280+
281+
// processKillTimeout not reached yet
282+
mockTimer.wind(299)
283+
284+
// SIGKILL not called yet
285+
expect(browserProcess.kill.withArgs('SIGKILL')).not.to.have.been.called
286+
287+
// processKillTimeout
288+
mockTimer.wind(301)
289+
290+
// expect killing with SIGKILL
291+
expect(browserProcess.kill.withArgs('SIGKILL')).to.have.been.called
292+
293+
browserProcess.emit('exit', 0)
294+
mockTempDir.remove.callArg(1)
295+
mockTempDir.remove.reset()
296+
mockSpawn.reset()
297+
})
298+
})
248299
})

0 commit comments

Comments
 (0)