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

Enable timeout ensureSynchronized everywhere (Solution #2) #12303

Merged
merged 13 commits into from
Oct 15, 2022

Conversation

curtisman
Copy link
Member

@curtisman curtisman commented Oct 6, 2022

Monkey patch Mocha's it function to wrap test functions and capture how long the test is supposed to run until timeout and patch the resetTimeout and clearTimeout function on the test to trap the timeout tracking in mocha. It will set up a parallel timeout that will reject a promise for timeoutPromise 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 if ensureSynchronized got stuck.

Also, change the behavior for timeoutPromise:

  • when duration is <=0 or Infinity. Instead of waiting for the default amount, it will now mean it won't timeout at all. This is so that we can avoid timeout when debugging.
  • By default, when no duration is specified, 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

@curtisman curtisman requested review from msfluid-bot and a team as code owners October 6, 2022 16:10
@github-actions github-actions bot added area: dds: propertydds area: driver Driver related issues area: odsp-driver area: tests Tests to add, test infrastructure improvements, etc dependencies Pull requests that update a dependency file labels Oct 6, 2022
@curtisman curtisman marked this pull request as draft October 6, 2022 16:10
@github-actions github-actions bot added the base: next PRs targeted against next branch label Oct 6, 2022
@curtisman
Copy link
Member Author

curtisman commented Oct 6, 2022

@vladsud This PR changes the behavior for what @anthony-murphy introduced with the original timeoutPromise concept, but it will get a more reliable timeout based on the test's timeout setup. What do you think?

It is a little bit uglier, using monkey patching, but it gets the job done. Let me know if you have any other ideas.

@curtisman
Copy link
Member Author

curtisman commented Oct 6, 2022

@agarwal-navin FYI, this solution would also fix AB#2182

@curtisman curtisman force-pushed the timeout2 branch 4 times, most recently from e1dd06a to 7270312 Compare October 7, 2022 03:09
@curtisman curtisman marked this pull request as ready for review October 8, 2022 13:41
@github-actions github-actions bot added the public api change Changes to a public API label Oct 9, 2022
this.timeout = Math.max(timeout - timeBuffer, 1);

// Set up timer to reject near the test timeout.
this.timer = setTimeout(() => {
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Contributor

@anthony-murphy anthony-murphy Oct 11, 2022

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

Copy link
Member Author

@curtisman curtisman Oct 11, 2022

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 time timeoutPromise that is already called in the test invocation before resetTimeout

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)

Copy link
Contributor

@anthony-murphy anthony-murphy Oct 14, 2022

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?

Copy link
Member Author

@curtisman curtisman Oct 14, 2022

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.

@github-actions github-actions bot removed the dependencies Pull requests that update a dependency file label Oct 13, 2022
@curtisman curtisman merged commit 9eb2dc6 into microsoft:next Oct 15, 2022
@curtisman curtisman deleted the timeout2 branch October 17, 2022 16:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: dds: propertydds area: driver Driver related issues area: odsp-driver area: tests Tests to add, test infrastructure improvements, etc base: next PRs targeted against next branch public api change Changes to a public API
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants