Skip to content

Commit

Permalink
Modify FAILOVER tests to reduce flakyness (#2780)
Browse files Browse the repository at this point in the history
  • Loading branch information
sazzad16 committed Dec 28, 2021
1 parent db53e13 commit ea18faa
Showing 1 changed file with 8 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class FailoverCommandsTest {
private HostAndPort masterAddress;
private HostAndPort replicaAddress;

private boolean switched;
private boolean switching;

@BeforeClass
public static void setUp() {
Expand Down Expand Up @@ -50,12 +50,12 @@ public void prepare() {
fail();
}

switched = false;
switching = false;
}

@After
public void cleanUp() {
if (switched) {
if (switching) {
try {
Thread.sleep(250);
} catch (InterruptedException ex) { }
Expand All @@ -64,11 +64,9 @@ public void cleanUp() {

@Test
public void failoverMaster() throws InterruptedException {
//
try (Jedis master = new Jedis(masterAddress)) {
assertEquals("OK", master.failover());
Thread.sleep(120); // allow some time to failover;
// not too much as everything is happening in same machine
Thread.sleep(250);
assertEquals("slave", master.role().get(0));
}
}
Expand All @@ -77,6 +75,7 @@ public void failoverMaster() throws InterruptedException {
public void failoverReplica() {
try (Jedis replica = new Jedis(replicaAddress)) {
replica.failover();
fail("FAILOVER is not valid when server is a replica.");
} catch(JedisDataException ex) {
assertEquals("ERR FAILOVER is not valid when server is a replica.", ex.getMessage());
}
Expand All @@ -85,9 +84,9 @@ public void failoverReplica() {
@Test
public void failoverToHAP() throws InterruptedException {
try (Jedis master = new Jedis(masterAddress)) {
switching = true;
assertEquals("OK", master.failover(FailoverParams.failoverParams()
.to(new HostAndPort("127.0.0.1", replicaAddress.getPort()))));
switched = true;
}
}

Expand All @@ -110,16 +109,17 @@ public void failoverForceWithoutTimeoutFailFast() {
@Test
public void failoverForce() throws InterruptedException {
try (Jedis master = new Jedis(masterAddress)) {
switching = true;
assertEquals("OK", master.failover(FailoverParams.failoverParams()
.to(new HostAndPort("127.0.0.1", replicaAddress.getPort())).force().timeout(100)));
switched = true;
}
}

@Test
public void failoverToWrongPort() {
try (Jedis master = new Jedis(masterAddress)) {
master.failover(FailoverParams.failoverParams().to("127.0.0.1", 6300));
fail("FAILOVER target HOST and PORT is not a replica.");
} catch(JedisDataException ex) {
assertEquals("ERR FAILOVER target HOST and PORT is not a replica.", ex.getMessage());
}
Expand Down

0 comments on commit ea18faa

Please sign in to comment.