jenkinstimeoutintegration-testingtestcontainerstestcontainers-junit5

Test Containers work normally locally Windows but not when Jenkins is running the tests


I have some testcontainers running for my junit intergration tests (Spring Boot, Junit 5)

public static PostgreSQLContainer<?> postgresContainer= new PostgreSQLContainer<>("postgres:13")
            .withDatabaseName("test")
            .withUsername("postgres")
            .withPassword("testIntegration")
            .withExposedPorts(5432)
            .withInitScript("test.sql")

And one for another postgrs database and one Generic one for ActiveMQ

    public static GenericContainer<?> aMQContainer= new GenericContainer<>("rmohr/activemq")
            .withExposedPorts(61616)
            .withEnv("DISABLE_SECURITY", "true")
            .withEnv("BROKER_CONFIG_GLOBAL_MAX_SIZE", "50000")
            .withEnv("BROKER_CONFIG_MAX_SIZE_BYTES", "50000")
            .withEnv("BROKER_CONFIG_MAX_DISK_USAGE", "100");
        postgresContainer.start();
        postgresContainer2.start();
        aMQContainer.start();

Locally everything work fine but when I run the tests in Jenkins which is set in a Linux environment (Raspberry Pi 4 4GB Model B) I get the following error:

    Caused by: org.testcontainers.containers.ContainerLaunchException: Container startup failed
    Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
    Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
    Caused by: org.testcontainers.containers.ContainerLaunchException: Timed out waiting for log  output   matching .*database systemt is ready to accept connections

I tried adding waiting conditions, or withStartupTimeoutSeconds(240) but to no avail.

Anyone with a similar problem?


Solution

  • In the end, I came up with this solution and it works stably for me:

    postgreSQLContainer.setWaitStrategy(new LogMessageWaitStrategy()
    .withRegEx(".database system is ready to accept connections.\\s")
    .withTimes(1)
    .withStartupTimeout(Duration.of(60, SECONDS)));