Skip to content

Commit 4fd5fb5

Browse files
authored
Stop NodeTests from timing out in certain cases (#49202) (#49503)
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 #44256 Closes #42350 Closes #44435
1 parent 71bcfbf commit 4fd5fb5

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;
@@ -151,7 +150,6 @@ private static Settings.Builder baseSettings() {
151150
}
152151

153152
public void testCloseOnOutstandingTask() throws Exception {
154-
assumeFalse("https://github.com/elastic/elasticsearch/issues/44256", Constants.WINDOWS);
155153
Node node = new MockNode(baseSettings().build(), basePlugins());
156154
node.start();
157155
ThreadPool threadpool = node.injector().getInstance(ThreadPool.class);
@@ -164,7 +162,7 @@ public void testCloseOnOutstandingTask() throws Exception {
164162
threadRunning.await();
165163
node.close();
166164
shouldRun.set(false);
167-
assertTrue(node.awaitClose(1, TimeUnit.DAYS));
165+
assertTrue(node.awaitClose(10L, TimeUnit.SECONDS));
168166
}
169167

170168
public void testCloseRaceWithTaskExecution() throws Exception {
@@ -210,7 +208,7 @@ public void testCloseRaceWithTaskExecution() throws Exception {
210208
closeThread.join();
211209

212210
shouldRun.set(false);
213-
assertTrue(node.awaitClose(1, TimeUnit.DAYS));
211+
assertTrue(node.awaitClose(10L, TimeUnit.SECONDS));
214212
}
215213

216214
public void testAwaitCloseTimeoutsOnNonInterruptibleTask() throws Exception {
@@ -227,7 +225,7 @@ public void testAwaitCloseTimeoutsOnNonInterruptibleTask() throws Exception {
227225
node.close();
228226
assertFalse(node.awaitClose(0, TimeUnit.MILLISECONDS));
229227
shouldRun.set(false);
230-
assertTrue(node.awaitClose(1, TimeUnit.DAYS));
228+
assertTrue(node.awaitClose(10L, TimeUnit.SECONDS));
231229
}
232230

233231
public void testCloseOnInterruptibleTask() throws Exception {
@@ -251,7 +249,7 @@ public void testCloseOnInterruptibleTask() throws Exception {
251249
});
252250
threadRunning.await();
253251
node.close();
254-
// close should not interrput ongoing tasks
252+
// close should not interrupt ongoing tasks
255253
assertFalse(interrupted.get());
256254
// but awaitClose should
257255
node.awaitClose(0, TimeUnit.SECONDS);
@@ -270,7 +268,7 @@ public void testCloseOnLeakedIndexReaderReference() throws Exception {
270268
Searcher searcher = shard.acquireSearcher("test");
271269
node.close();
272270

273-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> node.awaitClose(1, TimeUnit.DAYS));
271+
IllegalStateException e = expectThrows(IllegalStateException.class, () -> node.awaitClose(10L, TimeUnit.SECONDS));
274272
searcher.close();
275273
assertThat(e.getMessage(), containsString("Something is leaking index readers or store references"));
276274
}
@@ -286,7 +284,7 @@ public void testCloseOnLeakedStoreReference() throws Exception {
286284
shard.store().incRef();
287285
node.close();
288286

289-
IllegalStateException e = expectThrows(IllegalStateException.class, () -> node.awaitClose(1, TimeUnit.DAYS));
287+
IllegalStateException e = expectThrows(IllegalStateException.class, () -> node.awaitClose(10L, TimeUnit.SECONDS));
290288
shard.store().decRef();
291289
assertThat(e.getMessage(), containsString("Something is leaking index readers or store references"));
292290
}

0 commit comments

Comments
 (0)