Skip to content

Commit

Permalink
Flaky jar analyzer test (#9704)
Browse files Browse the repository at this point in the history
  • Loading branch information
laurit authored Oct 18, 2023
1 parent 3dbc301 commit e1772ad
Showing 1 changed file with 28 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,28 +14,46 @@
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
import io.opentelemetry.sdk.logs.data.LogRecordData;
import java.util.List;
import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.testcontainers.containers.GenericContainer;

class JarAnalyzerInstallerTest {

@RegisterExtension
static final InstrumentationExtension testing = AgentInstrumentationExtension.create();

@Test
@SuppressWarnings("ReturnValueIgnored")
void jarAnalyzerEnabled() throws InterruptedException {
Thread.sleep(5000);
// We clear exported data before running tests. Here we load a class from testcontainers with
// the assumption that no testcontainers classes have been loaded yet, and we'll have at least
// the testcontainers jar show up in jar analyzer events.
GenericContainer.class.getName();

List<LogRecordData> logRecordData = testing.logRecords();
List<LogRecordData> events =
logRecordData.stream()
.filter(
record -> {
Attributes attributes = record.getAttributes();
return "package".equals(attributes.get(AttributeKey.stringKey("event.domain")))
&& "info".equals(attributes.get(AttributeKey.stringKey("event.name")));
})
.collect(toList());
Awaitility.await()
.until(
() -> {
List<LogRecordData> logRecordData = testing.logRecords();
List<LogRecordData> eventList =
logRecordData.stream()
.filter(
record -> {
Attributes attributes = record.getAttributes();
return "package"
.equals(
attributes.get(AttributeKey.stringKey("event.domain")))
&& "info"
.equals(
attributes.get(AttributeKey.stringKey("event.name")));
})
.collect(toList());
return eventList;
},
(eventList) -> !eventList.isEmpty());

assertThat(events)
.hasSizeGreaterThan(0)
.allSatisfy(
Expand Down

0 comments on commit e1772ad

Please sign in to comment.