0

How can I tell docker-maven-plugin to wait for the RabbitMQ container to fully start up before running integration tests?

This is the plugin configuration I am using in the pom.xml:

<plugin>
    <groupId>io.fabric8</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <executions>
        <execution>
            <id>start-rabbitmq-container</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</goal>
            </goals>
            <configuration>
                <images>
                    <image>
                        <alias>rabbitmq</alias>
                        <name>rabbitmq:3.6.10-management</name>
                        <run>
                            <log>
                                <prefix>RABBITMQ</prefix>
                                <color>cyan</color>
                            </log>
                            <namingStrategy>alias</namingStrategy>
                            <ports>
                                <port>5672:5672</port>
                                <port>15672:15672</port>
                            </ports>
                        </run>
                    </image>
                </images>
            </configuration>
        </execution>
        <execution>
            <id>stop-rabbitmq-container</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>stop</goal>
            </goals>
        </execution>
    </executions>
</plugin>

At the moment the ITs start executing while RabbitMQ it's still initialising and failing as the server is not available.

Eduardo Sanchez-Ros
  • 1,777
  • 2
  • 18
  • 30

2 Answers2

1

"While starting a container is it possible to block the execution until some condition is met"

https://dmp.fabric8.io/#start-wait

You can wait for some log output from RabbitMQ container with log:

Regular expression which is applied against the log output of an container and blocks until the pattern is matched. You can use (?s) in the pattern to switch on multi line matching.

abinet
  • 2,552
  • 1
  • 15
  • 24
  • Thanks @abinet. According to the docs I can `wait` for a specified amount of `time` and block the execution. In the case of the RabbitMQ container, is there a more deterministic way to do that? – Eduardo Sanchez-Ros Aug 04 '17 at 12:41
  • Still no luck at this, I don't think looking at the log to determine if RabbitMQ has started is a good idea. – Eduardo Sanchez-Ros Aug 05 '17 at 16:01
1

I managed to find a more assertive way of checking for the status of RabbitMQ. As I am using the rabbitmq:3.6.10-management docker image, I can check that the management url on localhost:15672 is up:

<wait>
    <http>
        <url>http://localhost:15672</url>
        <method>GET</method>
        <status>200..399</status>
    </http>
    <time>10000</time>
</wait>

The wait configuration will check the return value of getting the management url, for a maximum of 10 seconds until it's within the specified HTTP response status range, but RabbitMQ normally starts up within 2 to 3 seconds.

Eduardo Sanchez-Ros
  • 1,777
  • 2
  • 18
  • 30