-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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
question, test: best way to retry async task #13346
Comments
I dislike 1 because it results in tests that are unreliable under load. I like 2. People sometimes seem surprised when they see it, but it has yet to cause problems. I don't have a problem with option 3 for the most part, but a potential issue with number 3 is that it makes tests unrunnable in older versions of Node.js. Often, when refactoring a test, I'll run it in an older version where it is expected to fail to make sure it still fails. This is not an issue for newer tests, of course. |
Should we add a helper to Or we can document 2 as an idiom (and 3 is self explanatory) |
I prefer documenting the idiom to a new helper function. My bar for adding yet more stuff to |
Should this remain open? |
Closing, as this should be turned into PR. |
master
test
In some tests we want to delay or retry an async task whose exact timing for success is indeterminable.
A few option come to mind:
setTimeout(task, n)
wheren
is an arbitrary number that's empirically proven to be sufficient.const interval = setInterval(() => {const ret = task(); if (ret) clearInterval(interval);}), 1)
do { const ret = await task()} while (ret != true)
Any other ideas or preferences?
Ref: #13252
Ref: #13312
/cc @nodejs/testing
The text was updated successfully, but these errors were encountered: