ibzib commented on a change in pull request #16639:
URL: https://github.com/apache/beam/pull/16639#discussion_r794140234
##########
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:
This sleep doesn't determine the length of the test, it's only there so
we don't immediately buffer infinite data and run out of memory.
But the test was waiting 2s, so I parameterized that timeout and reduced it
to 1ms for the test.
--
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]