Skip to content

Commit

Permalink
testCnxManagerTimeout should use valid ip that is not reachable.
Browse files Browse the repository at this point in the history
The random number returned can be signed hence negative and
for those cases test fails quickly. For a valid ip that is
not reachable ittakes a while longer to declare connection failure.
  • Loading branch information
Powell Molleti committed Mar 17, 2017
1 parent ec219a4 commit dcab629
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/java/test/org/apache/zookeeper/test/CnxManagerTest.java
Expand Up @@ -187,15 +187,13 @@ public void testCnxManager() throws Exception {
@Test
public void testCnxManagerTimeout() throws Exception {
Random rand = new Random();
byte b = (byte) rand.nextInt();
int deadPort = PortAssignment.unique();
String deadAddress = "10.1.1." + b;
String deadAddress = "10.1.1." + (rand.nextInt(254) + 1);

LOG.info("This is the dead address I'm trying: " + deadAddress);

peers.put(Long.valueOf(2),
new QuorumServer(2,
new ServerCfg(deadAddress, new InetSocketAddress(deadAddress, deadPort)),
new ServerCfg(deadAddress, new InetSocketAddress(deadAddress, PortAssignment.unique())),
new ServerCfg(deadAddress, new InetSocketAddress(deadAddress, PortAssignment.unique())),
new ServerCfg(deadAddress, new InetSocketAddress(deadAddress, PortAssignment.unique()))));
peerTmpdir[2] = ClientBase.createTmpDir();
Expand All @@ -213,7 +211,7 @@ public void testCnxManagerTimeout() throws Exception {
cnxManager.toSend(2L, createMsg(ServerState.LOOKING.ordinal(), 1, -1, 1));
long end = Time.currentElapsedTime();

if((end - begin) > 6000) Assert.fail("Waited more than necessary");
if((end - begin) > 15000) Assert.fail("Waited more than necessary");
cnxManager.halt();
Assert.assertFalse(cnxManager.listener.isAlive());
}
Expand Down

0 comments on commit dcab629

Please sign in to comment.