Skip to content

Commit b80183e

Browse files
authored
fix:test failure testAppendWhileShutdownSuccess (#904)
* fix:test failure testAppendWhileShutdownSuccess, a race special to test execution * fix one more test * fix another test
1 parent 2e49ce8 commit b80183e

File tree

1 file changed

+24
-12
lines changed
  • google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2

1 file changed

+24
-12
lines changed

google-cloud-bigquerystorage/src/test/java/com/google/cloud/bigquery/storage/v1beta2/StreamWriterTest.java

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -471,19 +471,23 @@ public void testBatchIsFlushedWithError() throws Exception {
471471
.build());
472472

473473
ApiFuture<AppendRowsResponse> appendFuture1 = sendTestMessage(writer, new String[] {"A"});
474-
ApiFuture<AppendRowsResponse> appendFuture2 = sendTestMessage(writer, new String[] {"B"});
475-
ApiFuture<AppendRowsResponse> appendFuture3 = sendTestMessage(writer, new String[] {"C"});
476474
try {
477-
appendFuture2.get();
478-
} catch (ExecutionException ex) {
479-
assertEquals(DataLossException.class, ex.getCause().getClass());
480-
}
481-
assertFalse(appendFuture3.isDone());
482-
writer.shutdown();
483-
try {
484-
appendFuture3.get();
485-
} catch (ExecutionException ex) {
486-
assertEquals(AbortedException.class, ex.getCause().getClass());
475+
ApiFuture<AppendRowsResponse> appendFuture2 = sendTestMessage(writer, new String[] {"B"});
476+
ApiFuture<AppendRowsResponse> appendFuture3 = sendTestMessage(writer, new String[] {"C"});
477+
try {
478+
appendFuture2.get();
479+
} catch (ExecutionException ex) {
480+
assertEquals(DataLossException.class, ex.getCause().getClass());
481+
}
482+
assertFalse(appendFuture3.isDone());
483+
writer.shutdown();
484+
try {
485+
appendFuture3.get();
486+
} catch (ExecutionException ex) {
487+
assertEquals(AbortedException.class, ex.getCause().getClass());
488+
}
489+
} catch (IllegalStateException ex) {
490+
assertEquals("Stream already failed.", ex.getMessage());
487491
}
488492
}
489493
}
@@ -739,6 +743,14 @@ public Throwable call() {
739743
}
740744
}
741745
return null;
746+
} catch (ExecutionException ex) {
747+
// Some wiredness in test presubmit runs, it seems this thread is always started after
748+
// the main thread.
749+
if (ex.getCause().getClass() == AbortedException.class) {
750+
return null;
751+
} else {
752+
return ex;
753+
}
742754
} catch (Exception e) {
743755
return e;
744756
}

0 commit comments

Comments
 (0)