测试容器在Windows本地正常工作,但在Jenkins运行测试时无法正常工作

pxq42qpu  于 2022-11-02  发布在  Jenkins
关注(0)|答案(2)|浏览(202)

我为我的junit集成测试运行了一些测试容器(Sping Boot 、Junit 5)

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

一个用于另一个postgrs数据库,另一个用于ActiveMQ的Generic数据库
第一个
本地一切工作正常,但当我在Jenkins中运行测试,这是在Linux环境中设置(树莓派4 4GB模型B)我得到以下错误:

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

我尝试添加等待条件,或使用StartupTimeoutSeconds(240),但没有效果。
有人有类似的问题吗?

v7pvogib

v7pvogib1#

最后,我想出了这个解决方案,它对我来说工作稳定:

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

n1bvdmb62#

问题似乎出在PostgresSqlContainer上,它无法理解映像是否在Docker中运行。将PostgresSqlContainer.withStartupCheckStrategy()更改为new IsRunningStartupCheckStrategy()对我有帮助

相关问题