From c19d84012e850349820811cf3aed451b325ff8fa Mon Sep 17 00:00:00 2001 From: Martijn van Groningen Date: Mon, 12 Feb 2018 11:59:12 +0100 Subject: [PATCH] iter --- .../rest/yaml/ESClientYamlSuiteTestCase.java | 42 ++++++------------- 1 file changed, 13 insertions(+), 29 deletions(-) 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 f3e98f919d4d5..927f9b46c966a 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 @@ -308,14 +308,7 @@ public void test() throws IOException { if (!testCandidate.getSetupSection().isEmpty()) { logger.debug("start setup test [{}]", testCandidate.getTestPath()); for (DoSection doSection : testCandidate.getSetupSection().getDoSections()) { - 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; - } + executeSection(doSection); } logger.debug("end setup test [{}]", testCandidate.getTestPath()); } @@ -324,27 +317,12 @@ public void test() throws IOException { try { for (ExecutableSection executableSection : testCandidate.getTestSection().getExecutableSections()) { - 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; - } + executeSection(executableSection); } } finally { logger.debug("start teardown test [{}]", testCandidate.getTestPath()); for (DoSection doSection : testCandidate.getTeardownSection().getDoSections()) { - 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. - } + executeSection(doSection); } logger.debug("end teardown test [{}]", testCandidate.getTestPath()); } @@ -356,10 +334,16 @@ public void test() throws IOException { private void executeSection(ExecutableSection executableSection) { try { executableSection.execute(restTestExecutionContext); - } catch (Exception e) { - throw new RuntimeException(errorMessage(executableSection, e), e); - } catch (AssertionError e) { - throw new AssertionError(errorMessage(executableSection, e), e); + } 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")); + if (e instanceof AssertionError) { + throw new AssertionError(errorMessage(executableSection, e), e); + } else { + throw new RuntimeException(errorMessage(executableSection, e), e); + } } }