From 5dea4c5a035c13a0bfaa8ecc91a0072c91303c98 Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Thu, 17 Nov 2016 20:41:25 +0000 Subject: [PATCH] Wait for server port to be written in a more robust manner Previously, we just waited for the file to exist before trying to read the port from it. This left a window where the file existed but its contents had not be written which could result in a NumberFormatException. This commit now waits for the file to have a length that is greater than zero. See gh-7379 --- .../boot/devtools/tests/DevToolsIntegrationTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java b/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java index e970b0aade..8c6ef0e9ed 100644 --- a/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java +++ b/spring-boot-integration-tests/spring-boot-devtools-tests/src/test/java/org/springframework/boot/devtools/tests/DevToolsIntegrationTests.java @@ -139,7 +139,7 @@ public class DevToolsIntegrationTests { private int awaitServerPort() throws Exception { long end = System.currentTimeMillis() + 20000; - while (!this.serverPortFile.exists()) { + while (this.serverPortFile.length() == 0) { if (System.currentTimeMillis() > end) { throw new IllegalStateException( "server.port file was not written within 20 seconds");