From a85024b18e9f5d723262d7ad1477b5ed5c83b3fe Mon Sep 17 00:00:00 2001 From: Bas Passon Date: Mon, 25 Mar 2024 22:25:28 +0100 Subject: [PATCH] Fixes #25682 postgres devservice not working with rancher-desktop on mac arm architecture --- .../deployment/PostgresqlDevServicesProcessor.java | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java index abdd0425a0de49..af09e7e9fc499f 100644 --- a/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java +++ b/extensions/devservices/postgresql/src/main/java/io/quarkus/devservices/postgresql/deployment/PostgresqlDevServicesProcessor.java @@ -12,7 +12,8 @@ import org.jboss.logging.Logger; import org.testcontainers.containers.PostgreSQLContainer; -import org.testcontainers.containers.wait.strategy.LogMessageWaitStrategy; +import org.testcontainers.containers.wait.strategy.Wait; +import org.testcontainers.containers.wait.strategy.WaitAllStrategy; import org.testcontainers.utility.DockerImageName; import io.quarkus.datasource.common.runtime.DataSourceUtil; @@ -99,16 +100,21 @@ public QuarkusPostgreSQLContainer(Optional imageName, OptionalInt fixedE super(DockerImageName .parse(imageName.orElseGet(() -> ConfigureUtil.getDefaultImageNameFor("postgresql"))) .asCompatibleSubstituteFor(DockerImageName.parse(PostgreSQLContainer.IMAGE))); + this.fixedExposedPort = fixedExposedPort; this.useSharedNetwork = useSharedNetwork; + // Workaround for https://github.com/testcontainers/testcontainers-java/issues/4799. // The motivation of this custom wait strategy is that Testcontainers fails to start a Postgresql database when it // has been already initialized. // This custom wait strategy will work fine regardless of the state of the Postgresql database. // More information in the issue ticket in Testcontainers. - this.waitStrategy = new LogMessageWaitStrategy() - .withRegEx("(" + READY_REGEX + ")?(" + SKIPPING_INITIALIZATION_REGEX + ")?") - .withTimes(2) + + // Added Wait.forListeningPort() for https://github.com/quarkusio/quarkus/issues/25682 + // as suggested by https://github.com/testcontainers/testcontainers-java/pull/6309 + this.waitStrategy = new WaitAllStrategy() + .withStrategy(Wait.forLogMessage("(" + READY_REGEX + ")?(" + SKIPPING_INITIALIZATION_REGEX + ")?", 2)) + .withStrategy(Wait.forListeningPort()) .withStartupTimeout(Duration.of(60L, ChronoUnit.SECONDS)); }