-
-
Notifications
You must be signed in to change notification settings - Fork 640
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
Test of sleep
has flaked in CI
#4010
Comments
Can you please share a link to the PR? This is an interesting situation! |
It is, isn't it! The PR in question was #3958. |
Okay, so luckily it appears to be a one-off situation. It may be because we use |
This is partly lucky, and partly very unlucky. 🙂 A "flake" like this, where the test sometimes fails when nothing is actually wrong, reduces people's confidence in the tests, and makes it more tempting for people to ignore failures instead of learning from them. What's definitely lucky is that, as I understand it, Ray and Greg have a lot of experience with some pretty bad test flakes on projects before they were employed at Zulip, so avoiding them in Zulip has been a priority. @ray-kraesig added the use of Lolex, in #3886, for most tests involving time, to avoid exactly this kind of flake. Corresponding to this test's naming as "(real)", as opposed to the other one that says "(ideal)", it looks like it doesn't use Lolex; it actually waits 1000-ish milliseconds, following the instruction to wait 1000 milliseconds. The reason for keeping a non-Lolex sleep test is best explained in the commit message for 019cc09e3:
Apparently, on that failure, the actual sleep time was 999 milliseconds, which is surprising to me; I considered the instructed number of milliseconds to be an inclusive lower bound on the actual number of milliseconds. But now I'm looking, I haven't found documentation to confirm that. |
PR #4045 failed Travis-CI due to this, ( my PR failing again while resolving conflicts :( ) |
Sometimes, `setTimeout(1000)` will fire after only 999 milliseconds. This appears to be due to an upstream bug in Node.js itself [1]. Closes zulip#4010. [1] nodejs/node#26578
When a test fails, Jest's error messages lean quite hard on this expectation. Here's a failure from zulip#4010: ● sleep (real) › waits for approximately the right number of milliseconds expect(received).toBeLessThanOrEqual(expected) Expected: <= 999 Received: 1000 (Plus the "received" and "1000" are highlighted in red, and the "expected" and "999" in green.) The truth is that we expected a value >= 1000 and received 999, so having it shown backward comes out pretty confusing. Flip the arguments so Jest shows them the right way around.
Ray found the cause of this -- here's his commit message for the fix (which I just merged):
As I wrote on the PR: it's reassuring, in a way, that this turns out to be a specific bug in Node with an understood cause that puts an upper bound on its effect. Less reassuring that the maintainers seem pretty blasé about whether to do anything about it. :-/ |
In a recent PR with no changes to either
async.js
orasync-test.js
, one of the tests for "sleep" flaked, mysteriously sleeping for only 999 milliseconds rather than 1000.The text was updated successfully, but these errors were encountered: