Skip to content

Commit 2c609cf

Browse files
authored
Fix flakyness of JedisPooledTest (#3506)
1 parent 155acfd commit 2c609cf

File tree

1 file changed

+8
-9
lines changed

1 file changed

+8
-9
lines changed

src/test/java/redis/clients/jedis/JedisPooledTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package redis.clients.jedis;
22

33
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.hamcrest.Matchers.anything;
45
import static org.hamcrest.Matchers.equalTo;
56
import static org.hamcrest.Matchers.greaterThanOrEqualTo;
67
import static org.junit.Assert.assertEquals;
7-
import static org.junit.Assert.assertNull;
88
import static org.junit.Assert.assertTrue;
99
import static org.junit.Assert.fail;
1010

@@ -22,6 +22,7 @@
2222
public class JedisPooledTest {
2323

2424
private static final HostAndPort hnp = HostAndPorts.getRedisServers().get(7);
25+
private static final HostAndPort pwp = HostAndPorts.getRedisServers().get(1); // password protected
2526

2627
@Test
2728
public void checkCloseableConnections() {
@@ -177,17 +178,16 @@ public void testResetValidCredentials() {
177178
DefaultRedisCredentialsProvider credentialsProvider =
178179
new DefaultRedisCredentialsProvider(new DefaultRedisCredentials(null, "bad password"));
179180

180-
try (JedisPooled pool = new JedisPooled(HostAndPorts.getRedisServers().get(0),
181-
DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider)
182-
.clientName("my_shiny_client_name").build())) {
181+
try (JedisPooled pool = new JedisPooled(pwp, DefaultJedisClientConfig.builder()
182+
.credentialsProvider(credentialsProvider).build())) {
183183
try {
184184
pool.get("foo");
185185
fail("Should not get resource from pool");
186186
} catch (JedisException e) { }
187187
assertEquals(0, pool.getPool().getNumActive());
188188

189189
credentialsProvider.setCredentials(new DefaultRedisCredentials(null, "foobared"));
190-
assertNull(pool.get("foo"));
190+
assertThat(pool.get("foo"), anything());
191191
}
192192
}
193193

@@ -238,9 +238,8 @@ public void cleanUp() {
238238
GenericObjectPoolConfig<Connection> poolConfig = new GenericObjectPoolConfig<>();
239239
poolConfig.setMaxTotal(1);
240240
poolConfig.setTestOnBorrow(true);
241-
try (JedisPooled pool = new JedisPooled(HostAndPorts.getRedisServers().get(0),
242-
DefaultJedisClientConfig.builder().credentialsProvider(credentialsProvider)
243-
.build(), poolConfig)) {
241+
try (JedisPooled pool = new JedisPooled(pwp, DefaultJedisClientConfig.builder()
242+
.credentialsProvider(credentialsProvider).build(), poolConfig)) {
244243
try {
245244
pool.get("foo");
246245
fail("Should not get resource from pool");
@@ -251,7 +250,7 @@ public void cleanUp() {
251250
assertThat(cleanupCount.getAndSet(0), greaterThanOrEqualTo(1));
252251

253252
validPassword.set(true);
254-
assertNull(pool.get("foo"));
253+
assertThat(pool.get("foo"), anything());
255254
assertThat(prepareCount.get(), equalTo(1));
256255
assertThat(cleanupCount.get(), equalTo(1));
257256
}

0 commit comments

Comments
 (0)