Skip to content

Commit a5e8333

Browse files
authored
Improve timeoutConnection() test (#3404)
- Increase sleep time to increase chance of connection to be broken - Reset timeout config even if test fails
1 parent 8a5740d commit a5e8333

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

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

+18-15
Original file line numberDiff line numberDiff line change
@@ -80,27 +80,30 @@ public String getPassword() {
8080
public void timeoutConnection() throws Exception {
8181
Jedis jedis = new Jedis("localhost", 6379, 15000);
8282
jedis.auth("foobared");
83-
String timeout = jedis.configGet("timeout").get(1);
84-
jedis.configSet("timeout", "1");
85-
Thread.sleep(2000);
83+
// read current config
84+
final String timeout = jedis.configGet("timeout").get(1);
8685
try {
87-
jedis.hmget("foobar", "foo");
88-
fail("Operation should throw JedisConnectionException");
89-
} catch (JedisConnectionException jce) {
90-
// expected
86+
jedis.configSet("timeout", "1");
87+
Thread.sleep(5000);
88+
try {
89+
jedis.hmget("foobar", "foo");
90+
fail("Operation should throw JedisConnectionException");
91+
} catch (JedisConnectionException jce) {
92+
// expected
93+
}
94+
jedis.close();
95+
} finally {
96+
// reset config
97+
jedis = new Jedis("localhost", 6379);
98+
jedis.auth("foobared");
99+
jedis.configSet("timeout", timeout);
100+
jedis.close();
91101
}
92-
jedis.close();
93-
94-
// reset config
95-
jedis = new Jedis("localhost", 6379);
96-
jedis.auth("foobared");
97-
jedis.configSet("timeout", timeout);
98-
jedis.close();
99102
}
100103

101104
@Test
102105
public void infiniteTimeout() throws Exception {
103-
try (Jedis timeoutJedis = new Jedis("localhost", 6379, 350, 350, 350)) {
106+
try (Jedis timeoutJedis = new Jedis("localhost", 6379, 200, 200, 200)) {
104107
timeoutJedis.auth("foobared");
105108
try {
106109
timeoutJedis.blpop(0, "foo");

0 commit comments

Comments
 (0)