Skip to content

Commit

Permalink
Wait a few seconds for InternalCommandPortListeningCheck to pass
Browse files Browse the repository at this point in the history
  • Loading branch information
codablock committed Feb 19, 2020
1 parent bdb6715 commit 6be1289
Showing 1 changed file with 14 additions and 2 deletions.
@@ -1,15 +1,17 @@
package org.testcontainers.containers.wait.internal;

import com.google.common.collect.ImmutableSet;
import org.junit.After;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.rnorth.ducttape.TimeoutException;
import org.rnorth.ducttape.unreliables.Unreliables;
import org.testcontainers.containers.GenericContainer;
import org.testcontainers.images.builder.ImageFromDockerfile;

import java.util.concurrent.TimeUnit;

import static java.util.Arrays.asList;
import static org.rnorth.visibleassertions.VisibleAssertions.assertFalse;
import static org.rnorth.visibleassertions.VisibleAssertions.assertTrue;
Expand Down Expand Up @@ -41,6 +43,8 @@ public InternalCommandPortListeningCheckTest(String dockerfile) {
public void singleListening() {
final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck(container, ImmutableSet.of(8080));

Unreliables.retryUntilTrue(5, TimeUnit.SECONDS, check);

final Boolean result = check.call();

assertTrue("InternalCommandPortListeningCheck identifies a single listening port", result);
Expand All @@ -50,6 +54,12 @@ public void singleListening() {
public void nonListening() {
final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck(container, ImmutableSet.of(8080, 1234));

try {
Unreliables.retryUntilTrue(5, TimeUnit.SECONDS, check);
} catch (TimeoutException e) {
// we expect it to timeout
}

final Boolean result = check.call();

assertFalse("InternalCommandPortListeningCheck detects a non-listening port among many", result);
Expand All @@ -59,6 +69,8 @@ public void nonListening() {
public void lowAndHighPortListening() {
final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck(container, ImmutableSet.of(100, 8080));

Unreliables.retryUntilTrue(5, TimeUnit.SECONDS, check);

final Boolean result = check.call();

assertTrue("InternalCommandPortListeningCheck identifies a low and a high port", result);
Expand Down

0 comments on commit 6be1289

Please sign in to comment.