@@ -135,7 +135,7 @@ describe('launchers/process.js', () => {
135
135
} )
136
136
} )
137
137
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
139
139
it ( 'start -> timeout -> restart' , ( done ) => {
140
140
// start
141
141
launcher . start ( 'http://localhost/' )
@@ -245,4 +245,55 @@ describe('launchers/process.js', () => {
245
245
} )
246
246
} )
247
247
} )
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
+ } )
248
299
} )
0 commit comments