Skip to content

Commit 498fee3

Browse files
authored
Fix flaky tests with 'await' (#3972)
* fix flaky test - dumy set-get to gain time * adding same commands for 'simple' * introdue tryAssert in CSC tests * remove leftovers * introduce awaitility for polling * nit * fix pipelining test untilasserted
1 parent f4b367d commit 498fee3

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

pom.xml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,13 @@
143143
<scope>test</scope>
144144
</dependency>
145145

146+
<dependency>
147+
<groupId>org.awaitility</groupId>
148+
<artifactId>awaitility</artifactId>
149+
<version>4.2.2</version>
150+
<scope>test</scope>
151+
</dependency>
152+
146153
<!-- circuit breaker / failover -->
147154
<dependency>
148155
<groupId>io.github.resilience4j</groupId>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,14 @@
2020
import java.util.Map;
2121
import java.util.Set;
2222
import java.util.UUID;
23+
import java.util.concurrent.TimeUnit;
2324

2425
import org.hamcrest.Matcher;
2526
import org.hamcrest.Matchers;
2627
import org.junit.Test;
2728
import org.junit.runner.RunWith;
2829
import org.junit.runners.Parameterized;
30+
import org.awaitility.Awaitility;
2931

3032
import redis.clients.jedis.commands.ProtocolCommand;
3133
import redis.clients.jedis.commands.jedis.JedisCommandsTestBase;
@@ -342,7 +344,8 @@ public void waitAof() {
342344

343345
try (Jedis j = new Jedis(endpoint.getHostAndPort())) {
344346
j.auth(endpoint.getPassword());
345-
assertEquals("aof", j.get("wait"));
347+
Awaitility.await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
348+
.untilAsserted(() -> assertEquals("aof", j.get("wait")));
346349
}
347350
}
348351

src/test/java/redis/clients/jedis/csc/UnifiedJedisClientSideCacheTestBase.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@
33
import static org.junit.Assert.assertEquals;
44
import static org.junit.Assert.assertNotSame;
55
import static org.junit.Assert.assertNull;
6+
import static org.awaitility.Awaitility.await;
67

78
import java.util.Arrays;
89
import java.util.List;
10+
import java.util.concurrent.TimeUnit;
911

1012
import org.junit.After;
1113
import org.junit.Before;
@@ -39,7 +41,8 @@ public void simple() {
3941
control.set("foo", "bar");
4042
assertEquals("bar", jedis.get("foo"));
4143
control.del("foo");
42-
assertNull(jedis.get("foo"));
44+
await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
45+
.untilAsserted(() -> assertNull(jedis.get("foo")));
4346
}
4447
}
4548

@@ -53,9 +56,8 @@ public void simpleWithSimpleMap() {
5356
assertEquals(1, cache.getSize());
5457
control.del("foo");
5558
assertEquals(1, cache.getSize());
56-
assertNull(jedis.get("foo"));
57-
assertEquals(1, cache.getSize());
58-
assertNull(jedis.get("foo"));
59+
await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
60+
.untilAsserted(() -> assertNull(jedis.get("foo")));
5961
assertEquals(1, cache.getSize());
6062
}
6163
}
@@ -67,7 +69,8 @@ public void flushAll() {
6769
control.set("foo", "bar");
6870
assertEquals("bar", jedis.get("foo"));
6971
control.flushAll();
70-
assertNull(jedis.get("foo"));
72+
await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
73+
.untilAsserted(() -> assertNull(jedis.get("foo")));
7174
}
7275
}
7376

@@ -81,9 +84,8 @@ public void flushAllWithSimpleMap() {
8184
assertEquals(1, cache.getSize());
8285
control.flushAll();
8386
assertEquals(1, cache.getSize());
84-
assertNull(jedis.get("foo"));
85-
assertEquals(1, cache.getSize());
86-
assertNull(jedis.get("foo"));
87+
await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
88+
.untilAsserted(() -> assertNull(jedis.get("foo")));
8789
assertEquals(1, cache.getSize());
8890
}
8991
}

src/test/java/redis/clients/jedis/util/AssertUtil.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,8 @@
77
import java.util.Collection;
88
import java.util.Iterator;
99
import java.util.List;
10-
import java.util.Map;
1110
import java.util.Objects;
1211
import java.util.Set;
13-
1412
import org.junit.ComparisonFailure;
1513
import redis.clients.jedis.RedisProtocol;
1614

0 commit comments

Comments
 (0)