Use Awaitility when waiting on local port

This commit is contained in:
onobc
2022-03-15 10:11:01 -05:00
committed by Oleg Zhurakousky
parent 0de3a5e7ea
commit da58b0904e
4 changed files with 34 additions and 19 deletions

View File

@@ -41,6 +41,7 @@ import org.springframework.messaging.support.MessageBuilder;
import org.springframework.util.MimeTypeUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.awaitility.Awaitility.await;
import static org.junit.jupiter.api.Assertions.fail;
/**
@@ -306,14 +307,15 @@ public class GrpcInteractionTests {
}
private int patientlyGetPort(ConfigurableApplicationContext context) throws InterruptedException {
Thread.sleep(500);
String port = context.getEnvironment().getProperty("local.grpc.server.port");
if (port == null) {
Thread.sleep(500);
port = context.getEnvironment().getProperty("local.grpc.server.port");
assertThat(port).as("Unable to get 'local.grpc.server.port' - server may not have started up").isNotNull();
}
return Integer.valueOf(port);
await()
.pollDelay(Duration.ofMillis(500))
.pollInterval(Duration.ofMillis(500))
.atMost(Duration.ofSeconds(3))
.untilAsserted(() -> {
String port = context.getEnvironment().getProperty("local.grpc.server.port");
assertThat(port).as("Unable to get 'local.grpc.server.port' - server may not have started up").isNotEmpty();
});
return Integer.valueOf(context.getEnvironment().getProperty("local.grpc.server.port"));
}
@EnableAutoConfiguration