I've found the number one cause of flakiness in tests is from misuse of nondeterministic or highly stateful functions. This becomes especially apparent when you recognize a lot of nondeterminism comes from misusing datetime libraries such as momentJS, or from Math.random . Even integration tests against certain "eventually consistent" databases tends to result in flakey tests. Entropy and Time libraries are intention…
Yes, definitely that. I've also seen entire piles of tests be flaky because: - They relied on something or other over the network, or - They used Selenium to try to see whether the Dom was updated correctly, and either Selenium itself or the way the code interacted with it made _all_ the tests flaky to some degree. The general trend I've seen is that the more "e2e" a test is, the flakier it is.
Probabilistic Flakiness: How do you test your tests?
31–36 of 36 posts
Re: Probabilistic Flakiness: How do you test your tests?
#32Yet again, a problem is not solved but paved over by a new level of indirection, and the house of cards grows taller.
Re: Probabilistic Flakiness: How do you test your tests?
#33They can't help it, each facebook engineering blog post has to start with that scale porn.
Re: Probabilistic Flakiness: How do you test your tests?
#34I've found the number one cause of flakiness in tests is from misuse of nondeterministic or highly stateful functions. This becomes especially apparent when you recognize a lot of nondeterminism comes from misusing datetime libraries such as momentJS, or from Math.random . Even integration tests against certain "eventually consistent" databases tends to result in flakey tests. Entropy and Time libraries are intention…
For testing purposes I often find myself making functions that take the date as an argument. If the language supports default values, I'll set it as a default value. If it doesn't, I'll make a convenience method or a null check to set it to 'now' if none is provided.
It turns out though that a lot of code we write to run within ±30 seconds of 'now' ends up over time having to run (or re-run) on old or future dates. So with the exception of logging and events, having that as an argument turns out to be useful or at least neutral.
For logging and events I'd probably use a mock timing library anyway.
Re: Probabilistic Flakiness: How do you test your tests?
#35Earlier quoted context omitted.
Agreed. Flaky tests are a bug and the only agreeable solution is to identify and remove the non-deterministic inputs.
But sometimes the bug is in the code not the test, and you wouldn't have known about the bug if you didn't write the flaky test! A flaky test which fails once in every N test suite runs is better than no test at all.
Tests I've found are much the same way. You don't write one flaky test and stop. If you write one and everybody is okay with it, you and your coworkers write more, and more, until there are 50, 100. Once the suite flakes out on an interval, nobody takes a failed test seriously, and then broken code doesn't get checked for hours. One broken test? I bet it's the usual. I'll just rerun it a couple of times.
The thread you're pulling on here starts to unravel the whole Continuous Integration sweater.