diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java index 5ee78c6942d..f3e98f919d4 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/yaml/ESClientYamlSuiteTestCase.java @@ -21,7 +21,6 @@ package org.elasticsearch.test.rest.yaml; import com.carrotsearch.randomizedtesting.RandomizedTest; import org.apache.http.HttpHost; -import org.apache.lucene.util.IOUtils; import org.elasticsearch.Version; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; @@ -144,15 +143,6 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { return new ClientYamlTestClient(restSpec, restClient, hosts, esVersion); } - @Override - protected void afterIfFailed(List errors) { - // Dump the stash on failure. Instead of dumping it in true json we escape `\n`s so stack traces are easier to read - logger.info("Stash dump on failure [{}]", - Strings.toString(restTestExecutionContext.stash(), true, true) - .replace("\\n", "\n").replace("\\r", "\r").replace("\\t", "\t")); - super.afterIfFailed(errors); - } - public static Iterable createParameters() throws Exception { String[] paths = resolvePathsProperty(REST_TESTS_SUITE, ""); // default to all tests under the test root List tests = new ArrayList<>(); @@ -318,7 +308,14 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { if (!testCandidate.getSetupSection().isEmpty()) { logger.debug("start setup test [{}]", testCandidate.getTestPath()); for (DoSection doSection : testCandidate.getSetupSection().getDoSections()) { - executeSection(doSection); + try { + executeSection(doSection); + } catch (AssertionError | Exception e) { + logger.info("Stash dump on setup failure [{}]", + Strings.toString(restTestExecutionContext.stash(), true, true) + .replace("\\n", "\n").replace("\\r", "\r").replace("\\t", "\t")); + throw e; + } } logger.debug("end setup test [{}]", testCandidate.getTestPath()); } @@ -327,12 +324,27 @@ public abstract class ESClientYamlSuiteTestCase extends ESRestTestCase { try { for (ExecutableSection executableSection : testCandidate.getTestSection().getExecutableSections()) { - executeSection(executableSection); + try { + executeSection(executableSection); + } catch (AssertionError | Exception e) { + // Dump the stash on failure. Instead of dumping it in true json we escape `\n`s so stack traces are easier to read + logger.info("Stash dump on test failure [{}]", + Strings.toString(restTestExecutionContext.stash(), true, true) + .replace("\\n", "\n").replace("\\r", "\r").replace("\\t", "\t")); + throw e; + } } } finally { logger.debug("start teardown test [{}]", testCandidate.getTestPath()); for (DoSection doSection : testCandidate.getTeardownSection().getDoSections()) { - executeSection(doSection); + try { + executeSection(doSection); + } catch (AssertionError | Exception e) { + logger.info("Stash dump on tear down failure [{}]", + Strings.toString(restTestExecutionContext.stash(), true, true) + .replace("\\n", "\n").replace("\\r", "\r").replace("\\t", "\t")); + // Don't rethrow exception here, that could hide the exception caused by a test. + } } logger.debug("end teardown test [{}]", testCandidate.getTestPath()); }