Repository: zookeeper
Updated Branches:
  refs/heads/branch-3.4 ac5fa3f54 -> 83e0ab896


ZOOKEEPER-2786: Flaky test: 
org.apache.zookeeper.test.ClientTest.testNonExistingOpCode

On branch 3.4 we attempt to check that an invalid opcode in a request causes 
the server to disconnect the client with:

```
        try {
            zk.exists("/m1", false);
            fail("The connection should have been closed");
        } catch (KeeperException.ConnectionLossException expected) {
        }
```

This can run into a race with the reconnection logic in 
`ClientCnxn.java`https://github.com/apache/zookeeper/blob/branch-3.4/src/java/main/org/apache/zookeeper/ClientCnxn.java#L1052
 We should use a watcher instead to track disconnects.

Author: Abraham Fine <af...@apache.org>

Reviewers: Michael Han <h...@apache.org>

Closes #260 from afine/ZOOKEEPER-2786


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

Branch: refs/heads/branch-3.4
Commit: 83e0ab896991dc89af22e4a3b82af47f208d7f26
Parents: ac5fa3f
Author: Abraham Fine <af...@apache.org>
Authored: Thu Jun 15 15:35:58 2017 -0700
Committer: Michael Han <h...@apache.org>
Committed: Thu Jun 15 15:35:58 2017 -0700

----------------------------------------------------------------------
 src/java/test/org/apache/zookeeper/test/ClientTest.java | 11 ++++-------
 1 file changed, 4 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zookeeper/blob/83e0ab89/src/java/test/org/apache/zookeeper/test/ClientTest.java
----------------------------------------------------------------------
diff --git a/src/java/test/org/apache/zookeeper/test/ClientTest.java 
b/src/java/test/org/apache/zookeeper/test/ClientTest.java
index b2a1394..7b2d19a 100644
--- a/src/java/test/org/apache/zookeeper/test/ClientTest.java
+++ b/src/java/test/org/apache/zookeeper/test/ClientTest.java
@@ -774,7 +774,8 @@ public class ClientTest extends ClientBase {
      */
     @Test
     public void testNonExistingOpCode() throws Exception  {
-        TestableZooKeeper zk = createClient();
+        CountdownWatcher watcher = new CountdownWatcher();
+        TestableZooKeeper zk = createClient(watcher);
 
         final String path = "/m1";
 
@@ -785,13 +786,9 @@ public class ClientTest extends ClientBase {
         request.setWatch(false);
         ExistsResponse response = new ExistsResponse();
         ReplyHeader r = zk.submitRequest(h, request, response, null);
-
         Assert.assertEquals(r.getErr(), Code.UNIMPLEMENTED.intValue());
 
-        try {
-            zk.exists("/m1", false);
-            fail("The connection should have been closed");
-        } catch (KeeperException.ConnectionLossException expected) {
-        }
+        // Sending a nonexisting opcode should cause the server to disconnect
+        watcher.waitForDisconnected(5000);
     }
 }

Reply via email to