From 4e6cc376192ebbf5c632fbf425f1552a3d31eb68 Mon Sep 17 00:00:00 2001 From: Lauri Tulmin Date: Thu, 19 Dec 2024 15:33:50 +0200 Subject: [PATCH] Rework shutdown in lettuce 5.0 tests --- .../lettuce/v5_0/AbstractLettuceClientTest.java | 13 +++++++++++++ .../lettuce/v5_0/LettuceAsyncClientTest.java | 2 +- .../lettuce/v5_0/LettuceReactiveClientTest.java | 2 +- .../lettuce/v5_0/LettuceSyncClientTest.java | 2 +- 4 files changed, 16 insertions(+), 3 deletions(-) diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/AbstractLettuceClientTest.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/AbstractLettuceClientTest.java index 18a58f875881..cb90534b13dd 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/AbstractLettuceClientTest.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/AbstractLettuceClientTest.java @@ -11,6 +11,7 @@ import io.opentelemetry.instrumentation.testing.internal.AutoCleanupExtension; import io.opentelemetry.instrumentation.testing.junit.AgentInstrumentationExtension; import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension; +import java.util.concurrent.TimeUnit; import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -78,4 +79,16 @@ protected static StatefulRedisConnection newContainerConnection( return statefulConnection; } + + static void shutdown(RedisClient redisClient) { + // using shutdownAsync instead of redisClient.shutdown() because there is a bug in the redis + // client that can cause the shutdown to hang + try { + redisClient.shutdownAsync(0, 15, TimeUnit.SECONDS).get(15, TimeUnit.SECONDS); + } catch (InterruptedException exception) { + Thread.currentThread().interrupt(); + } catch (Exception exception) { + // ignore + } + } } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncClientTest.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncClientTest.java index b03ceb0fa556..9f8b2258719c 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncClientTest.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceAsyncClientTest.java @@ -93,7 +93,7 @@ static void setUp() throws UnknownHostException { @AfterAll static void cleanUp() { connection.close(); - redisClient.shutdown(); + shutdown(redisClient); redisServer.stop(); } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceReactiveClientTest.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceReactiveClientTest.java index 416a963ca048..1bc93dd586a1 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceReactiveClientTest.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceReactiveClientTest.java @@ -63,7 +63,7 @@ static void setUp() throws UnknownHostException { @AfterAll static void cleanUp() { connection.close(); - redisClient.shutdown(); + shutdown(redisClient); redisServer.stop(); } diff --git a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceSyncClientTest.java b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceSyncClientTest.java index d84a4bc437a9..de26734dd98d 100644 --- a/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceSyncClientTest.java +++ b/instrumentation/lettuce/lettuce-5.0/javaagent/src/test/java/io/opentelemetry/javaagent/instrumentation/lettuce/v5_0/LettuceSyncClientTest.java @@ -74,7 +74,7 @@ static void setUp() throws UnknownHostException { @AfterAll static void cleanUp() { connection.close(); - redisClient.shutdown(); + shutdown(redisClient); redisServer.stop(); }