Skip to content

Commit bf29129

Browse files
committed
add test client error
1 parent 5daa37e commit bf29129

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/AbstractHttpClientTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1029,6 +1029,26 @@ void spanEndsAfterHeadersReceived() throws Exception {
10291029
});
10301030
}
10311031

1032+
@Test
1033+
void requestClientError() throws Exception {
1034+
assumeTrue(options.getTestClientError());
1035+
1036+
URI uri = resolveAddress("/client-error");
1037+
String method = "GET";
1038+
int responseCode = doRequest(method, uri);
1039+
1040+
assertThat(responseCode).isEqualTo(400);
1041+
1042+
testing.waitAndAssertTraces(
1043+
trace ->
1044+
trace.hasSpansSatisfyingExactly(
1045+
span ->
1046+
assertClientSpan(span, uri, method, 400, null)
1047+
.hasNoParent()
1048+
.hasStatus(StatusData.error()),
1049+
span -> assertServerSpan(span).hasParent(trace.getSpan(0))));
1050+
}
1051+
10321052
// Visible for spock bridge.
10331053
SpanDataAssert assertClientSpan(
10341054
SpanDataAssert span,

testing-common/src/main/java/io/opentelemetry/instrumentation/testing/junit/http/HttpClientTestOptions.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,8 @@ public boolean isLowLevelInstrumentation() {
8989

9090
public abstract boolean getTestNonStandardHttpMethod();
9191

92+
public abstract boolean getTestClientError();
93+
9294
public abstract Function<URI, String> getHttpProtocolVersion();
9395

9496
@Nullable
@@ -131,6 +133,7 @@ default Builder withDefaults() {
131133
.setTestCallbackWithParent(true)
132134
.setTestErrorWithCallback(true)
133135
.setTestNonStandardHttpMethod(true)
136+
.setTestClientError(false)
134137
.setHttpProtocolVersion(uri -> "1.1");
135138
}
136139

@@ -174,6 +177,8 @@ default Builder withDefaults() {
174177

175178
Builder setTestNonStandardHttpMethod(boolean value);
176179

180+
Builder setTestClientError(boolean value);
181+
177182
Builder setHttpProtocolVersion(Function<URI, String> value);
178183

179184
@CanIgnoreReturnValue

0 commit comments

Comments
 (0)