Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix sporadic Elasticsearch test failures #444

Merged
merged 3 commits into from
May 27, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
RestClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class Elasticsearch5RestClientTest extends AgentTestRunner {
static RestClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
RestClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,12 @@ class Elasticsearch6RestClientTest extends AgentTestRunner {
RestClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ class Elasticsearch2NodeClientTest extends AgentTestRunner {
def client = testNode.client()

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
TransportClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
ElasticsearchTemplate template

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class Elasticsearch2NodeClientTest extends AgentTestRunner {
def client = testNode.client()

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,12 @@ class Elasticsearch2TransportClientTest extends AgentTestRunner {
TransportClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ class Elasticsearch2SpringTemplateTest extends AgentTestRunner {
ElasticsearchTemplate template

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class Elasticsearch5NodeClientTest extends AgentTestRunner {
def client = testNode.client()

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class Elasticsearch5TransportClientTest extends AgentTestRunner {
TransportClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,12 @@ class Elasticsearch53NodeClientTest extends AgentTestRunner {
def client = testNode.client()

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ class Elasticsearch53TransportClientTest extends AgentTestRunner {
TransportClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class Elasticsearch53SpringTemplateTest extends AgentTestRunner {
ElasticsearchTemplate template

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,12 @@ class Elasticsearch6NodeClientTest extends AgentTestRunner {
def client = testNode.client()

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ class Elasticsearch6TransportClientTest extends AgentTestRunner {
TransportClient client

def setupSpec() {
withRetryOnBindException({
setupSpecUnderRetry()
})
}

def setupSpecUnderRetry() {
httpPort = PortUtils.randomOpenPort()
tcpPort = PortUtils.randomOpenPort()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import ch.qos.logback.classic.Logger;
import com.google.common.base.Predicate;
import com.google.common.base.Predicates;
import com.google.common.base.Throwables;
import com.google.common.collect.Sets;
import groovy.lang.Closure;
import groovy.lang.DelegatesTo;
Expand All @@ -35,6 +36,7 @@
import io.opentelemetry.trace.Tracer;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.Instrumentation;
import java.net.BindException;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
Expand Down Expand Up @@ -177,6 +179,22 @@ public void cleanUpAfterTests() {
TEST_LISTENER.deactivateTest(this);
}

public static void withRetryOnBindException(final Closure<?> closure) {
withRetryOnBindException(closure, 3);
}

private static void withRetryOnBindException(final Closure<?> closure, final int numRetries) {
try {
closure.call();
} catch (final Throwable t) {
if (numRetries == 0 || !(Throwables.getRootCause(t) instanceof BindException)) {
throw t;
}
log.debug("retrying due to bind exception: {}", t.getMessage(), t);
withRetryOnBindException(closure, numRetries - 1);
}
}

@AfterClass
public static synchronized void agentCleanup() {
if (null != activeTransformer) {
Expand Down