File tree Expand file tree Collapse file tree 7 files changed +55
-5
lines changed
fixture/fail-fast/timeout Expand file tree Collapse file tree 7 files changed +55
-5
lines changed Original file line number Diff line number Diff line change @@ -73,10 +73,16 @@ export default class Api extends Emittery {
73
73
const pendingWorkers = new Set ( ) ;
74
74
const timedOutWorkerFiles = new Set ( ) ;
75
75
let restartTimer ;
76
+ let ignoreTimeoutsUntil = 0 ;
76
77
if ( apiOptions . timeout && ! apiOptions . debug ) {
77
78
const timeout = ms ( apiOptions . timeout ) ;
78
79
79
80
restartTimer = debounce ( ( ) => {
81
+ if ( Date . now ( ) < ignoreTimeoutsUntil ) {
82
+ restartTimer ( ) ;
83
+ return ;
84
+ }
85
+
80
86
// If failFast is active, prevent new test files from running after
81
87
// the current ones are exited.
82
88
if ( failFast ) {
@@ -233,6 +239,11 @@ export default class Api extends Emittery {
233
239
}
234
240
235
241
const worker = fork ( file , options , apiOptions . nodeArguments ) ;
242
+ worker . onStateChange ( data => {
243
+ if ( data . type === 'test-timeout-configured' && ! apiOptions . debug ) {
244
+ ignoreTimeoutsUntil = Math . max ( ignoreTimeoutsUntil , Date . now ( ) + data . period ) ;
245
+ }
246
+ } ) ;
236
247
runStatus . observeWorker ( worker , file , { selectingLines : lineNumbers . length > 0 } ) ;
237
248
deregisteredSharedWorkers . push ( observeWorkerProcess ( worker , runStatus ) ) ;
238
249
Original file line number Diff line number Diff line change @@ -66,6 +66,13 @@ export default class Runner extends Emittery {
66
66
return true ;
67
67
} ;
68
68
69
+ this . notifyTimeoutUpdate = timeoutMs => {
70
+ this . emit ( 'stateChange' , {
71
+ type : 'test-timeout-configured' ,
72
+ period : timeoutMs
73
+ } ) ;
74
+ } ;
75
+
69
76
let hasStarted = false ;
70
77
let scheduledStart = false ;
71
78
const meta = Object . freeze ( {
@@ -290,7 +297,8 @@ export default class Runner extends Emittery {
290
297
powerAssert : this . powerAssert ,
291
298
title : `${ task . title } ${ titleSuffix || '' } ` ,
292
299
isHook : true ,
293
- testPassed
300
+ testPassed,
301
+ notifyTimeoutUpdate : this . notifyTimeoutUpdate
294
302
} ) ) ;
295
303
const outcome = await this . runMultiple ( hooks , this . serial ) ;
296
304
for ( const result of outcome . storedResults ) {
@@ -341,7 +349,8 @@ export default class Runner extends Emittery {
341
349
metadata : task . metadata ,
342
350
powerAssert : this . powerAssert ,
343
351
title : task . title ,
344
- registerUniqueTitle : this . registerUniqueTitle
352
+ registerUniqueTitle : this . registerUniqueTitle ,
353
+ notifyTimeoutUpdate : this . notifyTimeoutUpdate
345
354
} ) ;
346
355
347
356
const result = await this . runSingle ( test ) ;
Original file line number Diff line number Diff line change @@ -208,6 +208,7 @@ export default class Test {
208
208
this . registerUniqueTitle = options . registerUniqueTitle ;
209
209
this . logs = [ ] ;
210
210
this . teardowns = [ ] ;
211
+ this . notifyTimeoutUpdate = options . notifyTimeoutUpdate ;
211
212
212
213
const { snapshotBelongsTo = this . title , nextSnapshotIndex = 0 } = options ;
213
214
this . snapshotBelongsTo = snapshotBelongsTo ;
@@ -431,6 +432,8 @@ export default class Test {
431
432
this . finishDueToTimeout ( ) ;
432
433
}
433
434
} , ms ) ;
435
+
436
+ this . notifyTimeoutUpdate ( this . timeoutMs ) ;
434
437
}
435
438
436
439
refreshTimeout ( ) {
Original file line number Diff line number Diff line change @@ -291,7 +291,8 @@ for (const opt of opts) {
291
291
292
292
return api . run ( { files : [
293
293
path . join ( __dirname , 'fixture/fail-fast/timeout/fails.cjs' ) ,
294
- path . join ( __dirname , 'fixture/fail-fast/timeout/passes.cjs' )
294
+ path . join ( __dirname , 'fixture/fail-fast/timeout/passes.cjs' ) ,
295
+ path . join ( __dirname , 'fixture/fail-fast/timeout/passes-slow.cjs' )
295
296
] } )
296
297
. then ( runStatus => {
297
298
t . ok ( api . options . failFast ) ;
Original file line number Diff line number Diff line change
1
+ const delay = require ( 'delay' ) ;
2
+
3
+ const test = require ( '../../../../entrypoints/main.cjs' ) ;
4
+
5
+ test ( 'slow pass with timeout' , async t => {
6
+ t . timeout ( 120 ) ;
7
+ await delay ( 110 ) ;
8
+ t . pass ( ) ;
9
+ } ) ;
Original file line number Diff line number Diff line change @@ -20,7 +20,8 @@ export function withExperiments(experiments = {}) {
20
20
fn,
21
21
registerUniqueTitle,
22
22
metadata : { type : 'test' } ,
23
- title
23
+ title,
24
+ notifyTimeoutUpdate ( ) { }
24
25
} ) ;
25
26
}
26
27
@@ -32,7 +33,8 @@ export function withExperiments(experiments = {}) {
32
33
fn,
33
34
registerUniqueTitle,
34
35
metadata : { type : 'test' , failing : true } ,
35
- title : 'test.failing'
36
+ title : 'test.failing' ,
37
+ notifyTimeoutUpdate ( ) { }
36
38
} ) ;
37
39
} ;
38
40
Original file line number Diff line number Diff line change @@ -63,6 +63,21 @@ test('runner emits "stateChange" events', t => {
63
63
} ) ;
64
64
} ) ;
65
65
66
+ test ( 'notifyTimeoutUpdate emits "stateChange" event' , t => {
67
+ const runner = new Runner ( ) ;
68
+
69
+ runner . on ( 'stateChange' , evt => {
70
+ if ( evt . type === 'test-timeout-configured' ) {
71
+ t . same ( evt , {
72
+ type : 'test-timeout-configured' ,
73
+ period : 120
74
+ } ) ;
75
+ t . end ( ) ;
76
+ }
77
+ } ) ;
78
+ runner . notifyTimeoutUpdate ( 120 ) ;
79
+ } ) ;
80
+
66
81
test ( 'run serial tests before concurrent ones' , t => {
67
82
const array = [ ] ;
68
83
return promiseEnd ( new Runner ( ) , runner => {
You can’t perform that action at this time.
0 commit comments