Skip to content

Commit

Permalink
Fix flaky tests with 'await' (#3972)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
atakavci authored Oct 17, 2024
1 parent f4b367d commit 498fee3
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 11 deletions.
7 changes: 7 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,13 @@
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.awaitility</groupId>
<artifactId>awaitility</artifactId>
<version>4.2.2</version>
<scope>test</scope>
</dependency>

<!-- circuit breaker / failover -->
<dependency>
<groupId>io.github.resilience4j</groupId>
Expand Down
5 changes: 4 additions & 1 deletion src/test/java/redis/clients/jedis/PipeliningTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.awaitility.Awaitility;

import redis.clients.jedis.commands.ProtocolCommand;
import redis.clients.jedis.commands.jedis.JedisCommandsTestBase;
Expand Down Expand Up @@ -342,7 +344,8 @@ public void waitAof() {

try (Jedis j = new Jedis(endpoint.getHostAndPort())) {
j.auth(endpoint.getPassword());
assertEquals("aof", j.get("wait"));
Awaitility.await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertEquals("aof", j.get("wait")));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.awaitility.Awaitility.await;

import java.util.Arrays;
import java.util.List;
import java.util.concurrent.TimeUnit;

import org.junit.After;
import org.junit.Before;
Expand Down Expand Up @@ -39,7 +41,8 @@ public void simple() {
control.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
control.del("foo");
assertNull(jedis.get("foo"));
await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertNull(jedis.get("foo")));
}
}

Expand All @@ -53,9 +56,8 @@ public void simpleWithSimpleMap() {
assertEquals(1, cache.getSize());
control.del("foo");
assertEquals(1, cache.getSize());
assertNull(jedis.get("foo"));
assertEquals(1, cache.getSize());
assertNull(jedis.get("foo"));
await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertNull(jedis.get("foo")));
assertEquals(1, cache.getSize());
}
}
Expand All @@ -67,7 +69,8 @@ public void flushAll() {
control.set("foo", "bar");
assertEquals("bar", jedis.get("foo"));
control.flushAll();
assertNull(jedis.get("foo"));
await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertNull(jedis.get("foo")));
}
}

Expand All @@ -81,9 +84,8 @@ public void flushAllWithSimpleMap() {
assertEquals(1, cache.getSize());
control.flushAll();
assertEquals(1, cache.getSize());
assertNull(jedis.get("foo"));
assertEquals(1, cache.getSize());
assertNull(jedis.get("foo"));
await().atMost(5, TimeUnit.SECONDS).pollInterval(50, TimeUnit.MILLISECONDS)
.untilAsserted(() -> assertNull(jedis.get("foo")));
assertEquals(1, cache.getSize());
}
}
Expand Down
2 changes: 0 additions & 2 deletions src/test/java/redis/clients/jedis/util/AssertUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,8 @@
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;

import org.junit.ComparisonFailure;
import redis.clients.jedis.RedisProtocol;

Expand Down

0 comments on commit 498fee3

Please sign in to comment.