Fix race condition in JedisSentinelPoolTest

The test was issuing the failover command and only afterwards
connecting to the pub-sub channel to receive failover notifications.
If the failover occurred fast enought the pub-sub listener would never
get the notification.

Run the failover command on a separate Jedis connection after we're
absolutely sure that we're subscribed to the pub-sub channel.
This commit is contained in:
Nelson Rodrigues
2014-07-28 10:56:21 -07:00
parent 9e128b4520
commit 9013078d40
3 changed files with 11 additions and 7 deletions

View File

@@ -8,7 +8,8 @@ import redis.clients.jedis.JedisPubSub;
import redis.clients.jedis.tests.utils.FailoverAbortedException;
public class JedisSentinelTestUtil {
public static HostAndPort waitForNewPromotedMaster(Jedis sentinelJedis)
public static HostAndPort waitForNewPromotedMaster(final String masterName,
final Jedis sentinelJedis, final Jedis commandJedis)
throws InterruptedException {
final AtomicReference<String> newmaster = new AtomicReference<String>(
@@ -47,6 +48,7 @@ public class JedisSentinelTestUtil {
@Override
public void onPSubscribe(String pattern, int subscribedChannels) {
commandJedis.sentinelFailover(masterName);
}
}, "*");