Skip to content

Commit 494511c

Browse files
author
Ajay Kannan
committed
Add timeout to testSendQuitRequest and boolean return value to sendQuitRequest
1 parent 9b3e689 commit 494511c

2 files changed

Lines changed: 11 additions & 4 deletions

File tree

gcloud-java-datastore/src/main/java/com/google/gcloud/datastore/testing/LocalGcdHelper.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -524,7 +524,7 @@ private static void extractFile(ZipInputStream zipIn, File filePath) throws IOEx
524524
}
525525
}
526526

527-
public static String sendQuitRequest(int port) {
527+
public static boolean sendQuitRequest(int port) {
528528
StringBuilder result = new StringBuilder();
529529
try {
530530
URL url = new URL("http", "localhost", port, "/_ah/admin/quit");
@@ -543,7 +543,7 @@ public static String sendQuitRequest(int port) {
543543
} catch (IOException ignore) {
544544
// ignore
545545
}
546-
return result.toString();
546+
return result.toString().startsWith("Shutting down local server");
547547
}
548548

549549
public void stop() throws IOException, InterruptedException {

gcloud-java-datastore/src/test/java/com/google/gcloud/datastore/LocalGcdHelperTest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,16 @@ public void testFindAvailablePort() {
5050
@Test
5151
public void testSendQuitRequest() throws IOException, InterruptedException {
5252
LocalGcdHelper gcdHelper = LocalGcdHelper.start(PROJECT_ID, PORT);
53-
assertTrue(LocalGcdHelper.sendQuitRequest(PORT).startsWith("Shutting down local server"));
53+
assertTrue(LocalGcdHelper.sendQuitRequest(PORT));
54+
long timeoutMillis = 30000;
55+
long startTime = System.currentTimeMillis();
56+
boolean datastoreActive = LocalGcdHelper.isActive(PROJECT_ID, PORT);
57+
while (datastoreActive && System.currentTimeMillis() - startTime < timeoutMillis) {
58+
datastoreActive = LocalGcdHelper.isActive(PROJECT_ID, PORT);
59+
}
60+
assertFalse(datastoreActive);
61+
assertFalse(LocalGcdHelper.sendQuitRequest(PORT));
5462
gcdHelper.stop();
55-
assertTrue(LocalGcdHelper.sendQuitRequest(PORT).isEmpty()); // shouldn't error
5663
}
5764

5865
@Test

0 commit comments

Comments
 (0)