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

Document limitation of @QuarkusIntegrationTest using Docker image #25010

Closed
snazy opened this issue Apr 19, 2022 · 4 comments · Fixed by #25242
Closed

Document limitation of @QuarkusIntegrationTest using Docker image #25010

snazy opened this issue Apr 19, 2022 · 4 comments · Fixed by #25242
Labels
area/testing kind/bug Something isn't working
Milestone

Comments

@snazy
Copy link
Contributor

snazy commented Apr 19, 2022

Describe the bug

@QuarkusIntegrationTest runs against "any" "image type" (fast-jar, uber-jar, native image, Docker container), which is really neat.

@QuarkusIntegrationTest against Docker containers, when the tested application runs inside a Docker container, has an important limitation compared to the now deprecated-for-removal @NativeImageTest option, which is probably worth documenting.

Since the tested application runs inside a Docker container, the tested application cannot access resources running on the Docker host. Integration tests that for example use testcontainers need to be updated to use the proper Docker-network hostname.

OidcWiremockTestResource does not work with @QuarkusIntegrationTest against Docker containers, because the Wiremock server is running in the JVM running the test, which cannot be accessed from the Docker container running the Quarkus application.

Unfortunately there's no system property which can be easily checked for the currently tested Quarkus image type (fast/uber jar, native, docker). Seems worth to have such a property - or better: a way to only limit/restrict tests, likely with a new @DisabledOnNativeDockerImage annotation similar to @DisabledOnNativeImage and @DisabledOnIntegrationTest? Or add a set of "disabled image types" to @DisabledOnIntegrationTest?

Testcontainers JdbcDatabaseContainer example:
Old way was to simply use JdbcDatabaseContainer.getJdbcUrl(), but now it requires:

public class MyTestResourceLifecycleManager implements QuarkusTestResourceLifecycleManager, DevServicesContext.ContextAware {
  private Optional<String> containerNetworkId;

  @Override
  public void setIntegrationTestContext(DevServicesContext context) {
    containerNetworkId = context.containerNetworkId();
  }

  @Override
  public Map<String, String> start() {
    JdbcDatabaseContainer container = new PostgreSQLContainer ...
    
    String jdbcUrl = container.getJdbcUrl();

    // Replace hostname + port in the provided JDBC URL with the hostname of the Docker container
    // running PostgreSQL and the listening port.
    if (containerNetworkId.isPresent()) {
      String hostPort = container.getHost() + ':' + container.getMappedPort(POSTGRESQL_PORT);
      String networkHostPort =
          container.getCurrentContainerInfo().getConfig().getHostName() + ':' + POSTGRESQL_PORT;
      jdbcUrl = jdbcUrl.replace(hostPort, networkHostPort);
    }

    return ImmutableMap.of(
        "quarkus.datasource.username", container.getUsername(),
        "quarkus.datasource.password", container.getPassword(),
        "quarkus.datasource.jdbc.url", jdbcUrl);
  }
}
`` 

### Quarkus version or git rev

2.8.0
@snazy snazy added the kind/bug Something isn't working label Apr 19, 2022
@quarkus-bot
Copy link

quarkus-bot bot commented Apr 19, 2022

/cc @geoand

@geoand
Copy link
Contributor

geoand commented Apr 19, 2022

Thanks for reporting!

Would you like to contribute the documentation improvement?

@snazy
Copy link
Contributor Author

snazy commented Apr 19, 2022

Would you like to contribute the documentation improvement?

Can take a stab on it.

@geoand
Copy link
Contributor

geoand commented Apr 20, 2022

Or add a set of "disabled image types" to @DisabledOnIntegrationTest?

This is an interesting idea! I'll have a look.

geoand added a commit to geoand/quarkus that referenced this issue Apr 20, 2022
geoand added a commit to geoand/quarkus that referenced this issue Apr 20, 2022
geoand added a commit to geoand/quarkus that referenced this issue Apr 21, 2022
geoand added a commit that referenced this issue Apr 21, 2022
Introduce a way to disable integration tests for certain build types
snazy added a commit to snazy/quarkus that referenced this issue Apr 29, 2022
* Enhance text + example for `@QuarkusIntegrationTest` in `getting-started-testing.adoc`
* Add a note to `security-openid-connect.adoc`

Fixes quarkusio#25010
snazy added a commit to snazy/quarkus that referenced this issue May 4, 2022
* Enhance text + example for `@QuarkusIntegrationTest` in `getting-started-testing.adoc`
* Add a note to `security-openid-connect.adoc`

Fixes quarkusio#25010
@quarkus-bot quarkus-bot bot added this to the 2.10 - main milestone May 9, 2022
@gsmet gsmet modified the milestones: 2.10 - main, 2.9.1.Final May 12, 2022
gsmet pushed a commit to gsmet/quarkus that referenced this issue May 12, 2022
* Enhance text + example for `@QuarkusIntegrationTest` in `getting-started-testing.adoc`
* Add a note to `security-openid-connect.adoc`

Fixes quarkusio#25010

(cherry picked from commit 3ccc084)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/testing kind/bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants