Avoid a hung test - put a time limit on the queue access
Project: http://git-wip-us.apache.org/repos/asf/curator/repo Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/aa5337b9 Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/aa5337b9 Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/aa5337b9 Branch: refs/heads/master Commit: aa5337b9c56776339bcdbf6acf260757e73d233f Parents: ad033cf Author: randgalt <randg...@apache.org> Authored: Sat Nov 9 18:44:30 2013 -0800 Committer: randgalt <randg...@apache.org> Committed: Sat Nov 9 18:44:30 2013 -0800 ---------------------------------------------------------------------- .../org/apache/curator/framework/imps/TestNeverConnected.java | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/curator/blob/aa5337b9/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNeverConnected.java ---------------------------------------------------------------------- diff --git a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNeverConnected.java b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNeverConnected.java index 49ac850..0402c45 100644 --- a/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNeverConnected.java +++ b/curator-framework/src/test/java/org/apache/curator/framework/imps/TestNeverConnected.java @@ -26,15 +26,19 @@ import org.apache.curator.framework.CuratorFrameworkFactory; import org.apache.curator.framework.state.ConnectionState; import org.apache.curator.framework.state.ConnectionStateListener; import org.apache.curator.retry.RetryOneTime; +import org.apache.curator.test.Timing; import org.testng.Assert; import org.testng.annotations.Test; import java.util.concurrent.BlockingQueue; +import java.util.concurrent.TimeUnit; public class TestNeverConnected { @Test public void testNeverConnected() throws Exception { + Timing timing = new Timing(); + // use a connection string to a non-existent server CuratorFramework client = CuratorFrameworkFactory.newClient("localhost:1111", 100, 100, new RetryOneTime(1)); try @@ -53,7 +57,8 @@ public class TestNeverConnected client.create().inBackground().forPath("/"); - Assert.assertEquals(queue.take(), ConnectionState.LOST); + ConnectionState polled = queue.poll(timing.forWaiting().seconds(), TimeUnit.SECONDS); + Assert.assertEquals(polled, ConnectionState.LOST); } finally {