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



我有一些测试容器正在为我的junit集成测试(Spring 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数据库

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();

在本地,一切都很好,但当我在Jenkins中运行测试时,它是在Linux环境中设置的(Raspberry Pi 4 4GB Model 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(,但没有成功。

有人有类似的问题吗?

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

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

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

最新更新