Skip to content

Commit

Permalink
Fix OTel agent detector test that was polluting the JVM for later tests
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Quinn <[email protected]>
  • Loading branch information
tjquinno committed Mar 2, 2024
1 parent fd7f3b9 commit 4f58c97
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
16 changes: 10 additions & 6 deletions microprofile/telemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,16 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<forkCount>1</forkCount>
<reuseForks>false</reuseForks>
<!-- The default for the following is 5000 ms. Reducing it significantly speeds up tests. -->
<argLine>-Dotel.bsp.schedule.delay=100</argLine>
</configuration>
<executions>
<execution>
<id>default-test</id>
<configuration>
<!-- The default for the following is 5000 ms. Reducing it significantly speeds up tests. -->
<argLine>-Dotel.bsp.schedule.delay=100</argLine>

</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import io.helidon.tracing.providers.opentelemetry.HelidonOpenTelemetry;

import jakarta.enterprise.inject.spi.CDI;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.Test;

import static org.hamcrest.MatcherAssert.assertThat;
Expand Down Expand Up @@ -54,9 +55,18 @@ void shouldNotBeNoOpTelemetry(){

@Test
void checkEnvVariable(){
System.setProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT, "true");
Config config = CDI.current().select(Config.class).get();
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(true));
var originalAgentPropertyValue = System.setProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT, "true");
try {
Config config = CDI.current().select(Config.class).get();
boolean present = HelidonOpenTelemetry.AgentDetector.isAgentPresent(config);
assertThat(present, is(true));
} finally {
// Restore or clear the agent setting to avoid polluting other tests which might follow.
if (originalAgentPropertyValue != null) {
System.setProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT, originalAgentPropertyValue);
} else {
System.clearProperty(HelidonOpenTelemetry.IO_OPENTELEMETRY_JAVAAGENT);
}
}
}
}

0 comments on commit 4f58c97

Please sign in to comment.