Skip to content

Commit dee4cbe

Browse files
authored
Use Awaitility in FixedHostPortContainerTest (#9341)
1 parent 35cf6d3 commit dee4cbe

File tree

1 file changed

+8
-13
lines changed

1 file changed

+8
-13
lines changed

core/src/test/java/org/testcontainers/junit/FixedHostPortContainerTest.java

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
package org.testcontainers.junit;
22

3-
import com.google.common.util.concurrent.Uninterruptibles;
3+
import org.awaitility.Awaitility;
44
import org.junit.Test;
5-
import org.rnorth.ducttape.unreliables.Unreliables;
65
import org.testcontainers.TestImages;
76
import org.testcontainers.containers.FixedHostPortGenericContainer;
87
import org.testcontainers.containers.GenericContainer;
@@ -11,7 +10,7 @@
1110
import java.io.IOException;
1211
import java.io.InputStreamReader;
1312
import java.net.Socket;
14-
import java.util.concurrent.TimeUnit;
13+
import java.time.Duration;
1514

1615
import static org.assertj.core.api.Assertions.assertThat;
1716

@@ -71,7 +70,7 @@ public void testFixedHostPortMapping() throws IOException {
7170
.as("Port mapping does not seem to match given fixed port")
7271
.isEqualTo(unusedHostPort);
7372

74-
final String content = this.readResponse(echoServer, unusedHostPort);
73+
final String content = readResponse(echoServer, unusedHostPort);
7574
assertThat(content).as("Returned echo from fixed port does not match expected").isEqualTo(TEST_RESPONSE);
7675
}
7776
}
@@ -86,15 +85,11 @@ public void testFixedHostPortMapping() throws IOException {
8685
*/
8786
private String readResponse(GenericContainer container, Integer port) throws IOException {
8887
try (
89-
final BufferedReader reader = Unreliables.retryUntilSuccess(
90-
10,
91-
TimeUnit.SECONDS,
92-
() -> {
93-
Uninterruptibles.sleepUninterruptibly(1, TimeUnit.SECONDS);
94-
final Socket socket = new Socket(container.getHost(), port);
95-
return new BufferedReader(new InputStreamReader(socket.getInputStream()));
96-
}
97-
)
88+
Socket socket = Awaitility
89+
.await()
90+
.pollDelay(Duration.ofSeconds(1))
91+
.until(() -> new Socket(container.getHost(), port), Socket::isConnected);
92+
BufferedReader reader = new BufferedReader(new InputStreamReader(socket.getInputStream()))
9893
) {
9994
return reader.readLine();
10095
}

0 commit comments

Comments
 (0)