Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'pauseTest' doesn't reset the test timeout #496

Closed
azhiv opened this issue May 16, 2019 · 4 comments
Closed

'pauseTest' doesn't reset the test timeout #496

azhiv opened this issue May 16, 2019 · 4 comments

Comments

@azhiv
Copy link

azhiv commented May 16, 2019

In #291 the pauseTest method was updated in order to ignore the test timeout. However, this doesn't work as expected - putting await this.pauseTest(); somewhere in the test body doesn't actually prevent qunit to fail the test due to the timeout being hit. I found two workarounds:

  1. put assert.timeout(-1); in the beginning of the test
  2. run the test in devmode

The thing is none of this options is stated in the corresponding comment in addon-test-support/ember-qunit/index.js. This is a very convenient feature, so it would be really great to either update the comment or fix the behaviour to match the expected one.

@rwjblue
Copy link
Member

rwjblue commented May 16, 2019

Thank you for reporting!!! I took some time to dig into this issue the other day, and determine that the issue here is that when the test is an async function we have already returned a promise and qunit has already read the timeout value before you have a chance (in the test body) to set assert.timeout(-1).

Specifically, this is the order of events today:

  • QUnit invokes the test body (which is an async function) here
  • A promise is returned (because that is how async functions work) so Test.prototype.resolvePromise falls into the promise handling code here
  • Before chaining off the promise (to pass/fail the test based on success or failure) QUnit uses the current timeout value to set up a race against the promise resolution here
  • Only after all of that is the actual test body going to be invoked
  • Sometime later, the user calls await pauseTest() which calls this.pauseTest() here which ultimately invokes assert.timeout(-1) here
  • assert.timeout sets testInstance.timeout to the new value here, but never cancels/interacts with the timer created above by returning a promise from the test body

Proposed solution:

We need to update QUnit's implementation of assert.timeout to reset any current timeouts by canceling and setting up a new timer (if the timer is > 0).

@rwjblue
Copy link
Member

rwjblue commented May 16, 2019

Writing all that up made me realize there is a temporary work around we can do until we get the fixes in QUnit: #497.

@step2yeung
Copy link
Contributor

step2yeung commented Jun 24, 2019

Added a PR on QUnit for this! cc @rwjblue @scalvert

@rwjblue
Copy link
Member

rwjblue commented Aug 17, 2020

The fix from @step2yeung landed in qunit@2.9.3.

@rwjblue rwjblue closed this as completed Aug 17, 2020
Krinkle added a commit to Krinkle/ember-qunit that referenced this issue Mar 3, 2024
Follows-up emberjs#497 which introduced
this because QUnit 2.8 didn't support changing an existing `assert.timeout()`
by calling it again in the same test (it would leave the old one unchanged,
and start a second timeout).

This was fixed in QUnit 2.9.3, released in Oct 2019.

The ember-qunit package declares a peer dependency on `qunit@2.13.0`,
which should remove the need for this workaround.

Ref emberjs#496.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants