-
Notifications
You must be signed in to change notification settings - Fork 535
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
Enable timeout ensureSynchronized
everywhere (Solution #2)
#12303
Conversation
@vladsud This PR changes the behavior for what @anthony-murphy introduced with the original It is a little bit uglier, using monkey patching, but it gets the job done. Let me know if you have any other ideas. |
@agarwal-navin FYI, this solution would also fix AB#2182 |
e1dd06a
to
7270312
Compare
this.timeout = Math.max(timeout - timeBuffer, 1); | ||
|
||
// Set up timer to reject near the test timeout. | ||
this.timer = setTimeout(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this feels like a lot of complexity to just create a timer. i think i'd prefer to just make timeoutPromise smarter, and pull the timeout off the test in the default case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i'm hoping we could just do something like timeout = runnable.duration - runnable.timeout() - timeBuffer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if not. the below code in if (globalThis.getMochaModule !== undefined)
could just set some var to be the start time in runnablePrototype.resetTimeout. That and the current time would take the role of runnable.duration above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@anthony-murphy Capture the end time was my original solution. But that doesn't work fully:
- if the call to set the timeout is within the test itself, then we will have reset/clear/reset/clear. We need to have a way to cancel and change the rejection timeout for
timeoutPromise
that is already in flight. resetTimeout
get calls after the async test function is called returns the promise, it is too late to influence the timetimeoutPromise
that is already called in the test invocation beforeresetTimeout
Also timeoutPromise
also don't have access to the current runnable
. While we can capture that, but we it won't have the time elapsed so far (duration
is only set when the test is done)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change is flight makes sense? is it something our tests do? how high of fidelity do we want here? as i think the current mechanism would break with test parallelism?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have seen multiple test doing it at the beginning of the test. I can probably search for them and move it to outside, but I'd like to avoid it breaking in case something add a test that does that.
No. mocha parallelism is achieved via different process.
Monkey patch Mocha's
it
function to wrap test functions and capture how long the test is supposed to run until timeout and patch theresetTimeout
andclearTimeout
function on the test to trap the timeout tracking in mocha. It will set up a parallel timeout that will reject a promise fortimeoutPromise
right before the test would timeout.Remove the 5 min timeout for
ensureSynchronized
(which is unless for test) and use the now default behavior of the test timeout captured above. The purpose is to provide a better error message and stack ifensureSynchronized
got stuck.Also, change the behavior for
timeoutPromise
:timeoutPromise
has no affect. Only if you are inside the test function that it will use the test timeout.Fix AB#2175
This is an alternative solution to PR #12278