Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix flaky tests with 'await' #3972

Merged
merged 7 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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")));
Comment on lines +347 to +348
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❤️

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it. Got to add it to Lettuce tests too at some point!

}
}

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;

sazzad16 marked this conversation as resolved.
Show resolved Hide resolved
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
Loading