'Testcontainers RabbitMq with SSL/TLS fails to wait for a container to start

I have a test using RabbitMq in Testcontainers. The test is working using HTTP

@Container private static final RabbitMQContainer RABBITMQ_CONTAINER =
          new RabbitMQContainer()
                  .withLogConsumer(new Slf4jLogConsumer(LOG))
                  .withStartupTimeout(Duration.of(5, ChronoUnit.MINUTES))
                  .waitingFor(Wait.forHttp("/api/vhosts")
                          .forPort(15672)
                          .withBasicCredentials("guest", "guest"));

and fails when I switch to HTTPS

@Container private static final RabbitMQContainer RABBITMQ_CONTAINER =
          new RabbitMQContainer()
                  .withLogConsumer(new Slf4jLogConsumer(LOG))
                  .withStartupTimeout(Duration.of(5, ChronoUnit.MINUTES))
                  .waitingFor(Wait.forHttp("/api/vhosts")
                          .usingTls()
                          .forPort(15671)
                          .withBasicCredentials("guest", "guest"))
                  .withSSL(forClasspathResource("/certs/server_key.pem", 0644),
                          forClasspathResource("/certs/server_certificate.pem", 0644),
                          forClasspathResource("/certs/ca_certificate.pem", 0644),
                          VERIFY_NONE,
                          false);

In logs I see that container can not start:

...
18:53:21.274 [main] INFO  - /brave_swirles: Waiting for 60 seconds for URL: https://localhost:50062/api/vhosts (where port 50062 maps to container port 15671)
...
18:54:21.302 [main] ERROR - Could not start container
org.testcontainers.containers.ContainerLaunchException: Timed out waiting for URL to be accessible (https://localhost:50062/api/vhosts should return HTTP 200)

What do I miss? I'd want at least Testcontainers' waiting strategy works.



Solution 1:[1]

Using RabbitMQContainer with custom SSL certificates makes it hard to also use HttpWaitStrategy. In this case, you probably need to configure the whole JVM to trust those SSL certificates.

Alternatively, just continue to use the default wait strategy (which will be a LogMessageWaitStrategy).

For further examples, just look at the RabbitMQContainer tests in Testcontainers itself: https://github.com/testcontainers/testcontainers-java/blob/c3f53b3a63e6b0bc800a7f0fbce91ce95a8986b3/modules/rabbitmq/src/test/java/org/testcontainers/containers/RabbitMQContainerTest.java#L237-L264

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kevin Wittek