curator-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From randg...@apache.org
Subject curator git commit: More work on making tests more reliable. Also, for CURATOR-257, removed the enigmatic thread sleep in TestingZooKeeperMain.blockUntilStarted() in favor or more rigorous checks for the testing servers starting
Date Wed, 09 Sep 2015 13:30:58 GMT
Repository: curator
Updated Branches:
  refs/heads/CURATOR-3.0 520fc2c99 -> d71f49bf5


More work on making tests more reliable. Also, for CURATOR-257, removed the enigmatic thread
sleep in TestingZooKeeperMain.blockUntilStarted() in favor or more rigorous checks for the
testing servers starting


Project: http://git-wip-us.apache.org/repos/asf/curator/repo
Commit: http://git-wip-us.apache.org/repos/asf/curator/commit/d71f49bf
Tree: http://git-wip-us.apache.org/repos/asf/curator/tree/d71f49bf
Diff: http://git-wip-us.apache.org/repos/asf/curator/diff/d71f49bf

Branch: refs/heads/CURATOR-3.0
Commit: d71f49bf56ef0e158cf180c7366fbee3ffe3dfb9
Parents: 520fc2c
Author: randgalt <randgalt@apache.org>
Authored: Wed Sep 9 08:30:51 2015 -0500
Committer: randgalt <randgalt@apache.org>
Committed: Wed Sep 9 08:30:51 2015 -0500

----------------------------------------------------------------------
 .../nodes/TestPersistentEphemeralNode.java      |  5 +--
 .../queue/TestDistributedDelayQueue.java        |  9 +++--
 .../recipes/queue/TestDistributedQueue.java     |  2 +-
 .../curator/test/TestingQuorumPeerMain.java     | 18 +++++++--
 .../curator/test/TestingZooKeeperMain.java      | 40 +++++++++++++++++---
 .../java/org/apache/curator/test/Timing.java    | 12 +++++-
 pom.xml                                         |  2 +
 7 files changed, 72 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/curator/blob/d71f49bf/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
index 011000b..4162886 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/nodes/TestPersistentEphemeralNode.java
@@ -387,10 +387,8 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
                 // Kill the session, thus cleaning up the node...
                 KillSession.kill(curator.getZookeeperClient().getZooKeeper());
 
-                timing.sleepABit();
-
                 // Make sure the node ended up getting deleted...
-                assertTrue(deletionTrigger.firedWithin(timing.forSessionSleep().seconds(),
TimeUnit.SECONDS));
+                assertTrue(deletionTrigger.firedWithin(timing.multiple(1.5).forSessionSleep().seconds(),
TimeUnit.SECONDS));
                 node.debugReconnectLatch.countDown();
 
                 // Now put a watch in the background looking to see if it gets created...
@@ -718,6 +716,7 @@ public class TestPersistentEphemeralNode extends BaseClassForTests
             }
             catch ( InterruptedException e )
             {
+                Thread.currentThread().interrupt();
                 throw Throwables.propagate(e);
             }
         }

http://git-wip-us.apache.org/repos/asf/curator/blob/d71f49bf/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java
index 74cd2ee..a76f449 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedDelayQueue.java
@@ -138,10 +138,13 @@ public class TestDistributedDelayQueue extends BaseClassForTests
     @Test
     public void testSorting() throws Exception
     {
+        Timing                          timing = new Timing();
+
         //Need to use a fairly large number to ensure that sorting can take some time.
         final int QTY = 1000;
 
-        Timing                          timing = new Timing();
+        final int DELAY_MS = timing.multiple(.1).milliseconds();
+
         DistributedDelayQueue<Long>     putQueue = null;
         DistributedDelayQueue<Long>     getQueue = null;
         CuratorFramework                client = CuratorFrameworkFactory.newClient(server.getConnectString(),
timing.session(), timing.connection(), new RetryOneTime(1));
@@ -157,7 +160,7 @@ public class TestDistributedDelayQueue extends BaseClassForTests
             //been added prior to the consumption starting. Otherwise it's possible to start
             //processing entries before they've all been added so the ordering will be 
             //incorrect.
-            long delay = System.currentTimeMillis() + 5000;            
+            long delay = System.currentTimeMillis() + DELAY_MS;
             for ( long i = 0; i < QTY; ++i )
             {
                 data.put(delay, i);
@@ -184,7 +187,7 @@ public class TestDistributedDelayQueue extends BaseClassForTests
             long lastValue = -1;
             for ( int i = 0; i < QTY; ++i )
             {
-                Long value = consumer.take(6, TimeUnit.SECONDS);
+                Long value = consumer.take(DELAY_MS * 2, TimeUnit.MILLISECONDS);
                 Assert.assertNotNull(value);
                 Assert.assertEquals(value, new Long(lastValue + 1));
                 lastValue = value;

http://git-wip-us.apache.org/repos/asf/curator/blob/d71f49bf/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java
----------------------------------------------------------------------
diff --git a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java
b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java
index a191166..2f0f9a8 100644
--- a/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java
+++ b/curator-recipes/src/test/java/org/apache/curator/framework/recipes/queue/TestDistributedQueue.java
@@ -175,7 +175,7 @@ public class TestDistributedQueue extends BaseClassForTests
                 "/lock",
                 QueueBuilder.NOT_SET,
                 true,
-                5000
+                timing.milliseconds()
             )
             {
                 @SuppressWarnings("SimplifiableConditionalExpression")

http://git-wip-us.apache.org/repos/asf/curator/blob/d71f49bf/curator-test/src/main/java/org/apache/curator/test/TestingQuorumPeerMain.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/TestingQuorumPeerMain.java
b/curator-test/src/main/java/org/apache/curator/test/TestingQuorumPeerMain.java
index 9f9f302..e1c1f89 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingQuorumPeerMain.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingQuorumPeerMain.java
@@ -63,18 +63,26 @@ class TestingQuorumPeerMain extends QuorumPeerMain implements ZooKeeperMainFace
     {
         if ( quorumPeer != null )
         {
-            quorumPeer.shutdown();
+            try
+            {
+                quorumPeer.shutdown();
+            }
+            finally
+            {
+                quorumPeer = null;
+            }
         }
     }
 
     @Override
     public void blockUntilStarted() throws Exception
     {
-        while ( quorumPeer == null )
+        long startTime = System.currentTimeMillis();
+        while ( (quorumPeer == null) && ((System.currentTimeMillis() - startTime)
<= TestingZooKeeperMain.MAX_WAIT_MS) )
         {
             try
             {
-                Thread.sleep(100);
+                Thread.sleep(10);
             }
             catch ( InterruptedException e )
             {
@@ -82,5 +90,9 @@ class TestingQuorumPeerMain extends QuorumPeerMain implements ZooKeeperMainFace
                 break;
             }
         }
+        if ( quorumPeer == null )
+        {
+            throw new Exception("quorumPeer never got set");
+        }
     }
 }

http://git-wip-us.apache.org/repos/asf/curator/blob/d71f49bf/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
b/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
index a13ce9c..7d0c6a1 100644
--- a/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
+++ b/curator-test/src/main/java/org/apache/curator/test/TestingZooKeeperMain.java
@@ -37,7 +37,7 @@ public class TestingZooKeeperMain extends ZooKeeperServerMain implements
ZooKeep
     private final CountDownLatch latch = new CountDownLatch(1);
     private final AtomicReference<Exception> startingException = new AtomicReference<Exception>(null);
 
-    private static final int MAX_WAIT_MS = 1000;
+    static final int MAX_WAIT_MS = new Timing().milliseconds();
 
     @Override
     public void kill()
@@ -105,9 +105,15 @@ public class TestingZooKeeperMain extends ZooKeeperServerMain implements
ZooKeep
                     }
                 }
             }
+            else
+            {
+                throw new Exception("No zkServer");
+            }
+        }
+        else
+        {
+            throw new Exception("No connection factory");
         }
-
-        Thread.sleep(1000);
 
         Exception exception = startingException.get();
         if ( exception != null )
@@ -162,8 +168,20 @@ public class TestingZooKeeperMain extends ZooKeeperServerMain implements
ZooKeep
         do
         {
             cnxnFactory = (ServerCnxnFactory)cnxnFactoryField.get(this);
+            if ( cnxnFactory == null )
+            {
+                try
+                {
+                    Thread.sleep(10);
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                    throw e;
+                }
+            }
         }
-        while ( (cnxnFactory == null) && ((System.currentTimeMillis() - startTime)
< MAX_WAIT_MS) );
+        while ( (cnxnFactory == null) && ((System.currentTimeMillis() - startTime)
<= MAX_WAIT_MS) );
 
         return cnxnFactory;
     }
@@ -174,11 +192,23 @@ public class TestingZooKeeperMain extends ZooKeeperServerMain implements
ZooKeep
         zkServerField.setAccessible(true);
         ZooKeeperServer zkServer;
 
-        // Wait until the zkServer field is non-null or up to 1s, whichever comes first.
+        // Wait until the zkServer field is non-null
         long startTime = System.currentTimeMillis();
         do
         {
             zkServer = (ZooKeeperServer)zkServerField.get(cnxnFactory);
+            if ( zkServer == null )
+            {
+                try
+                {
+                    Thread.sleep(10);
+                }
+                catch ( InterruptedException e )
+                {
+                    Thread.currentThread().interrupt();
+                    throw e;
+                }
+            }
         }
         while ( (zkServer == null) && ((System.currentTimeMillis() - startTime) <
MAX_WAIT_MS) );
 

http://git-wip-us.apache.org/repos/asf/curator/blob/d71f49bf/curator-test/src/main/java/org/apache/curator/test/Timing.java
----------------------------------------------------------------------
diff --git a/curator-test/src/main/java/org/apache/curator/test/Timing.java b/curator-test/src/main/java/org/apache/curator/test/Timing.java
index 5eb5bc0..27e4e53 100644
--- a/curator-test/src/main/java/org/apache/curator/test/Timing.java
+++ b/curator-test/src/main/java/org/apache/curator/test/Timing.java
@@ -213,13 +213,23 @@ public class Timing
     }
 
     /**
+     * Return a new timing with a multiple for sleeping a smaller amount of time
+     *
+     * @return this timing multiplied
+     */
+    public Timing forSleepingABit()
+    {
+        return multiple(.25);
+    }
+
+    /**
      * Sleep for a small amount of time
      *
      * @throws InterruptedException if interrupted
      */
     public void sleepABit() throws InterruptedException
     {
-        unit.sleep(value / 4);
+        forSleepingABit().sleep();
     }
 
     /**

http://git-wip-us.apache.org/repos/asf/curator/blob/d71f49bf/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index d67e52b..b48ff54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -637,6 +637,8 @@
                 <artifactId>maven-surefire-plugin</artifactId>
                 <configuration>
                     <redirectTestOutputToFile>true</redirectTestOutputToFile>
+                    <threadCount>1</threadCount>
+                    <reuseForks>false</reuseForks>
                 </configuration>
             </plugin>
 


Mime
View raw message