diff --git a/java/src/org/openqa/selenium/net/UrlChecker.java b/java/src/org/openqa/selenium/net/UrlChecker.java index 44437f2a463c8..e12d9492350c7 100644 --- a/java/src/org/openqa/selenium/net/UrlChecker.java +++ b/java/src/org/openqa/selenium/net/UrlChecker.java @@ -154,7 +154,10 @@ public void waitUntilUnavailable(long timeout, TimeUnit unit, final URL url) "Timed out waiting for %s to become unavailable after %d ms", url, System.currentTimeMillis() - start), e); - } catch (InterruptedException | ExecutionException e) { + } catch (InterruptedException e) { + Thread.currentThread().interrupt(); + throw new RuntimeException(e); + } catch (ExecutionException e) { throw new RuntimeException(e); } } diff --git a/java/test/org/openqa/selenium/net/UrlCheckerTest.java b/java/test/org/openqa/selenium/net/UrlCheckerTest.java index 2d36293df9349..58b74b7983572 100644 --- a/java/test/org/openqa/selenium/net/UrlCheckerTest.java +++ b/java/test/org/openqa/selenium/net/UrlCheckerTest.java @@ -102,4 +102,33 @@ public void cleanup() { safelyCall(() -> server.stop()); safelyCall(executorService::shutdownNow); } + + @Test + void waitUntilUnavailablePreservesInterruptStatus() throws Exception { + Thread caller = Thread.currentThread(); + Thread interrupter = + new Thread( + () -> { + try { + Thread.sleep(500); + } catch (InterruptedException ignored) { + } + caller.interrupt(); + }); + interrupter.start(); + + boolean threw = false; + boolean preserved = false; + try { + urlChecker.waitUntilUnavailable(10, TimeUnit.SECONDS, url); + } catch (RuntimeException expected) { + threw = true; + preserved = Thread.currentThread().isInterrupted(); + Thread.interrupted(); + } + interrupter.join(); + + assertThat(threw).isTrue(); + assertThat(preserved).isTrue(); + } }