Skip to content

Commit

Permalink
test: Added wait
Browse files Browse the repository at this point in the history
  • Loading branch information
jruaux committed Jun 19, 2023
1 parent ea2072e commit f6932dc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,8 @@ void teardownTarget() {
@BeforeEach
void flushAllTarget() throws InterruptedException {
targetConnection.sync().flushall();
awaitUntil(() -> targetConnection.sync().dbsize().equals(0L));
RedisModulesCommands<String, String> sync = targetConnection.sync();
awaitEquals(() -> 0L, sync::dbsize);
}

@Override
Expand Down Expand Up @@ -421,7 +422,7 @@ void fileImportDump() throws Exception {
RedisServerCommands<String, String> sync = connection.sync();
sync.flushall();
execute("dump-import", this::configureDumpFileImportCommand);
Assertions.assertEquals(records.size(), sync.dbsize());
awaitEquals(records::size, sync::dbsize);
}

private void configureDumpFileImportCommand(CommandLine.ParseResult parseResult) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.function.Supplier;

import org.awaitility.Awaitility;
import org.codehaus.plexus.util.cli.CommandLineUtils;
Expand All @@ -31,6 +32,7 @@
import org.springframework.core.task.SyncTaskExecutor;

import com.redis.lettucemod.api.StatefulRedisModulesConnection;
import com.redis.lettucemod.api.sync.RedisModulesCommands;
import com.redis.lettucemod.util.ClientBuilder;
import com.redis.lettucemod.util.RedisModulesUtils;
import com.redis.riot.cli.common.AbstractCommand;
Expand Down Expand Up @@ -100,7 +102,8 @@ void setupTest() throws Exception {
jobLauncher.setTaskExecutor(new SyncTaskExecutor());
stepBuilderFactory = new StepBuilderFactory(jobRepository, new ResourcelessTransactionManager());
connection.sync().flushall();
awaitUntil(() -> connection.sync().dbsize().equals(0L));
RedisModulesCommands<String, String> sync = connection.sync();
awaitEquals(() -> 0l, sync::dbsize);
}

protected void awaitUntilFalse(Callable<Boolean> conditionEvaluator) {
Expand All @@ -111,6 +114,10 @@ protected void awaitUntil(Callable<Boolean> conditionEvaluator) {
Awaitility.await().timeout(DEFAULT_AWAIT_TIMEOUT).until(conditionEvaluator);
}

protected void awaitEquals(Supplier<Object> expected, Supplier<Object> actual) {
awaitUntil(() -> expected.get().equals(actual.get()));
}

protected AbstractRedisClient client(RedisServer server) {
return ClientBuilder.create(RedisURI.create(server.getRedisURI())).cluster(server.isCluster()).build();
}
Expand Down

0 comments on commit f6932dc

Please sign in to comment.