Fix Flakey Unit Tests This change restores two unit tests that failed regularly when run under Windows. Both of these tests time how long it takes to shutdown either the Application or the Service, and in both cases it took slightly longer than expected. I believe the timing constraints were too tight, especially for ShutdownWaiterTest.testShutdownFullWait(), which told the waiter to wait 50 milliseconds for the shutdown to complete and complained if it took more than 58 milliseconds. This could be an issue if shutdown took many seconds, minutes, or forever, but taking 10 or 20 milliseconds longer to shutdown should not really be considered a problem. Before I disabled the test, shutdown was taking slightly more than 58 milliseconds most of the time, with an occasional breach of 60 milliseconds when run on my Windows VM. I bumped the ceiling to 65 ms and could easily be convinced that 75 or 100 ms would be acceptable. I also replaced instances of "Mu" with "microseconds" in the error messages, since the character did not display correctly in the windows shell. The second flakey test, ApplicationTest.testFastShutdownWhenStarting(), I was unable to get it to fail again in 100 attempts. I even ran 2 instances of the Connector Manager coverage tests at the same time, each of which pegs the CPUs. I thought I would overheat the machine with all 4 cores pegged for nearly an hour. Therefore, I restored the test unchanged. If it starts failing again, we should address it then. Code Review: http://codereview.appspot.com/83000045
diff --git a/test/com/google/enterprise/adaptor/ApplicationTest.java b/test/com/google/enterprise/adaptor/ApplicationTest.java index 90d07f0..e30a728 100644 --- a/test/com/google/enterprise/adaptor/ApplicationTest.java +++ b/test/com/google/enterprise/adaptor/ApplicationTest.java
@@ -103,7 +103,6 @@ assertFalse(adaptor.hasBeenShutdownAtSomePoint); } - /* TODO (pjo): FLAKEY This fails on windows with took a long time... @Test public void testFastShutdownWhenStarting() throws Exception { class FailAlwaysAdaptor extends NullAdaptor { @@ -134,7 +133,6 @@ + duration); } } - */ @Test public void testFastShutdown() throws Exception {
diff --git a/test/com/google/enterprise/adaptor/ShutdownWaiterTest.java b/test/com/google/enterprise/adaptor/ShutdownWaiterTest.java index 38327e5..2da76da 100644 --- a/test/com/google/enterprise/adaptor/ShutdownWaiterTest.java +++ b/test/com/google/enterprise/adaptor/ShutdownWaiterTest.java
@@ -55,7 +55,8 @@ long timeTakenUs = TimeUnit.MICROSECONDS.convert( System.nanoTime() - start, TimeUnit.NANOSECONDS); assertFalse(Thread.currentThread().isInterrupted()); - assertTrue("shutdown took " + timeTakenUs + "µs", timeTakenUs < 1300); + assertTrue("shutdown took " + timeTakenUs + " microseconds", + timeTakenUs < 1300); } @Test @@ -65,7 +66,6 @@ waiter.processingStarting(Thread.currentThread()); } - /* TODO (pjo): FLAKEY Test taking 58000+ on Windows @Test public void testInterruptFullWait() throws Exception { final AtomicBoolean interrupted = new AtomicBoolean(); @@ -90,11 +90,11 @@ assertTrue(interrupted.get()); waiter.processingCompleted(testThread); // Because the test blocks, it causes noticeable variation occasionally. - // Thus the high amount of slop. - assertTrue("shutdown took " + timeTakenUs + "µs", - timeTakenUs > 48000 && timeTakenUs < 58000); + // Thus the high amount of slop. Consider bumping the maximum to + // 75000 or even 100000 if this test continues to fail frequently. + assertTrue("shutdown took " + timeTakenUs + " microseconds", + timeTakenUs > 48000 && timeTakenUs < 65000); } - */ @Test public void testInterruptNonfullWait() throws Exception { @@ -128,6 +128,7 @@ long timeTakenUs = TimeUnit.MICROSECONDS.convert( System.nanoTime() - start, TimeUnit.NANOSECONDS); assertTrue(completed.get()); - assertTrue("shutdown took " + timeTakenUs + "µs", timeTakenUs < 1000); + assertTrue("shutdown took " + timeTakenUs + " microseconds", + timeTakenUs < 1000); } }