Skip to content

Commit a35b534

Browse files
authored
[TEST] call yaml client close method from test suite (#31591)
We added a way to close the yaml test client with #31575. Such close method also needs to be called from the test suite though for the additional clients to be closed.
1 parent 13e1cf6 commit a35b534

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java

+15-8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.common.collect.Tuple;
3232
import org.elasticsearch.common.io.PathUtils;
3333
import org.elasticsearch.common.xcontent.NamedXContentRegistry;
34+
import org.elasticsearch.core.internal.io.IOUtils;
3435
import org.elasticsearch.test.rest.ESRestTestCase;
3536
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestApi;
3637
import org.elasticsearch.test.rest.yaml.restspec.ClientYamlSuiteRestSpec;
@@ -105,6 +106,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
105106
private static List<BlacklistedPathPatternMatcher> blacklistPathMatchers;
106107
private static ClientYamlTestExecutionContext restTestExecutionContext;
107108
private static ClientYamlTestExecutionContext adminExecutionContext;
109+
private static ClientYamlTestClient clientYamlTestClient;
108110

109111
private final ClientYamlTestCandidate testCandidate;
110112

@@ -136,7 +138,7 @@ public void initAndResetContext() throws Exception {
136138
final Version esVersion = versionVersionTuple.v1();
137139
final Version masterVersion = versionVersionTuple.v2();
138140
logger.info("initializing client, minimum es version [{}], master version, [{}], hosts {}", esVersion, masterVersion, hosts);
139-
final ClientYamlTestClient clientYamlTestClient = initClientYamlTestClient(restSpec, client(), hosts, esVersion, masterVersion);
141+
clientYamlTestClient = initClientYamlTestClient(restSpec, client(), hosts, esVersion, masterVersion);
140142
restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType());
141143
adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false);
142144
final String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
@@ -169,6 +171,18 @@ protected ClientYamlTestClient initClientYamlTestClient(
169171
restClientBuilder -> configureClient(restClientBuilder, restClientSettings()));
170172
}
171173

174+
@AfterClass
175+
public static void closeClient() throws IOException {
176+
try {
177+
IOUtils.close(clientYamlTestClient);
178+
} finally {
179+
blacklistPathMatchers = null;
180+
restTestExecutionContext = null;
181+
adminExecutionContext = null;
182+
clientYamlTestClient = null;
183+
}
184+
}
185+
172186
/**
173187
* Create parameters for this parameterized test. Uses the
174188
* {@link ExecutableSection#XCONTENT_REGISTRY list} of executable sections
@@ -266,13 +280,6 @@ private static void validateSpec(ClientYamlSuiteRestSpec restSpec) {
266280
}
267281
}
268282

269-
@AfterClass
270-
public static void clearStatic() {
271-
blacklistPathMatchers = null;
272-
restTestExecutionContext = null;
273-
adminExecutionContext = null;
274-
}
275-
276283
private static Tuple<Version, Version> readVersionsFromCatNodes(RestClient restClient) throws IOException {
277284
// we simply go to the _cat/nodes API and parse all versions in the cluster
278285
Response response = restClient.performRequest("GET", "/_cat/nodes", Collections.singletonMap("h", "version,master"));

0 commit comments

Comments
 (0)