kennknowles commented on a change in pull request #16639:
URL: https://github.com/apache/beam/pull/16639#discussion_r794115806



##########
File path: 
runners/google-cloud-dataflow-java/src/test/java/org/apache/beam/runners/dataflow/options/DataflowPipelineOptionsTest.java
##########
@@ -236,12 +242,80 @@ public void testDefaultGcpRegionFromEnvironment() {
     }
 
     @Test
-    public void testDefaultGcpRegionFromGcloud() throws IOException, 
InterruptedException {
+    public void testDefaultGcpRegionFromGcloud()
+        throws IOException, InterruptedException, TimeoutException {
       mockStatic(DefaultGcpRegionFactory.class);
       
when(DefaultGcpRegionFactory.getRegionFromEnvironment()).thenReturn(null);
       
when(DefaultGcpRegionFactory.getRegionFromGcloudCli()).thenReturn("us-west1");
       DataflowPipelineOptions options = 
PipelineOptionsFactory.as(DataflowPipelineOptions.class);
       assertEquals("us-west1", options.getRegion());
     }
+
+    /**
+     * If gcloud gets stuck, test that {@link 
DefaultGcpRegionFactory#getRegionFromGcloudCli()}
+     * times out instead of blocking forever.
+     */
+    @Test(timeout = 10000L)
+    public void testGetRegionFromGcloudCliTimeout()
+        throws IOException, InterruptedException, TimeoutException {
+      mockStatic(DefaultGcpRegionFactory.class, Answers.CALLS_REAL_METHODS);
+      when(DefaultGcpRegionFactory.startGcloud())
+          .thenReturn(
+              new Process() {
+                @Override
+                public OutputStream getOutputStream() {
+                  return new OutputStream() {
+                    @Override
+                    public void write(int b) throws IOException {
+                      // Do nothing.
+                    }
+                  };
+                }
+
+                @Override
+                public InputStream getInputStream() {
+                  return new InputStream() {
+                    @Override
+                    public int read() throws IOException {
+                      // Return EOF immediately.
+                      return -1;
+                    }
+                  };
+                }
+
+                @Override
+                public InputStream getErrorStream() {
+                  return new InputStream() {
+                    @Override
+                    public int read() throws IOException {
+                      // Never return EOF to create an infinite loop.
+                      try {
+                        Thread.sleep(1000);

Review comment:
       Can we parameterize this to avoid adding a big wait to a test? I know it 
is just a second in a long suite, but it makes me sad.




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to