diff options
author | guice.mirrorbot@gmail.com <guice.mirrorbot@gmail.com@d779f126-a31b-0410-b53b-1d3aecad763e> | 2011-10-16 22:34:21 +0000 |
---|---|---|
committer | guice.mirrorbot@gmail.com <guice.mirrorbot@gmail.com@d779f126-a31b-0410-b53b-1d3aecad763e> | 2011-10-16 22:34:21 +0000 |
commit | b405e0417151915b98c3d2033adb9770336a7bbb (patch) | |
tree | dcacfeb9940f4c80524c4bf618212a3612f95110 /extensions/service | |
parent | 7e5464ef25b98ea8f1988040d3623b93129ff1f4 (diff) | |
download | guice-b405e0417151915b98c3d2033adb9770336a7bbb.tar.gz |
Fix flaky service test. The whole AsyncService thing probably should just be rm'd, but fixing the test for now.
Revision created by MOE tool push_codebase.
MOE_MIGRATION=3475
git-svn-id: https://google-guice.googlecode.com/svn/trunk@1591 d779f126-a31b-0410-b53b-1d3aecad763e
Diffstat (limited to 'extensions/service')
-rw-r--r-- | extensions/service/test/com/google/inject/service/SingleServiceIntegrationTest.java | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/extensions/service/test/com/google/inject/service/SingleServiceIntegrationTest.java b/extensions/service/test/com/google/inject/service/SingleServiceIntegrationTest.java index ca36b472..9463b166 100644 --- a/extensions/service/test/com/google/inject/service/SingleServiceIntegrationTest.java +++ b/extensions/service/test/com/google/inject/service/SingleServiceIntegrationTest.java @@ -7,6 +7,7 @@ import java.util.concurrent.CountDownLatch; import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; +import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicInteger; @@ -17,7 +18,7 @@ import java.util.concurrent.atomic.AtomicInteger; public class SingleServiceIntegrationTest extends TestCase { - public final void testAsyncServiceLifecycle() throws InterruptedException { + public final void testAsyncServiceLifecycle() throws Exception { ExecutorService executor = Executors.newSingleThreadExecutor(); final CountDownLatch startLatch = new CountDownLatch(1); @@ -38,9 +39,14 @@ public class SingleServiceIntegrationTest extends TestCase { } }; - service.start(); - // This should not pass! + Future<?> future = service.start(); + // This should not pass! TODO(sameb): Why? Looks like it should to me assertTrue(startLatch.await(2, TimeUnit.SECONDS)); + // onStart() is called before the state is set to STARTED, so we need + // to wait until the Future finishes to guarantee it really was started. + // This still manages to test what we want because the startLatch check + // is before this. + future.get(1, TimeUnit.SECONDS); service.stop(); assertTrue(stopLatch.await(2, TimeUnit.SECONDS)); |