Skip to content

Commit 59cf396

Browse files
zhengwei143copybara-github
authored andcommitted
Fix repository/downloader:DownloaderTestSuite for windows + JDK21.
Fixes #21593. PiperOrigin-RevId: 613965386 Change-Id: I436ad3b865b01380a88190f4a58a2205997c73ab
1 parent 992ef00 commit 59cf396

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

.bazelci/presubmit.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,6 @@ tasks:
356356
- "-//src/test/java/com/google/devtools/build/lib/remote:RemoteTests"
357357
- "-//src/test/shell/bazel/remote/..."
358358
- "-//tools/python:pywrapper_test"
359-
# https://github.com/bazelbuild/bazel/issues/21593
360-
- "-//src/test/java/com/google/devtools/build/lib/bazel/repository/downloader:DownloaderTestSuite"
361359
include_json_profile:
362360
- build
363361
- test

src/test/java/com/google/devtools/build/lib/bazel/repository/downloader/HttpConnectorTest.java

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@
5050
import java.util.List;
5151
import java.util.Locale;
5252
import java.util.Map;
53+
import java.util.Optional;
5354
import java.util.concurrent.Callable;
5455
import java.util.concurrent.ConcurrentHashMap;
5556
import java.util.concurrent.CyclicBarrier;
@@ -361,8 +362,23 @@ public void socketTimeout_throwsIOExceptionInsteadOfSocketTimeoutException() thr
361362
ISO_8859_1)) {
362363
fail("Should have thrown");
363364
} catch (IOException expected) {
364-
assertThat(expected).hasCauseThat().isInstanceOf(SocketTimeoutException.class);
365-
assertThat(expected).hasCauseThat().hasMessageThat().ignoringCase().contains("timed out");
365+
if (expected.getCause() != null) {
366+
// SocketTimeoutException gets wrapped in an IOException and rethrown.
367+
assertThat(expected).hasCauseThat().isInstanceOf(SocketTimeoutException.class);
368+
assertThat(expected).hasCauseThat().hasMessageThat().ignoringCase().contains("timed out");
369+
} else {
370+
// For windows, it is possible that the thrown exception is a ConnectException (no cause)
371+
// from {@code HttpURLConnection.connect()} rather than a SocketTimeoutException from
372+
// {@code HttpURLConnection.getResponseCode()}. In the former case, we expect the
373+
// SocketTimeoutException to have already occurred but gets suppressed within the final
374+
// ConnectException (upon max retry).
375+
ImmutableList<Throwable> suppressed = ImmutableList.copyOf(expected.getSuppressed());
376+
Optional<Throwable> ste =
377+
suppressed.stream().filter(t -> t instanceof SocketTimeoutException).findFirst();
378+
assertThat(ste).isPresent();
379+
assertThat(ste.get()).isInstanceOf(SocketTimeoutException.class);
380+
assertThat(ste.get()).hasMessageThat().ignoringCase().contains("timed out");
381+
}
366382
}
367383
}
368384
}

0 commit comments

Comments
 (0)