From 2c609cfb3adab13ae843aacc862389cca454951a Mon Sep 17 00:00:00 2001 From: M Sazzadul Hoque <7600764+sazzad16@users.noreply.github.com> Date: Sat, 19 Aug 2023 08:35:12 +0600 Subject: [PATCH] Fix flakyness of JedisPooledTest (#3506) --- .../redis/clients/jedis/JedisPooledTest.java | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/src/test/java/redis/clients/jedis/JedisPooledTest.java b/src/test/java/redis/clients/jedis/JedisPooledTest.java index cdae9a5965..6036062f5b 100644 --- a/src/test/java/redis/clients/jedis/JedisPooledTest.java +++ b/src/test/java/redis/clients/jedis/JedisPooledTest.java @@ -1,10 +1,10 @@ package redis.clients.jedis; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.anything; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; @@ -22,6 +22,7 @@ public class JedisPooledTest { private static final HostAndPort hnp = HostAndPorts.getRedisServers().get(7); + private static final HostAndPort pwp = HostAndPorts.getRedisServers().get(1); // password protected @Test public void checkCloseableConnections() { @@ -177,9 +178,8 @@ public void testResetValidCredentials() { DefaultRedisCredentialsProvider credentialsProvider = new DefaultRedisCredentialsProvider(new DefaultRedisCredentials(null, "bad password")); - try (JedisPooled pool = new JedisPooled(HostAndPorts.getRedisServers().get(0), - DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider) - .clientName("my_shiny_client_name").build())) { + try (JedisPooled pool = new JedisPooled(pwp, DefaultJedisClientConfig.builder() + .credentialsProvider(credentialsProvider).build())) { try { pool.get("foo"); fail("Should not get resource from pool"); @@ -187,7 +187,7 @@ public void testResetValidCredentials() { assertEquals(0, pool.getPool().getNumActive()); credentialsProvider.setCredentials(new DefaultRedisCredentials(null, "foobared")); - assertNull(pool.get("foo")); + assertThat(pool.get("foo"), anything()); } } @@ -238,9 +238,8 @@ public void cleanUp() { GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig<>(); poolConfig.setMaxTotal(1); poolConfig.setTestOnBorrow(true); - try (JedisPooled pool = new JedisPooled(HostAndPorts.getRedisServers().get(0), - DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider) - .build(), poolConfig)) { + try (JedisPooled pool = new JedisPooled(pwp, DefaultJedisClientConfig.builder() + .credentialsProvider(credentialsProvider).build(), poolConfig)) { try { pool.get("foo"); fail("Should not get resource from pool"); @@ -251,7 +250,7 @@ public void cleanUp() { assertThat(cleanupCount.getAndSet(0), greaterThanOrEqualTo(1)); validPassword.set(true); - assertNull(pool.get("foo")); + assertThat(pool.get("foo"), anything()); assertThat(prepareCount.get(), equalTo(1)); assertThat(cleanupCount.get(), equalTo(1)); }