diff --git a/test/framework/src/main/java/org/elasticsearch/transport/nio/ESSelector.java b/test/framework/src/main/java/org/elasticsearch/transport/nio/ESSelector.java index 667107f7b3e..91e308a33b5 100644 --- a/test/framework/src/main/java/org/elasticsearch/transport/nio/ESSelector.java +++ b/test/framework/src/main/java/org/elasticsearch/transport/nio/ESSelector.java @@ -177,8 +177,11 @@ public abstract class ESSelector implements Closeable { try { exitedLoop.await(); } catch (InterruptedException e) { - eventHandler.uncaughtException(e); + Thread.currentThread().interrupt(); + throw new IllegalStateException("Thread was interrupted while waiting for selector to close", e); } + } else if (selector.isOpen()) { + selector.close(); } } } diff --git a/test/framework/src/test/java/org/elasticsearch/transport/nio/ESSelectorTests.java b/test/framework/src/test/java/org/elasticsearch/transport/nio/ESSelectorTests.java index 69c2c00489d..6459447c1a8 100644 --- a/test/framework/src/test/java/org/elasticsearch/transport/nio/ESSelectorTests.java +++ b/test/framework/src/test/java/org/elasticsearch/transport/nio/ESSelectorTests.java @@ -81,6 +81,12 @@ public class ESSelectorTests extends ESTestCase { verify(handler).selectException(ioException); } + public void testSelectorClosedIfOpenAndEventLoopNotRunning() throws IOException { + when(rawSelector.isOpen()).thenReturn(true); + selector.close(); + verify(rawSelector).close(); + } + private static class TestSelector extends ESSelector { TestSelector(EventHandler eventHandler, Selector selector) throws IOException {