Skip to content

Commit

Permalink
Fix repository/downloader:DownloaderTestSuite for windows + JDK21.
Browse files Browse the repository at this point in the history
Fixes bazelbuild#21593.

PiperOrigin-RevId: 613965386
Change-Id: I436ad3b865b01380a88190f4a58a2205997c73ab
  • Loading branch information
zhengwei143 authored and copybara-github committed Mar 8, 2024
1 parent 992ef00 commit 59cf396
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 0 additions & 2 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -356,8 +356,6 @@ tasks:
- "-//src/test/java/com/google/devtools/build/lib/remote:RemoteTests"
- "-//src/test/shell/bazel/remote/..."
- "-//tools/python:pywrapper_test"
# https://github.com/bazelbuild/bazel/issues/21593
- "-//src/test/java/com/google/devtools/build/lib/bazel/repository/downloader:DownloaderTestSuite"
include_json_profile:
- build
- test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CyclicBarrier;
Expand Down Expand Up @@ -361,8 +362,23 @@ public void socketTimeout_throwsIOExceptionInsteadOfSocketTimeoutException() thr
ISO_8859_1)) {
fail("Should have thrown");
} catch (IOException expected) {
assertThat(expected).hasCauseThat().isInstanceOf(SocketTimeoutException.class);
assertThat(expected).hasCauseThat().hasMessageThat().ignoringCase().contains("timed out");
if (expected.getCause() != null) {
// SocketTimeoutException gets wrapped in an IOException and rethrown.
assertThat(expected).hasCauseThat().isInstanceOf(SocketTimeoutException.class);
assertThat(expected).hasCauseThat().hasMessageThat().ignoringCase().contains("timed out");
} else {
// For windows, it is possible that the thrown exception is a ConnectException (no cause)
// from {@code HttpURLConnection.connect()} rather than a SocketTimeoutException from
// {@code HttpURLConnection.getResponseCode()}. In the former case, we expect the
// SocketTimeoutException to have already occurred but gets suppressed within the final
// ConnectException (upon max retry).
ImmutableList<Throwable> suppressed = ImmutableList.copyOf(expected.getSuppressed());
Optional<Throwable> ste =
suppressed.stream().filter(t -> t instanceof SocketTimeoutException).findFirst();
assertThat(ste).isPresent();
assertThat(ste.get()).isInstanceOf(SocketTimeoutException.class);
assertThat(ste.get()).hasMessageThat().ignoringCase().contains("timed out");
}
}
}
}
Expand Down

0 comments on commit 59cf396

Please sign in to comment.