diff --git a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java index 24c0fbf9faab..7c60da50b0b0 100644 --- a/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java +++ b/gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java @@ -524,7 +524,7 @@ private static void extractFile(ZipInputStream zipIn, File filePath) throws IOEx } } - public static String sendQuitRequest(int port) { + public static boolean sendQuitRequest(int port) { StringBuilder result = new StringBuilder(); try { URL url = new URL("http", "localhost", port, "/_ah/admin/quit"); @@ -543,7 +543,7 @@ public static String sendQuitRequest(int port) { } catch (IOException ignore) { // ignore } - return result.toString(); + return result.toString().startsWith("Shutting down local server"); } public void stop() throws IOException, InterruptedException { diff --git a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelperTest.java b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelperTest.java index bfc3ffdaccfe..40ea62c5a7e0 100644 --- a/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelperTest.java +++ b/gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelperTest.java @@ -50,9 +50,16 @@ public void testFindAvailablePort() { @Test public void testSendQuitRequest() throws IOException, InterruptedException { LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT); - assertTrue(LocalGcdHelper.sendQuitRequest(PORT).startsWith("Shutting down local server")); + assertTrue(LocalGcdHelper.sendQuitRequest(PORT)); + long timeoutMillis = 30000; + long startTime = System.currentTimeMillis(); + boolean datastoreActive = LocalGcdHelper.isActive(PROJECT_ID, PORT); + while (datastoreActive && System.currentTimeMillis() - startTime < timeoutMillis) { + datastoreActive = LocalGcdHelper.isActive(PROJECT_ID, PORT); + } + assertFalse(datastoreActive); + assertFalse(LocalGcdHelper.sendQuitRequest(PORT)); gcdHelper.stop(); - assertTrue(LocalGcdHelper.sendQuitRequest(PORT).isEmpty()); // shouldn't error } @Test