Skip to content

Commit

Permalink
Fix OTel agent detector test that was polluting the JVM for later tes…
Browse files Browse the repository at this point in the history
…ts (#8449)

* Fix OTel agent detector test that was polluting the JVM for later tests

Signed-off-by: Tim Quinn <tim.quinn@oracle.com>

* Remove a stray blank line in the pom

* Review comments

---------

Signed-off-by: Tim Quinn <tim.quinn@oracle.com>
  • Loading branch information
tjquinno authored Mar 4, 2024
1 parent 0b16c29 commit 611ba50
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 10 deletions.
21 changes: 15 additions & 6 deletions microprofile/telemetry/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@
Support for MicroProfile Telemetry
</description>

<properties>
<!-- The default for the following is 5000 ms. Reducing it speeds up tests significantly. -->
<otel.bsp.schedule.delay>100</otel.bsp.schedule.delay>
</properties>

<dependencies>
<dependency>
<groupId>io.helidon.tracing.providers</groupId>
Expand Down Expand Up @@ -137,12 +142,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>
<systemPropertyVariables>
<otel.bsp.schedule.delay>${otel.bsp.schedule.delay}</otel.bsp.schedule.delay>
</systemPropertyVariables>
</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 611ba50

Please sign in to comment.