11package org .testcontainers .containers .wait .internal ;
22
33import com .google .common .collect .ImmutableSet ;
4- import org .junit .After ;
5- import org .junit .Before ;
64import org .junit .Rule ;
75import org .junit .Test ;
86import org .junit .runner .RunWith ;
97import org .junit .runners .Parameterized ;
8+ import org .rnorth .ducttape .TimeoutException ;
9+ import org .rnorth .ducttape .unreliables .Unreliables ;
1010import org .testcontainers .containers .GenericContainer ;
1111import org .testcontainers .images .builder .ImageFromDockerfile ;
1212
13+ import java .util .concurrent .TimeUnit ;
14+
1315import static java .util .Arrays .asList ;
1416import static org .rnorth .visibleassertions .VisibleAssertions .assertFalse ;
1517import static org .rnorth .visibleassertions .VisibleAssertions .assertTrue ;
@@ -41,6 +43,8 @@ public InternalCommandPortListeningCheckTest(String dockerfile) {
4143 public void singleListening () {
4244 final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck (container , ImmutableSet .of (8080 ));
4345
46+ Unreliables .retryUntilTrue (5 , TimeUnit .SECONDS , check );
47+
4448 final Boolean result = check .call ();
4549
4650 assertTrue ("InternalCommandPortListeningCheck identifies a single listening port" , result );
@@ -50,6 +54,12 @@ public void singleListening() {
5054 public void nonListening () {
5155 final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck (container , ImmutableSet .of (8080 , 1234 ));
5256
57+ try {
58+ Unreliables .retryUntilTrue (5 , TimeUnit .SECONDS , check );
59+ } catch (TimeoutException e ) {
60+ // we expect it to timeout
61+ }
62+
5363 final Boolean result = check .call ();
5464
5565 assertFalse ("InternalCommandPortListeningCheck detects a non-listening port among many" , result );
@@ -59,6 +69,8 @@ public void nonListening() {
5969 public void lowAndHighPortListening () {
6070 final InternalCommandPortListeningCheck check = new InternalCommandPortListeningCheck (container , ImmutableSet .of (100 , 8080 ));
6171
72+ Unreliables .retryUntilTrue (5 , TimeUnit .SECONDS , check );
73+
6274 final Boolean result = check .call ();
6375
6476 assertTrue ("InternalCommandPortListeningCheck identifies a low and a high port" , result );
0 commit comments