Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat add testerror #12924

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1029,6 +1029,34 @@ void spanEndsAfterHeadersReceived() throws Exception {
});
}

@Test
void requestClientError() throws Exception {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is essentially a copy of errorSpan test, perhaps it would make sense to parameterize that test instead

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assumeTrue(options.getTestClientError());

URI uri = resolveAddress("/client-error");
String method = "GET";

testing.runWithSpan(
"parent",
() -> {
try {
doRequest(method, uri);
} catch (Throwable ignored) {
// ignored
}
});

testing.waitAndAssertTraces(
trace ->
trace.hasSpansSatisfyingExactly(
span -> span.hasName("parent").hasKind(SpanKind.INTERNAL).hasNoParent(),
span ->
assertClientSpan(span, uri, method, 400, null)
.hasParent(trace.getSpan(0))
.hasStatus(StatusData.error()),
span -> assertServerSpan(span).hasParent(trace.getSpan(1))));
}

// Visible for spock bridge.
SpanDataAssert assertClientSpan(
SpanDataAssert span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ public boolean isLowLevelInstrumentation() {

public abstract boolean getTestNonStandardHttpMethod();

public abstract boolean getTestClientError();

public abstract Function<URI, String> getHttpProtocolVersion();

@Nullable
Expand Down Expand Up @@ -131,6 +133,7 @@ default Builder withDefaults() {
.setTestCallbackWithParent(true)
.setTestErrorWithCallback(true)
.setTestNonStandardHttpMethod(true)
.setTestClientError(true)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if a test is always enabled then there is no need to add an option to disable it

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

.setHttpProtocolVersion(uri -> "1.1");
}

Expand Down Expand Up @@ -174,6 +177,8 @@ default Builder withDefaults() {

Builder setTestNonStandardHttpMethod(boolean value);

Builder setTestClientError(boolean value);

Builder setHttpProtocolVersion(Function<URI, String> value);

@CanIgnoreReturnValue
Expand Down
Loading