-
Notifications
You must be signed in to change notification settings - Fork 29.7k
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
investigate flaky test-timers-promisified #37395
Comments
Refs: #37226 but this looks different |
Here's the code that's failing. In this code, {
// Check that the timing is correct
let pre = false;
let post = false;
setPromiseTimeout(1).then(() => pre = true);
const iterable = setInterval(() => {}, 2);
const iterator = iterable[Symbol.asyncIterator]();
iterator.next().then(common.mustCall(() => {
assert.ok(pre, 'interval ran too early');
assert.ok(!post, 'interval ran too late');
return iterator.next();
})).then(common.mustCall(() => {
assert.ok(post, 'second interval ran too early');
return iterator.return();
}));
setPromiseTimeout(3).then(() => post = true);
} |
I think we established already that Node makes no timing guarantees (at the moment) other than:
(I think this behaviour is very counterintuitive, but I also acknowledge I was just not aware of it for a pretty long time - and fixing this is hard) Since the order of timers is not guaranteed - I would write these tests using mocks (mock out Timeout or something a-la @sinon/fake-timers). I think any fix we will make to these sort of tests is inherently flakey if it relies on a guarantee timers don't make. |
I'm not sure if this is the other bug, I think that there's timer "drift" happening here. Maybe relying on 1-2-3 ms timers wasn't such a great idea. I agree with @benjamingr that it's difficult to fix this correctly, although with the current timer implementation I think that without the second check ('second interval ran too early') this test shouldn't fail. |
FWIW I’ve had a bad run of consecutive failures so I ran a stress test to check this is still flaky and hasn’t become consistently failing. It is still flaky, failing 436 times out of 1000: https://ci.nodejs.org/job/node-stress-single-test/nodes=rhel7-s390x/217/ |
@richardlau #37425 is an attempt to fix this if you want to give that a review. |
https://ci.nodejs.org/job/node-test-commit-linuxone/25660/nodes=rhel7-s390x/console
The text was updated successfully, but these errors were encountered: