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

Write http server tests in java #5501

Merged
merged 6 commits into from
Mar 8, 2022

Conversation

laurit
Copy link
Contributor

@laurit laurit commented Mar 4, 2022

Add an option to write http server tests in java as junit tests and convert grails3 test to java. Being able to write tests in java will hopefully allow us to upgrade to groovy 4 (currently grails tests don't run with groovy 4) which hopefully will let us run some tests on jdk17.

@laurit laurit requested a review from a team as a code owner March 4, 2022 13:47
});
}

testing.waitAndAssertTraces(assertions);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This behaves a bit strangely. When an assertion fails it will take 10s until awaitility times out.

Copy link
Member

@trask trask left a comment

Choose a reason for hiding this comment

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

🥳 !!

I think you read @anuraaga's mind, he was just talking about this yesterday 😁

laurit and others added 2 commits March 5, 2022 14:34
Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
Copy link
Contributor

@anuraaga anuraaga left a comment

Choose a reason for hiding this comment

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

Yay!

return span;
}

private static void assertException(
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you use SpanDataAssert.hasException?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I didn't use SpanDataAssert.hasException because it requires an instance of Throwable but here we only have exception class and error message. As actually we use only a few exception classes and all of them have a suitable constructor I could try constructing the exception instance reflectively.

Copy link
Member

Choose a reason for hiding this comment

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

we use only a few exception classes and all of them have a suitable constructor I could try constructing the exception instance reflectively

I think this approach makes the test harder to read, @anuraaga what do you think about something like SpanDataAssert.hasExceptionSatisying for the most flexibility here?

@laurit I'm ok merging with any approach here and we can revisit

Copy link
Contributor

Choose a reason for hiding this comment

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

I think that could be useful, but in this case, can't the places passing an exception class and String error message pass a Throwable instead by calling new Class(message)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think it should be done in a separate pr as this pr is already fairly large.

String contextPath = "";
Class<? extends Throwable> expectedExceptionClass = Exception.class;

Function<ServerEndpoint, Boolean> hasHandlerSpan = unused -> false;
Copy link
Member

Choose a reason for hiding this comment

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

Why not use Predicate for this?

@trask trask merged commit b349638 into open-telemetry:main Mar 8, 2022
RashmiRam pushed a commit to RashmiRam/opentelemetry-auto-instr-java that referenced this pull request May 23, 2022
* Write http server tests in java

* typo

* Apply suggestions from code review

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>

* add comments

* address review comments

* use Predicate

Co-authored-by: Trask Stalnaker <trask.stalnaker@gmail.com>
@laurit laurit deleted the http-server-test-in-java branch July 6, 2023 17:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants