Skip to content

Commit c145c95

Browse files
committed
Stop NodeTests from timing out in certain cases
The NodeTests class contains tests that check behavior when shutting down a node. This involves starting a node, performing some operation, stopping the node, and then awaiting the close of the node. Part of closing a node is the termination of the node's ThreadPool. ThreadPool termination semantics can be deceiving. The ThreadPool#terminate method takes a timeout value and the first oddity is that the terminate method can take two times the timeout value before returning. Internally this method acts on the ExecutorService instances that are held by the ThreadPool. First, an orderly shutdown is attempted and pending tasks are allowed to execute while waiting for the timeout value. If any of the ExecutorService instances have not terminated, a call is made to attempt to stop all active tasks (usually using interrupts) and then waits for up to the timeout value a second time for the termination of the ExecutorService instances. This means that if use a large value when waiting for a node to close, we may not attempt to interrupt any threads that are in a blocking call before the test times out. In order to avoid causing these tests to time out, this change reduces the timeout passed to Node#awaitClose to 10 seconds from 1 day. This will allow blocked threads to be interrupted before the test suite fails due to the timeout. Closes elastic#44256 Closes elastic#42350
1 parent 730faa8 commit c145c95

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

server/src/test/java/org/elasticsearch/node/NodeTests.java

+6-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
*/
1919
package org.elasticsearch.node;
2020

21-
import org.apache.lucene.util.Constants;
2221
import org.apache.lucene.util.LuceneTestCase;
2322
import org.elasticsearch.bootstrap.BootstrapCheck;
2423
import org.elasticsearch.bootstrap.BootstrapContext;
@@ -150,7 +149,6 @@ private static Settings.Builder baseSettings() {
150149
}
151150

152151
public void testCloseOnOutstandingTask() throws Exception {
153-
assumeFalse("https://github.com/elastic/elasticsearch/issues/44256", Constants.WINDOWS);
154152
Node node = new MockNode(baseSettings().build(), basePlugins());
155153
node.start();
156154
ThreadPool threadpool = node.injector().getInstance(ThreadPool.class);
@@ -163,7 +161,7 @@ public void testCloseOnOutstandingTask() throws Exception {
163161
threadRunning.await();
164162
node.close();
165163
shouldRun.set(false);
166-
assertTrue(node.awaitClose(1, TimeUnit.DAYS));
164+
assertTrue(node.awaitClose(10L, TimeUnit.SECONDS));
167165
}
168166

169167
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/42577")
@@ -206,7 +204,7 @@ public void testCloseRaceWithTaskExecution() throws Exception {
206204
closeThread.join();
207205

208206
shouldRun.set(false);
209-
assertTrue(node.awaitClose(1, TimeUnit.DAYS));
207+
assertTrue(node.awaitClose(10L, TimeUnit.SECONDS));
210208
}
211209

212210
public void testAwaitCloseTimeoutsOnNonInterruptibleTask() throws Exception {
@@ -223,7 +221,7 @@ public void testAwaitCloseTimeoutsOnNonInterruptibleTask() throws Exception {
223221
node.close();
224222
assertFalse(node.awaitClose(0, TimeUnit.MILLISECONDS));
225223
shouldRun.set(false);
226-
assertTrue(node.awaitClose(1, TimeUnit.DAYS));
224+
assertTrue(node.awaitClose(10L, TimeUnit.SECONDS));
227225
}
228226

229227
public void testCloseOnInterruptibleTask() throws Exception {
@@ -247,7 +245,7 @@ public void testCloseOnInterruptibleTask() throws Exception {
247245
});
248246
threadRunning.await();
249247
node.close();
250-
// close should not interrput ongoing tasks
248+
// close should not interrupt ongoing tasks
251249
assertFalse(interrupted.get());
252250
// but awaitClose should
253251
node.awaitClose(0, TimeUnit.SECONDS);
@@ -266,7 +264,7 @@ public void testCloseOnLeakedIndexReaderReference() throws Exception {
266264
Searcher searcher = shard.acquireSearcher("test");
267265
node.close();
268266

269-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> node.awaitClose(1, TimeUnit.DAYS));
267+
IllegalStateException e = expectThrows(IllegalStateException.class, () -> node.awaitClose(10L, TimeUnit.SECONDS));
270268
searcher.close();
271269
assertThat(e.getMessage(), Matchers.containsString("Something is leaking index readers or store references"));
272270
}
@@ -282,7 +280,7 @@ public void testCloseOnLeakedStoreReference() throws Exception {
282280
shard.store().incRef();
283281
node.close();
284282

285-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> node.awaitClose(1, TimeUnit.DAYS));
283+
IllegalStateException e = expectThrows(IllegalStateException.class, () -> node.awaitClose(10L, TimeUnit.SECONDS));
286284
shard.store().decRef();
287285
assertThat(e.getMessage(), Matchers.containsString("Something is leaking index readers or store references"));
288286
}

0 commit comments

Comments
 (0)