Skip to content

Commit 0d75646

Browse files
Fix not waiting for Netty ThreadDeathWatcher in IT (#31758) (#31789)
Same problem and solution as in #30763 Fixes #30547
1 parent d646fc4 commit 0d75646

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

x-pack/qa/smoke-test-plugins-ssl/src/test/java/org/elasticsearch/smoketest/SmokeTestMonitoringWithSecurityIT.java

+35
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
package org.elasticsearch.smoketest;
77

8+
import io.netty.util.ThreadDeathWatcher;
9+
import io.netty.util.concurrent.GlobalEventExecutor;
810
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
911
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
1012
import org.elasticsearch.common.network.NetworkAddress;
@@ -19,12 +21,15 @@
1921
import org.elasticsearch.xpack.core.security.SecurityField;
2022
import org.junit.After;
2123
import org.junit.Before;
24+
import org.junit.ClassRule;
25+
import org.junit.rules.ExternalResource;
2226

2327
import java.net.InetSocketAddress;
2428
import java.util.Collection;
2529
import java.util.Collections;
2630
import java.util.List;
2731
import java.util.Optional;
32+
import java.util.concurrent.TimeUnit;
2833

2934
import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
3035
import static org.hamcrest.Matchers.equalTo;
@@ -42,6 +47,36 @@
4247
* indexed in the cluster.
4348
*/
4449
public class SmokeTestMonitoringWithSecurityIT extends ESIntegTestCase {
50+
51+
/**
52+
* A JUnit class level rule that runs after the AfterClass method in {@link ESIntegTestCase},
53+
* which stops the cluster. After the cluster is stopped, there are a few netty threads that
54+
* can linger, so we wait for them to finish otherwise these lingering threads can intermittently
55+
* trigger the thread leak detector
56+
*/
57+
@ClassRule
58+
public static final ExternalResource STOP_NETTY_RESOURCE = new ExternalResource() {
59+
@Override
60+
protected void after() {
61+
try {
62+
GlobalEventExecutor.INSTANCE.awaitInactivity(5, TimeUnit.SECONDS);
63+
} catch (InterruptedException e) {
64+
Thread.currentThread().interrupt();
65+
} catch (IllegalStateException e) {
66+
if (e.getMessage().equals("thread was not started") == false) {
67+
throw e;
68+
}
69+
// ignore since the thread was never started
70+
}
71+
72+
try {
73+
ThreadDeathWatcher.awaitInactivity(5, TimeUnit.SECONDS);
74+
} catch (InterruptedException e) {
75+
Thread.currentThread().interrupt();
76+
}
77+
}
78+
};
79+
4580
private static final String USER = "test_user";
4681
private static final String PASS = "x-pack-test-password";
4782
private static final String MONITORING_PATTERN = ".monitoring-*";

0 commit comments

Comments
 (0)