a case of unstable test
Jul. 29th, 2010 09:30 amI have an entity A, and append an entity B to its set of "children". Somehow the entity A already has one child of type B, so there's more than one. It's okay. Except that I did not expect it.
Then, assuming there's just one child, I take the first one, and check its values. And kaboom, which one is retrieved, changes from test to test. Why is it? Well, it depends on its hashcode, right? Since it is in a set, etc. And the hashcode depends on its values. And its values include creation time, which is, well, since we don't care, is taken from System.currentTimeMillis(). So the test's behavior depends on the millisecond in which the test is launched.
As a solution, of course, I have to add the check for the size of the set. But, in any case, having tests which behavior depends on current time makes them flaky by default.
Then, assuming there's just one child, I take the first one, and check its values. And kaboom, which one is retrieved, changes from test to test. Why is it? Well, it depends on its hashcode, right? Since it is in a set, etc. And the hashcode depends on its values. And its values include creation time, which is, well, since we don't care, is taken from System.currentTimeMillis(). So the test's behavior depends on the millisecond in which the test is launched.
As a solution, of course, I have to add the check for the size of the set. But, in any case, having tests which behavior depends on current time makes them flaky by default.