youtube/vitess — pull request #128 by enisoc (2014-10-30 08:38:31+00:00)
Title: Deflake TestMarkDown in vtgate balancer.

@guoliang100

The vtgate balancer test seems flaky, according to a user who got this:

--- FAIL: TestMarkDown (0.02 seconds)
balancer_test.go:161: want <20ms, got 20.75796ms

I don't see any reason why the measured time would be exactly 2 times retryDelay, so I'm assuming it's a coincidence. That means the program just organically took 20.75796ms since the first mark-down, perhaps due to all the sorting and shuffling on a slow VM. I increased the retryDelay to 100ms to help catch a non-waiting Get() on slower machines, but the real issue this user saw is from the max time check.

I removed the max time check because I don't think it makes sense to require the time to be less than some value. The contract of the code-under-test is satisfied as long as Get() returns at all (and later than retryDelay since the first mark-down). I changed the test to effectively time out only if Get() hangs due to a bad value passed to Sleep().