Skip to content

Commit 5257df1

Browse files
committed
Take async cache writes into consideration
Since Spring Data Redis 4.0 and when using Lettuce, entries may be written to the cache asynchronously. This means that they may not be immediately visible to a subsequent read. This commit adapts the test to use Awaitility to wait for the expected entry to become visible in the cache. Closes gh-50356
1 parent 7cfd94a commit 5257df1

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

smoke-test/spring-boot-smoke-test-cache/src/dockerTest/java/smoketest/cache/SampleCacheApplicationRedisTests.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616

1717
package smoketest.cache;
1818

19+
import java.time.Duration;
20+
1921
import com.redis.testcontainers.RedisContainer;
22+
import org.awaitility.Awaitility;
2023
import org.junit.jupiter.api.Test;
2124
import org.testcontainers.junit.jupiter.Container;
2225
import org.testcontainers.junit.jupiter.Testcontainers;
@@ -52,9 +55,11 @@ void validateCache() {
5255
countries.clear(); // Simple test assuming the cache is empty
5356
assertThat(countries.get("BE")).isNull();
5457
Country be = this.countryRepository.findByCode("BE");
55-
ValueWrapper belgium = countries.get("BE");
56-
assertThat(belgium).isNotNull();
57-
assertThat((Country) belgium.get()).isEqualTo(be);
58+
Awaitility.waitAtMost(Duration.ofSeconds(10)).untilAsserted(() -> {
59+
ValueWrapper belgium = countries.get("BE");
60+
assertThat(belgium).isNotNull();
61+
assertThat((Country) belgium.get()).isEqualTo(be);
62+
});
5863
}
5964

6065
}

0 commit comments

Comments
 (0)