Skip to content

Commit

Permalink
Fix not waiting for Netty ThreadDeathWatcher in IT (#31758)
Browse files Browse the repository at this point in the history
Same problem and solution as in #30763
Fixes #30547
  • Loading branch information
original-brownbear authored Jul 3, 2018
1 parent e65115a commit ed41d4f
Showing 1 changed file with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
package org.elasticsearch.smoketest;

import io.netty.util.ThreadDeathWatcher;
import io.netty.util.concurrent.GlobalEventExecutor;
import org.elasticsearch.action.admin.cluster.node.info.NodeInfo;
import org.elasticsearch.action.admin.indices.template.get.GetIndexTemplatesResponse;
import org.elasticsearch.common.network.NetworkAddress;
Expand All @@ -19,12 +21,15 @@
import org.elasticsearch.xpack.core.security.SecurityField;
import org.junit.After;
import org.junit.Before;
import org.junit.ClassRule;
import org.junit.rules.ExternalResource;

import java.net.InetSocketAddress;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeUnit;

import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked;
import static org.hamcrest.Matchers.equalTo;
Expand All @@ -42,6 +47,36 @@
* indexed in the cluster.
*/
public class SmokeTestMonitoringWithSecurityIT extends ESIntegTestCase {

/**
* A JUnit class level rule that runs after the AfterClass method in {@link ESIntegTestCase},
* which stops the cluster. After the cluster is stopped, there are a few netty threads that
* can linger, so we wait for them to finish otherwise these lingering threads can intermittently
* trigger the thread leak detector
*/
@ClassRule
public static final ExternalResource STOP_NETTY_RESOURCE = new ExternalResource() {
@Override
protected void after() {
try {
GlobalEventExecutor.INSTANCE.awaitInactivity(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} catch (IllegalStateException e) {
if (e.getMessage().equals("thread was not started") == false) {
throw e;
}
// ignore since the thread was never started
}

try {
ThreadDeathWatcher.awaitInactivity(5, TimeUnit.SECONDS);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
}
};

private static final String USER = "test_user";
private static final String PASS = "x-pack-test-password";
private static final String MONITORING_PATTERN = ".monitoring-*";
Expand Down

0 comments on commit ed41d4f

Please sign in to comment.