Skip to content

Commit

Permalink
Add timeout to testSendQuitRequest and boolean return value to sendQu…
Browse files Browse the repository at this point in the history
…itRequest
  • Loading branch information
Ajay Kannan committed Oct 23, 2015
1 parent 9b3e689 commit 494511c
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 494511c

Please sign in to comment.