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 HTTP Server TCK #8499
Conversation
Adds a new module `http-server-tck` This module contains multiple tests for a Micronaut HTTP Server. Those tests were ported from the AWS Module. It has an API `ServerUnderTest` and `ServerUnderTestProvider` which allows registering a module, implementing the TCK easily via a service loader. It contains a test module `test-suite-http-server-tck-netty` which runs the TCK against `micronaut-http-server-netty`.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the whole test harness seems a bit convoluted. couldnt these be normal junit tests that access the server implementation using a rule or something?
Delete Test in this commit are moved to the TCK micronaut-projects/micronaut-core#8499
Not sure what you are proposing. Please, create a PR with this one as the base with your proposal See linked PRs, specially in azure and lambda to see |
i dont mean the ServerUnderTest necessarily, i just want the tests to not be default methods in interfaces. e.g. by configuring junit to run the tests from the main tck module in the netty module. @melix what do you think, is there a better way to achieve this? |
Why can't we have ordinary Spock tests as we have before? It should have been enough to copy existing Netty tests, and different implementations would provide a server implementation. |
I feel like you created some testing framework when it's not needed at all. |
It should be possible to have tests exposed as a transitive dependency. By default Gradle will only add the tests from |
@melix getting the right server implementation injected is already solved using ServiceLoader in this PR. i think that approach is fine. |
Right so it should only be a matter of:
I think we already do something like this in |
There are a few ways:
|
extending each test is not workable here, since we will have tck implementations in different repositories. it's too easy to miss a test. |
The requisite is that we need to publish a library with tests. And use that library in different repositories (servlet, azure, azure). I think it is safer to publish a standard java library with interfaces and consume it s proposed in this PR than complicating the build. To run the TCK means just creating a class which implements an interface and a Moreover, if you are not compliant with a test you can Disable the test see above example. Honestly, I think it is a good solution it makes trivial to implement it in other modules. See linked PRs. About creating a testing framework. The test is in this PR are based on the tests that were in the AWS Module. I had to rewrite them so that they are HTTP server framework agnostic. I wrote helper classes (TestScenario, HTTPResponseAssertion) to remove a lot of duplication and to handle things such as bean pollution. We had a lot of duplication and tests difficult to read and these classes allow you to write HTTP Server tests as:
But using |
The AWS PR is a good example of consuming the library: https://github.com/micronaut-projects/micronaut-aws/pull/1538/files# Right now, it has |
i think it is better to have to do small modifications to the build in dependent modules, if it means we can use normal testing patterns: classes instead of interfaces, automatic discovery instead of registering each test class, maybe even spock, and maybe even being able to click the green arrow in intellij to run a test... i see that in the aws pr, you disabled an individual test, which is indeed more convenient with your approach. however you could also do this with a normal exclusion rule. imo you should work with @melix to find a good approach to keep the build as clean as possible but still allow normal testing patterns. (the techempower approach seems hacky, i dont know) |
If you want to run a single test in your tck. You create a class and |
I like Spock. However, I think it is easier to maintain and to publish a library based on JUnit than in Spock. |
I agree with @yawkat that we should publish a test suite. It shouldn't really be complicated to do it, and it can use Spock too. Consuming shouldn't be complicated either. Especially if the consumers are only Micronaut projects. |
Would like to point out that there is one other advantage of using JUnit/Java in that we can run these TCK tests with native image. |
I have changed the PR to use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks!
import org.junit.jupiter.api.Test; | ||
import java.io.IOException; | ||
|
||
@SuppressWarnings({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we can turn of sonar/checkstyle for these modules? we don't use them for spock tests either, they're just gonna be a pita...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
http-server-tck/src/main/java/io/micronaut/http/server/tck/tests/BodyTest.java
Outdated
Show resolved
Hide resolved
"java:S5960", // We're allowed assertions, as these are used in tests only | ||
}) | ||
@Experimental | ||
public final class AssertionUtils { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This module should be internal
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, other modules may want to use it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, but not outside of Micronaut org
import org.junit.jupiter.api.Test; | ||
import java.io.IOException; | ||
|
||
@SuppressWarnings({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree
http-server-tck/src/main/java/io/micronaut/http/server/tck/tests/FilterErrorTest.java
Outdated
Show resolved
Hide resolved
http-server-tck/src/main/java/io/micronaut/http/server/tck/tests/FiltersTest.java
Outdated
Show resolved
Hide resolved
"checkstyle:MissingJavadocType", | ||
"checkstyle:DesignForExtension" | ||
}) | ||
public class MiscTest { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would separate tests into packages named after it's test scenarios: .filters, .reactive, .form etc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree we could improve how the TCK is structured. We can do this after this his been merged. The tests were ported from AWS, where there was no clear structure.
http-server-tck/src/main/java/io/micronaut/http/server/tck/tests/MiscTest.java
Outdated
Show resolved
Hide resolved
test-suite-http-server-tck-netty/src/test/resources/logback.xml
Outdated
Show resolved
Hide resolved
SonarCloud Quality Gate failed. |
Adds a new module
http-server-tck
This module contains multiple tests for a Micronaut HTTP Server. Those tests were ported from the AWS Module.
It has an API
ServerUnderTest
andServerUnderTestProvider
which allows registering a module, implementing the TCK easily via a service loader.It contains a test module
test-suite-http-server-tck-netty
which runs the TCK againstmicronaut-http-server-netty
.