Verify that server span ends after child spans in java tests (#8208)
Currently server span end time verification is only implemented for groovy tests.
This commit is contained in:
parent
702b9ae70f
commit
4d21d45f3d
|
@ -134,5 +134,8 @@ class KtorHttpServerTest : AbstractHttpServerTest<ApplicationEngine>() {
|
||||||
else -> expectedHttpRoute(it)
|
else -> expectedHttpRoute(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// ktor does not have a controller lifecycle so the server span ends immediately when the
|
||||||
|
// response is sent, which is before the controller span finishes.
|
||||||
|
options.setVerifyServerSpanEndTime(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -134,5 +134,9 @@ class KtorHttpServerTest : AbstractHttpServerTest<ApplicationEngine>() {
|
||||||
else -> expectedHttpRoute(it)
|
else -> expectedHttpRoute(it)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ktor does not have a controller lifecycle so the server span ends immediately when the
|
||||||
|
// response is sent, which is before the controller span finishes.
|
||||||
|
options.setVerifyServerSpanEndTime(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,6 +48,7 @@ import java.util.concurrent.CountDownLatch;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
|
import org.assertj.core.api.AssertAccess;
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.junit.jupiter.api.AfterAll;
|
import org.junit.jupiter.api.AfterAll;
|
||||||
import org.junit.jupiter.api.BeforeAll;
|
import org.junit.jupiter.api.BeforeAll;
|
||||||
|
@ -466,6 +467,17 @@ public abstract class AbstractHttpServerTest<SERVER> extends AbstractHttpServerU
|
||||||
}
|
}
|
||||||
|
|
||||||
trace.hasSpansSatisfyingExactly(spanAssertions);
|
trace.hasSpansSatisfyingExactly(spanAssertions);
|
||||||
|
|
||||||
|
if (options.verifyServerSpanEndTime) {
|
||||||
|
List<SpanData> spanData = AssertAccess.getActual(trace);
|
||||||
|
if (spanData.size() > 1) {
|
||||||
|
SpanData rootSpan = spanData.get(0);
|
||||||
|
for (int j = 1; j < spanData.size(); j++) {
|
||||||
|
assertThat(rootSpan.getEndEpochNanos())
|
||||||
|
.isGreaterThanOrEqualTo(spanData.get(j).getEndEpochNanos());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -51,6 +51,7 @@ public final class HttpServerTestOptions {
|
||||||
boolean testPathParam = false;
|
boolean testPathParam = false;
|
||||||
boolean testCaptureHttpHeaders = true;
|
boolean testCaptureHttpHeaders = true;
|
||||||
boolean testCaptureRequestParameters = false;
|
boolean testCaptureRequestParameters = false;
|
||||||
|
boolean verifyServerSpanEndTime = true;
|
||||||
|
|
||||||
HttpServerTestOptions() {}
|
HttpServerTestOptions() {}
|
||||||
|
|
||||||
|
@ -174,6 +175,12 @@ public final class HttpServerTestOptions {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@CanIgnoreReturnValue
|
||||||
|
public HttpServerTestOptions setVerifyServerSpanEndTime(boolean verifyServerSpanEndTime) {
|
||||||
|
this.verifyServerSpanEndTime = verifyServerSpanEndTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface SpanNameMapper {
|
public interface SpanNameMapper {
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
/*
|
||||||
|
* Copyright The OpenTelemetry Authors
|
||||||
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.assertj.core.api;
|
||||||
|
|
||||||
|
public final class AssertAccess {
|
||||||
|
private AssertAccess() {}
|
||||||
|
|
||||||
|
public static <ACTUAL> ACTUAL getActual(AbstractAssert<?, ACTUAL> abstractAssert) {
|
||||||
|
return abstractAssert.actual;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue