You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Semaphore imbalance when returned promise resolves when test timed out. #1375
What environment are you running QUnit in? (e.g., browser, Node): Browser & Node
How are you running QUnit? (e.g., script, testem, Grunt): qunit Node CLI / testem
What are you trying to do?
A test returning a promise (or an async) that runs longer than the allowed timeout period, causes an internal test semaphore imbalance if the returned promise ever settles.
Code that reproduces the problem:
QUnit.module('group of tests',function(hooks){QUnit.test('one',function(assert){assert.timeout(10);returnnewPromise(resolve=>setTimeout(resolve,20));});QUnit.test('two',function(assert){returnnewPromise(resolve=>setTimeout(resolve,20)).then(()=>{assert.ok(true,'all is well');});});});
I did some debugging with @scalvert for this issue on Friday and we believe we have a good understanding of what is going on and how to fix it (so hopefully we'll have a PR inbound soon), but I wanted to create the issue for discussion also.
The basic issue is that Test.prototype.resolvePromise here always calls resume (in both reject and fulfilled scenarios) which attempts to decrements the individual tests semaphore:
After a test timeout (see this for what that does) we reset the tests semaphore to 0, but we don't also prevent resume from running when the promise finally does resolve.
When the promise finally resolves, the test is "long gone" but resume is still called which decrements the tests semaphore (now to -1) and calls internalStart. When internalStart is called and the passed in test.semaphore < 0 we call pushFailure to log the semaphore imbalance.
Unfortunately, since pushFailurealways logs failures to the QUnit.config.current test (or creates a new global failure) this pushFailure about semaphore imbalance causes a completely unrelated test to fail (the test that happens to be running) not the test that actually had the imbalance.
Activity
rwjblue commentedon Feb 20, 2019
I did some debugging with @scalvert for this issue on Friday and we believe we have a good understanding of what is going on and how to fix it (so hopefully we'll have a PR inbound soon), but I wanted to create the issue for discussion also.
The basic issue is that
Test.prototype.resolvePromisehere always callsresume(in both reject and fulfilled scenarios) which attempts to decrements the individual tests semaphore:qunit/src/test.js
Lines 523 to 539 in 766db37
After a test timeout (see this for what that does) we reset the tests semaphore to
0, but we don't also preventresumefrom running when the promise finally does resolve.When the promise finally resolves, the test is "long gone" but
resumeis still called which decrements the tests semaphore (now to-1) and callsinternalStart. WheninternalStartis called and the passed intest.semaphore < 0we callpushFailureto log the semaphore imbalance.Unfortunately, since
pushFailurealways logs failures to theQUnit.config.currenttest (or creates a new global failure) thispushFailureabout semaphore imbalance causes a completely unrelated test to fail (the test that happens to be running) not the test that actually had the imbalance.trentmwillis commentedon Feb 21, 2019
Thanks y'all for the detailed report and PR to fix. I'll cut a new release tomorrow.