JAMES-2242 Solve Fake SMTP wait strategy Default Host port strategy waits for the FIRST port to be bound. However Fake SMTP port is slowest to be bound. This can lead to tests targetting the not-yet bound port.
Adding additional polling solves the issue. Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/16410ae2 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/16410ae2 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/16410ae2 Branch: refs/heads/master Commit: 16410ae2daa7f9c331fa226f98f29349cb1c7eb5 Parents: 62b00eb Author: benwa <btell...@linagora.com> Authored: Mon Dec 4 18:14:48 2017 +0700 Committer: Antoine Duprat <adup...@linagora.com> Committed: Mon Dec 4 14:42:23 2017 +0100 ---------------------------------------------------------------------- .../org/apache/james/mpt/smtp/ForwardSmtpTest.java | 16 +++++++++++++++- .../james/util/streams/SwarmGenericContainer.java | 13 +++++++++++++ .../GatewayRemoteDeliveryIntegrationTest.java | 2 ++ .../james/transport/mailets/GroupMappingTest.java | 2 ++ .../james/jmap/VacationRelayIntegrationTest.java | 2 ++ 5 files changed, 34 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/16410ae2/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java ---------------------------------------------------------------------- diff --git a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java index 1e87578..954ebd2 100644 --- a/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java +++ b/mpt/impl/smtp/core/src/main/java/org/apache/james/mpt/smtp/ForwardSmtpTest.java @@ -27,6 +27,7 @@ import java.net.InetAddress; import java.util.Locale; import org.apache.james.mpt.script.SimpleScriptedTestProtocol; +import org.apache.james.util.streams.ContainerNames; import org.apache.james.util.streams.SwarmGenericContainer; import org.junit.Before; import org.junit.Rule; @@ -36,6 +37,9 @@ import org.junit.rules.TemporaryFolder; import org.testcontainers.containers.wait.HostPortWaitStrategy; import com.google.common.base.Charsets; +import com.jayway.awaitility.Awaitility; +import com.jayway.awaitility.Duration; +import com.jayway.awaitility.core.ConditionFactory; import com.jayway.restassured.RestAssured; import com.jayway.restassured.builder.RequestSpecBuilder; import com.jayway.restassured.http.ContentType; @@ -48,7 +52,7 @@ public abstract class ForwardSmtpTest { public static final String PASSWORD = "secret"; private final TemporaryFolder folder = new TemporaryFolder(); - private final SwarmGenericContainer fakeSmtp = new SwarmGenericContainer("weave/rest-smtp-sink:latest") + private final SwarmGenericContainer fakeSmtp = new SwarmGenericContainer(ContainerNames.FAKE_SMTP) .withExposedPorts(25) .withAffinityToContainer() .waitingFor(new HostPortWaitStrategy()); @@ -82,6 +86,16 @@ public abstract class ForwardSmtpTest { .setPort(80) .setBaseUri("http://" + containerIp.getHostAddress()) .build(); + + Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; + ConditionFactory calmlyAwait = Awaitility.with() + .pollInterval(slowPacedPollInterval) + .and() + .with() + .pollDelay(slowPacedPollInterval) + .await(); + + calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> fakeSmtp.tryConnect(25)); } @Test http://git-wip-us.apache.org/repos/asf/james-project/blob/16410ae2/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java ---------------------------------------------------------------------- diff --git a/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java b/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java index 8b50aa2..fbecff2 100644 --- a/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java +++ b/server/container/util-java8/src/test/java/org/apache/james/util/streams/SwarmGenericContainer.java @@ -19,9 +19,12 @@ package org.apache.james.util.streams; +import java.net.Socket; import java.time.Duration; import java.util.List; +import javax.net.SocketFactory; + import org.junit.Assume; import org.junit.rules.TestRule; import org.junit.runner.Description; @@ -131,6 +134,16 @@ public class SwarmGenericContainer implements TestRule { return container.getContainerInfo(); } + public boolean tryConnect(int port) { + try { + Socket socket = SocketFactory.getDefault().createSocket(getContainerIp(), port); + socket.close(); + return true; + } catch (Exception e) { + return false; + } + } + @Override public Statement apply(Statement statement, Description description) { return container.apply(statement, description); http://git-wip-us.apache.org/repos/asf/james-project/blob/16410ae2/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java index 9094ab6..374d7bf 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/mailets/GatewayRemoteDeliveryIntegrationTest.java @@ -123,6 +123,8 @@ public class GatewayRemoteDeliveryIntegrationTest { .pollDelay(slowPacedPollInterval) .await(); + calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> fakeSmtp.tryConnect(25)); + RestAssured.requestSpecification = new RequestSpecBuilder() .setContentType(ContentType.JSON) .setAccept(ContentType.JSON) http://git-wip-us.apache.org/repos/asf/james-project/blob/16410ae2/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java ---------------------------------------------------------------------- diff --git a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java index c9f36f9..4ec65fb 100644 --- a/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java +++ b/server/mailet/integration-testing/src/test/java/org/apache/james/transport/mailets/GroupMappingTest.java @@ -174,6 +174,8 @@ public class GroupMappingTest { Duration slowPacedPollInterval = Duration.FIVE_HUNDRED_MILLISECONDS; calmlyAwait = Awaitility.with().pollInterval(slowPacedPollInterval).and().with().pollDelay(slowPacedPollInterval).await(); + calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> fakeSmtp.tryConnect(25)); + dataProbe = jamesServer.getProbe(DataProbeImpl.class); dataProbe.addDomain(DOMAIN1); dataProbe.addDomain(DOMAIN2); http://git-wip-us.apache.org/repos/asf/james-project/blob/16410ae2/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java ---------------------------------------------------------------------- diff --git a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java index f0b9108..1887c45 100644 --- a/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java +++ b/server/protocols/jmap-integration-testing/jmap-integration-testing-common/src/test/java/org/apache/james/jmap/VacationRelayIntegrationTest.java @@ -116,6 +116,8 @@ public abstract class VacationRelayIntegrationTest { .pollInterval(slowPacedPollInterval) .and() .pollDelay(slowPacedPollInterval).await(); + + calmlyAwait.atMost(Duration.ONE_MINUTE).until(() -> fakeSmtp.tryConnect(25)); } @After --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org