Skip to content

Commit

Permalink
Speed up test
Browse files Browse the repository at this point in the history
  • Loading branch information
brunobat committed Jan 16, 2025
1 parent 033874f commit 83665cc
Showing 1 changed file with 27 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,23 +1,5 @@
package io.quarkus.opentelemetry.deployment.traces;

import static io.quarkus.opentelemetry.runtime.tracing.mutiny.MutinyTracingHelper.wrapWithSpan;
import static org.assertj.core.api.Assertions.assertThat;

import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import jakarta.inject.Inject;

import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
Expand All @@ -33,6 +15,23 @@
import io.smallrye.mutiny.helpers.test.UniAssertSubscriber;
import io.vertx.core.Context;
import io.vertx.core.Vertx;
import jakarta.inject.Inject;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.extension.RegisterExtension;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;

import java.time.Duration;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;

import static io.quarkus.opentelemetry.runtime.tracing.mutiny.MutinyTracingHelper.wrapWithSpan;
import static org.assertj.core.api.Assertions.assertThat;

class MutinyTracingHelperTest {

Expand All @@ -42,7 +41,10 @@ class MutinyTracingHelperTest {
() -> ShrinkWrap.create(JavaArchive.class)
.addClasses(TestSpanExporter.class, TestSpanExporterProvider.class)
.addAsResource(new StringAsset(TestSpanExporterProvider.class.getCanonicalName()),
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider"));
"META-INF/services/io.opentelemetry.sdk.autoconfigure.spi.traces.ConfigurableSpanExporterProvider")
.addAsResource(new StringAsset(
"quarkus.otel.bsp.schedule.delay=50ms\n"),
"application.properties"));

@Inject
private TestSpanExporter spanExporter;
Expand All @@ -53,7 +55,7 @@ class MutinyTracingHelperTest {
@Inject
private Vertx vertx;

@AfterEach
@BeforeEach
void tearDown() {
spanExporter.reset();
}
Expand Down Expand Up @@ -128,7 +130,7 @@ void testSpanWithExplicitParent(final String contextType, final String contextNa
@ParameterizedTest(name = "{index}: Nested uni pipeline with implicit parent {1}")
@MethodSource("generateContextRunners")
void testNestedPipeline_implicitParent(final String contextType,
final String contextName) {
final String contextName) {

final String parentSpanName = "parentSpan";
final String childSpanName = "childSpan";
Expand All @@ -148,7 +150,7 @@ void testNestedPipeline_implicitParent(final String contextType,
.subscribe()
.withSubscriber(new UniAssertSubscriber<>());

subscriber.awaitItem();
subscriber.awaitItem(Duration.ofMillis(300));

//ensure there are 2 spans with doSomething and doSomethingAsync as children of testSpan
final List<SpanData> spans = spanExporter.getFinishedSpanItems(2);
Expand Down Expand Up @@ -178,7 +180,7 @@ void testNestedPipeline_explicitNoParent(final String contextType, final String
.subscribe()
.withSubscriber(new UniAssertSubscriber<>());

subscriber.awaitItem();
subscriber.awaitItem(Duration.ofMillis(300));

//ensure there are 2 spans but without parent-child relationship
final List<SpanData> spans = spanExporter.getFinishedSpanItems(2);
Expand Down Expand Up @@ -256,13 +258,13 @@ void testSimpleMultiPipeline_Merge(final String contextType, final String contex
}

private static void assertChildSpan(final List<SpanData> spans, final String parentSpanName,
final String childSpanName1) {
final String childSpanName1) {
assertThat(spans.stream()
.filter(span -> span.getName().equals(childSpanName1))
.findAny()
.orElseThrow()
.getParentSpanId()).isEqualTo(
spans.stream().filter(span -> span.getName().equals(parentSpanName)).findAny().get().getSpanId());
spans.stream().filter(span -> span.getName().equals(parentSpanName)).findAny().get().getSpanId());
}

private static Stream<Arguments> generateContextRunners() {
Expand Down

0 comments on commit 83665cc

Please sign in to comment.