Skip to content

Commit

Permalink
improve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
EddeCCC committed Sep 12, 2024
1 parent a1ecc75 commit cef59e7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down Expand Up @@ -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
*/
Expand Down Expand Up @@ -163,22 +164,20 @@ 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(
() -> {
String newLogs = target.getLogs();
int currentConfigUpdateCount = countTimes(newLogs, updateMessage);
return currentConfigUpdateCount > configUpdateCount;
});

// Wait an additional second as puffer
Thread.sleep(1000);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@ class InstrumentationStateTest {
@Test
void typeIsNotInstrumented() {
InstrumentationState state = InstrumentationState.create();

boolean isInstrumented = state.isInstrumented(TEST_TYPE);

assertFalse(isInstrumented);
}

@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);
Expand All @@ -42,6 +47,7 @@ void typeIsInstrumented() {

InstrumentationState state = InstrumentationState.create();
state.addInstrumentedType(TEST_TYPE, configuration);

boolean isInstrumented = state.isInstrumented(TEST_TYPE);

assertTrue(isInstrumented);
Expand All @@ -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);
Expand Down

0 comments on commit cef59e7

Please sign in to comment.