From 5257df1bb16b28b171ffb8125ef151aaf82d7cb7 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 7 May 2026 15:42:50 +0100 Subject: [PATCH] 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 --- .../cache/SampleCacheApplicationRedisTests.java | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/smoke-test/spring-boot-smoke-test-cache/src/dockerTest/java/smoketest/cache/SampleCacheApplicationRedisTests.java b/smoke-test/spring-boot-smoke-test-cache/src/dockerTest/java/smoketest/cache/SampleCacheApplicationRedisTests.java index 7517b02720a..b36661a9320 100644 --- a/smoke-test/spring-boot-smoke-test-cache/src/dockerTest/java/smoketest/cache/SampleCacheApplicationRedisTests.java +++ b/smoke-test/spring-boot-smoke-test-cache/src/dockerTest/java/smoketest/cache/SampleCacheApplicationRedisTests.java @@ -16,7 +16,10 @@ package smoketest.cache; +import java.time.Duration; + import com.redis.testcontainers.RedisContainer; +import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; import org.testcontainers.junit.jupiter.Container; import org.testcontainers.junit.jupiter.Testcontainers; @@ -52,9 +55,11 @@ class SampleCacheApplicationRedisTests { countries.clear(); // Simple test assuming the cache is empty assertThat(countries.get("BE")).isNull(); Country be = this.countryRepository.findByCode("BE"); - ValueWrapper belgium = countries.get("BE"); - assertThat(belgium).isNotNull(); - assertThat((Country) belgium.get()).isEqualTo(be); + Awaitility.waitAtMost(Duration.ofSeconds(10)).untilAsserted(() -> { + ValueWrapper belgium = countries.get("BE"); + assertThat(belgium).isNotNull(); + assertThat((Country) belgium.get()).isEqualTo(be); + }); } }