Skip to content

Commit ba7453a

Browse files
scalvertstefanpenner
authored andcommitted
Core: Ensuring semaphores are balanced when timeout occurs (#1376)
* Core: Ensuring semaphores are balanced when timeout occurs * Test: Loosening regex in tap-output for testing
1 parent 766db37 commit ba7453a

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

src/test.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,7 @@ export function only( testName, callback ) {
728728

729729
// Put a hold on processing and return a function that will release it.
730730
export function internalStop( test ) {
731+
let released = false;
731732
test.semaphore += 1;
732733
config.blocking = true;
733734

@@ -748,13 +749,13 @@ export function internalStop( test ) {
748749
`Test took longer than ${timeoutDuration}ms; test timed out.`,
749750
sourceFromStacktrace( 2 )
750751
);
752+
released = true;
751753
internalRecover( test );
752754
}, timeoutDuration );
753755
}
754756

755757
}
756758

757-
let released = false;
758759
return function resume() {
759760
if ( released ) {
760761
return;

test/cli/fixtures/expected/tap-outputs.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,26 @@ not ok 1 global failure
164164
# skip 0
165165
# todo 0
166166
# fail 1
167+
`,
168+
169+
"qunit timeout":
170+
`TAP version 13
171+
not ok 1 timeout > first
172+
---
173+
message: "Test took longer than 10ms; test timed out."
174+
severity: failed
175+
actual: null
176+
expected: undefined
177+
stack: at ontimeout (.*)
178+
at tryOnTimeout (.*)
179+
(.*)\\s*(.*)?
180+
...
181+
ok 2 timeout > second
182+
1..2
183+
# pass 1
184+
# skip 0
185+
# todo 0
186+
# fail 1
167187
`,
168188

169189
// in node 8, the stack trace includes 'at <anonymous>. But not in node 6 or 10.

test/cli/fixtures/timeout/index.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
QUnit.module( "timeout", function() {
2+
QUnit.test( "first", function( assert ) {
3+
assert.timeout( 10 );
4+
5+
return new Promise( resolve => setTimeout( resolve, 20 ) );
6+
} );
7+
8+
QUnit.test( "second", function( assert ) {
9+
return new Promise( resolve => setTimeout( resolve, 20 ) )
10+
.then( () => {
11+
assert.ok( true, "This promise resolved" );
12+
} );
13+
} );
14+
} );

test/cli/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ QUnit.module( "CLI Main", function() {
137137
}
138138
} ) );
139139

140+
QUnit.test( "timeouts correctly recover", co.wrap( function* ( assert ) {
141+
const command = "qunit timeout";
142+
try {
143+
yield execute( command );
144+
} catch ( e ) {
145+
assert.equal( e.code, 1 );
146+
assert.equal( e.stderr, "" );
147+
const re = new RegExp( expectedOutput[ command ] );
148+
assert.equal( re.test( e.stdout ), true );
149+
}
150+
} ) );
151+
140152
if ( semver.gte( process.versions.node, "9.0.0" ) ) {
141153
QUnit.test( "callbacks and hooks from modules are properly released for garbage collection", co.wrap( function* ( assert ) {
142154
const command = "node --expose-gc --allow-natives-syntax ../../../bin/qunit.js memory-leak/*.js";

0 commit comments

Comments
 (0)