From cef59e7d8263e1cdb5354dce3e92ed4c2c1f16b4 Mon Sep 17 00:00:00 2001 From: EddeCCC Date: Thu, 12 Sep 2024 15:59:41 +0200 Subject: [PATCH] improve tests --- .../agent/integrationtest/spring/ScopeTest.java | 11 +++++------ .../instrumentation/InstrumentationStateTest.java | 7 +++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/test/java/rocks/inspectit/gepard/agent/integrationtest/spring/ScopeTest.java b/src/test/java/rocks/inspectit/gepard/agent/integrationtest/spring/ScopeTest.java index a16a704..cf638a6 100644 --- a/src/test/java/rocks/inspectit/gepard/agent/integrationtest/spring/ScopeTest.java +++ b/src/test/java/rocks/inspectit/gepard/agent/integrationtest/spring/ScopeTest.java @@ -5,8 +5,8 @@ import java.util.concurrent.TimeUnit; import okhttp3.Call; import okhttp3.Request; -import org.junit.jupiter.api.Test; import org.awaitility.Awaitility; +import org.junit.jupiter.api.Test; public class ScopeTest extends SpringTestBase { @@ -129,7 +129,8 @@ private void assertLogs(String logs, int times) { } /** - * Checks, if a specific message can be found for a specific amount of times inside the provided logs. + * Checks, if a specific message can be found for a specific amount of times inside the provided + * logs. * * @return true, if the message appears the expected amount of times in the logs */ @@ -163,13 +164,14 @@ private int countTimes(String logs, String message) { * logs. First the method counts the current amount of update messages. If the amount of update * messages has increased, it is assumed that a new configuration has been pooled. */ - private void awaitConfigurationUpdate() throws InterruptedException { + private void awaitConfigurationUpdate() { String updateMessage = "Fetched configuration from configuration server and received status code 200"; String logs = target.getLogs(); int configUpdateCount = countTimes(logs, updateMessage); Awaitility.await() + .pollDelay(5, TimeUnit.SECONDS) .atMost(15, TimeUnit.SECONDS) .until( () -> { @@ -177,8 +179,5 @@ private void awaitConfigurationUpdate() throws InterruptedException { int currentConfigUpdateCount = countTimes(newLogs, updateMessage); return currentConfigUpdateCount > configUpdateCount; }); - - // Wait an additional second as puffer - Thread.sleep(1000); } } diff --git a/src/test/java/rocks/inspectit/gepard/agent/internal/instrumentation/InstrumentationStateTest.java b/src/test/java/rocks/inspectit/gepard/agent/internal/instrumentation/InstrumentationStateTest.java index 27aee33..f9ed8ba 100644 --- a/src/test/java/rocks/inspectit/gepard/agent/internal/instrumentation/InstrumentationStateTest.java +++ b/src/test/java/rocks/inspectit/gepard/agent/internal/instrumentation/InstrumentationStateTest.java @@ -23,6 +23,7 @@ class InstrumentationStateTest { @Test void typeIsNotInstrumented() { InstrumentationState state = InstrumentationState.create(); + boolean isInstrumented = state.isInstrumented(TEST_TYPE); assertFalse(isInstrumented); @@ -30,7 +31,11 @@ void typeIsNotInstrumented() { @Test void typeIsNotInstrumentedWithConfiguration() { + when(configuration.isActive()).thenReturn(false); + InstrumentationState state = InstrumentationState.create(); + state.addInstrumentedType(TEST_TYPE, configuration); + boolean isInstrumented = state.isInstrumented(TEST_TYPE); assertFalse(isInstrumented); @@ -42,6 +47,7 @@ void typeIsInstrumented() { InstrumentationState state = InstrumentationState.create(); state.addInstrumentedType(TEST_TYPE, configuration); + boolean isInstrumented = state.isInstrumented(TEST_TYPE); assertTrue(isInstrumented); @@ -52,6 +58,7 @@ void typeIsDeinstrumented() { InstrumentationState state = InstrumentationState.create(); state.addInstrumentedType(TEST_TYPE, configuration); state.invalidateInstrumentedType(TEST_TYPE); + boolean isInstrumented = state.isInstrumented(TEST_TYPE); assertFalse(isInstrumented);