Skip to content

Commit 5b85062

Browse files
committed
[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 e6d3249 commit 5b85062

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;
@@ -104,6 +105,7 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase {
104105
private static List<BlacklistedPathPatternMatcher> blacklistPathMatchers;
105106
private static ClientYamlTestExecutionContext restTestExecutionContext;
106107
private static ClientYamlTestExecutionContext adminExecutionContext;
108+
private static ClientYamlTestClient clientYamlTestClient;
107109

108110
private final ClientYamlTestCandidate testCandidate;
109111

@@ -142,7 +144,7 @@ public void initAndResetContext() throws Exception {
142144
throw ex;
143145
}
144146
}
145-
ClientYamlTestClient clientYamlTestClient = initClientYamlTestClient(restSpec, restClient, hosts, esVersion);
147+
clientYamlTestClient = initClientYamlTestClient(restSpec, restClient, hosts, esVersion);
146148
restTestExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, randomizeContentType());
147149
adminExecutionContext = new ClientYamlTestExecutionContext(clientYamlTestClient, false);
148150
String[] blacklist = resolvePathsProperty(REST_TESTS_BLACKLIST, null);
@@ -174,6 +176,18 @@ protected ClientYamlTestClient initClientYamlTestClient(
174176
restClientBuilder -> configureClient(restClientBuilder, restClientSettings()));
175177
}
176178

179+
@AfterClass
180+
public static void closeClient() throws IOException {
181+
try {
182+
IOUtils.close(clientYamlTestClient);
183+
} finally {
184+
blacklistPathMatchers = null;
185+
restTestExecutionContext = null;
186+
adminExecutionContext = null;
187+
clientYamlTestClient = null;
188+
}
189+
}
190+
177191
/**
178192
* Create parameters for this parameterized test. Uses the
179193
* {@link ExecutableSection#XCONTENT_REGISTRY list} of executable sections
@@ -271,13 +285,6 @@ private static void validateSpec(ClientYamlSuiteRestSpec restSpec) {
271285
}
272286
}
273287

274-
@AfterClass
275-
public static void clearStatic() {
276-
blacklistPathMatchers = null;
277-
restTestExecutionContext = null;
278-
adminExecutionContext = null;
279-
}
280-
281288
private static Tuple<Version, Version> readVersionsFromCatNodes(RestClient restClient) throws IOException {
282289
// we simply go to the _cat/nodes API and parse all versions in the cluster
283290
Response response = restClient.performRequest("GET", "/_cat/nodes", Collections.singletonMap("h", "version,master"));

0 commit comments

Comments
 (0)