Skip to content

Commit af41bc7

Browse files
committed
add app cleanup, assert events, rewrite test to use waitAndAssertTraces
1 parent 0490ecd commit af41bc7

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerApplicationTest.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,11 @@
1919
import static io.opentelemetry.semconv.UrlAttributes.URL_SCHEME;
2020
import static org.assertj.core.api.Assertions.assertThat;
2121

22+
import io.opentelemetry.api.common.Attributes;
2223
import io.opentelemetry.api.trace.SpanKind;
2324
import io.opentelemetry.instrumentation.testing.junit.InstrumentationExtension;
2425
import io.opentelemetry.instrumentation.testing.junit.LibraryInstrumentationExtension;
26+
import org.junit.jupiter.api.AfterAll;
2527
import org.junit.jupiter.api.BeforeAll;
2628
import org.junit.jupiter.api.Test;
2729
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -37,6 +39,11 @@ static void setup() throws Exception {
3739
app = new RatpackFunctionalTest(RatpackApp.class);
3840
}
3941

42+
@AfterAll
43+
static void cleanup() {
44+
app.close();
45+
}
46+
4047
@Test
4148
void testAddSpanOnHandlers() {
4249
assertThat(app.getHttpClient().get("foo").getBody().getText()).isEqualTo("hi-foo");
@@ -96,8 +103,18 @@ void testPropagateTraceToHttpCalls() {
96103

97104
@Test
98105
void testIgnoreHandlersBeforeOpenTelemetryServerHandler() {
99-
assertThat(app.getHttpClient().get("ignore").getBody().getText()).isEqualTo("ignored");
100-
assertThat(testing.spans().stream().filter(span -> "GET /ignore".equals(span.getName())))
101-
.isEmpty();
106+
testing.runWithSpan(
107+
"parent",
108+
() ->
109+
assertThat(app.getHttpClient().get("ignore").getBody().getText()).isEqualTo("ignored"));
110+
111+
testing.waitAndAssertTraces(
112+
trace ->
113+
trace.hasSpansSatisfyingExactly(
114+
span ->
115+
span.hasName("parent")
116+
.hasNoParent()
117+
.hasKind(SpanKind.INTERNAL)
118+
.hasAttributes(Attributes.empty())));
102119
}
103120
}

instrumentation/ratpack/ratpack-1.7/library/src/test/java/io/opentelemetry/instrumentation/ratpack/v1_7/server/RatpackServerTest.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ void testPropagateTraceWithInstrumentedAsyncOperations() throws Exception {
127127
span.hasName("a-span")
128128
.hasParent(trace.getSpan(0))
129129
.hasAttributes(Attributes.empty())
130-
.hasTotalRecordedEvents(1)));
130+
.hasEventsSatisfyingExactly(
131+
event -> event.hasName("an-event").hasAttributes(Attributes.empty()))));
131132
}
132133

133134
@Test
@@ -194,7 +195,8 @@ void testPropagateTraceWithInstrumentedAsyncConcurrentOperations() throws Except
194195
span.hasName("a-span")
195196
.hasParent(trace.getSpan(0))
196197
.hasAttributes(Attributes.empty())
197-
.hasTotalRecordedEvents(1)),
198+
.hasEventsSatisfyingExactly(
199+
event -> event.hasName("an-event").hasAttributes(Attributes.empty()))),
198200
trace ->
199201
trace.hasSpansSatisfyingExactly(
200202
span ->
@@ -215,6 +217,7 @@ void testPropagateTraceWithInstrumentedAsyncConcurrentOperations() throws Except
215217
span.hasName("another-span")
216218
.hasParent(trace.getSpan(0))
217219
.hasAttributes(Attributes.empty())
218-
.hasTotalRecordedEvents(1)));
220+
.hasEventsSatisfyingExactly(
221+
event -> event.hasName("an-event").hasAttributes(Attributes.empty()))));
219222
}
220223
}

0 commit comments

Comments
 (0)