Skip to content

Commit 9a308a2

Browse files
committed
fix more races in pubsub tests
Previously BlockingProcessStreamReader has a terminate() method, used to tell the Reader to stop reading from the emulator process. This causes an inter-process race. If the Reader stops before reading emulator's output, the emulator process will hang as it tries to write to stdout/stderr as there's no one to read from the other side of the pipe. Since there is no way to safely stop the Reader, this commit deletes the method and its associated test. Additionally, the timeout for LocalSystemTest is increased to 3 minutes, since the emulator, somehow, consistently takes just longer than a minute to shut down.
1 parent b85e1cc commit 9a308a2

4 files changed

Lines changed: 6 additions & 21 deletions

File tree

google-cloud-core/src/main/java/com/google/cloud/testing/BaseEmulatorHelper.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,15 +114,15 @@ protected final void startProcess(String blockUntilOutput)
114114
* and stop any possible thread listening for its output.
115115
*/
116116
protected final int waitForProcess(Duration timeout) throws IOException, InterruptedException, TimeoutException {
117-
if (blockingProcessReader != null) {
118-
blockingProcessReader.terminate();
119-
blockingProcessReader = null;
120-
}
121117
if (activeRunner != null) {
122118
int exitCode = activeRunner.waitFor(timeout);
123119
activeRunner = null;
124120
return exitCode;
125121
}
122+
if (blockingProcessReader != null) {
123+
blockingProcessReader.join();
124+
blockingProcessReader = null;
125+
}
126126
return 0;
127127
}
128128

google-cloud-core/src/main/java/com/google/cloud/testing/BlockingProcessStreamReader.java

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,6 @@ private BlockingProcessStreamReader(String emulator, InputStream stream, String
6161
}
6262
}
6363

64-
void terminate() throws IOException {
65-
interrupt();
66-
}
67-
6864
@Override
6965
public void run() {
7066
String previousLine = "";
@@ -79,9 +75,7 @@ public void run() {
7975
processLogLine(previousLine, nextLine);
8076
}
8177
} catch (IOException e) {
82-
if (!isInterrupted()) {
83-
e.printStackTrace(System.err);
84-
}
78+
e.printStackTrace(System.err);
8579
}
8680
processLogLine(previousLine, firstNonNull(nextLine, ""));
8781
writeLog();

google-cloud-core/src/test/java/com/google/cloud/testing/BlockingProcessStreamReaderTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,6 @@ Multimap<Level, String> getLogs() {
7474
}
7575
}
7676

77-
@Test
78-
public void testBlockUntil() throws IOException {
79-
InputStream stream = new ByteArrayInputStream(OUTPUT.getBytes(Charsets.UTF_8));
80-
BlockingProcessStreamReader thread =
81-
BlockingProcessStreamReader.start("emulator", stream, BLOCK_UNTIL, null);
82-
thread.terminate();
83-
stream.close();
84-
}
85-
8677
@Test
8778
public void testForwardLogEntry() throws IOException, InterruptedException {
8879
TestLogger logger = new TestLogger();

google-cloud-pubsub/src/test/java/com/google/cloud/pubsub/LocalSystemTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ public static void startServer() throws IOException, InterruptedException {
5050
public static void stopServer() throws Exception {
5151
pubsub.close();
5252
pubsubHelper.reset();
53-
pubsubHelper.stop(Duration.standardMinutes(1));
53+
pubsubHelper.stop(Duration.standardMinutes(3));
5454
}
5555
}

0 commit comments

Comments
 (0)