diff options
author | jonmv <venstad@gmail.com> | 2024-01-11 09:45:01 +0100 |
---|---|---|
committer | jonmv <venstad@gmail.com> | 2024-01-11 09:45:01 +0100 |
commit | df94fea49a0dc848cc2c7d86772ef4a2a83386ee (patch) | |
tree | 23e310d6d02a765e5be26a828092380e7a7a15e9 | |
parent | 1b5f77ef226384be2fc3ac775b56d4bfecb5ff3c (diff) |
Update tenant test runner JUnit version as well
6 files changed, 51 insertions, 42 deletions
diff --git a/dependency-versions/pom.xml b/dependency-versions/pom.xml index 60989a579a2..d9eed69c7ea 100644 --- a/dependency-versions/pom.xml +++ b/dependency-versions/pom.xml @@ -146,8 +146,8 @@ <!-- Versions used by tenant parent pom and testing framework --> <!-- CAUTION: upgrading junit for tenants poms may break testing frameworks --> - <junit.vespa.tenant.version>5.8.1</junit.vespa.tenant.version> - <junit.platform.vespa.tenant.version>1.8.1</junit.platform.vespa.tenant.version> + <junit.vespa.tenant.version>5.10.1</junit.vespa.tenant.version> + <junit.platform.vespa.tenant.version>1.10.1</junit.platform.vespa.tenant.version> <surefire.vespa.tenant.version>${surefire.vespa.version}</surefire.vespa.tenant.version> <!-- Maven plugins --> diff --git a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java index f90f910ee7e..b585739b950 100644 --- a/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java +++ b/vespa-osgi-testrunner/src/main/java/com/yahoo/vespa/testrunner/TestReport.java @@ -4,6 +4,7 @@ package com.yahoo.vespa.testrunner; import ai.vespa.hosted.cd.InconclusiveTestException; import com.yahoo.collections.Comparables; import com.yahoo.vespa.testrunner.TestRunner.Suite; +import org.junit.platform.commons.util.ReflectionUtils; import org.junit.platform.engine.UniqueId; import org.junit.platform.engine.UniqueId.Segment; import org.junit.platform.launcher.TestIdentifier; @@ -30,6 +31,8 @@ import static java.util.Arrays.copyOf; */ public class TestReport { + private static final List<String> testFrameworkRootClasses = List.of(ReflectionUtils.class.getName(), JunitRunner.class.getName()); + private final Object monitor = new Object(); private final Set<TestIdentifier> complete = new HashSet<>(); private final Clock clock; @@ -138,7 +141,7 @@ public class TestReport { void log(LogRecord record) { synchronized (monitor) { - if (record.getThrown() != null) trimStackTraces(record.getThrown(), JunitRunner.class.getName()); + if (record.getThrown() != null) trimStackTraces(record.getThrown()); if ( ! (current.children.peekLast() instanceof OutputNode)) current.children.add(new OutputNode(current)); @@ -277,9 +280,9 @@ public class TestReport { private final Throwable thrown; private final Suite suite; - public FailureNode(NamedNode parent, Instant now, Throwable thrown, Suite suite) { + FailureNode(NamedNode parent, Instant now, Throwable thrown, Suite suite) { super(parent, null, thrown.toString(), now); - trimStackTraces(thrown, JunitRunner.class.getName()); + trimStackTraces(thrown); this.thrown = thrown; this.suite = suite; @@ -330,7 +333,7 @@ public class TestReport { * This is based on the assumption that the relevant stack is anything above the first native * reflection invocation, above any frame in the given root class. */ - static void trimStackTraces(Throwable thrown, String testFrameworkRootClass) { + static void trimStackTraces(Throwable thrown) { if (thrown == null) return; @@ -340,8 +343,8 @@ public class TestReport { int cutoff = 0; boolean rootedInTestFramework = false; while (++i < stack.length) { - rootedInTestFramework |= testFrameworkRootClass.equals(stack[i].getClassName()); - if (firstReflectFrame == -1 && stack[i].getClassName().startsWith("jdk.internal.reflect.")) + rootedInTestFramework |= testFrameworkRootClasses.contains(stack[i].getClassName()); + if (firstReflectFrame == -1 && (stack[i].getClassName().startsWith("jdk.internal.reflect.") || stack[i].getClassName().startsWith("java.lang.reflect."))) firstReflectFrame = i; // jdk.internal.reflect class invokes the first user test frame, on both jdk 17 and 21. if (rootedInTestFramework && firstReflectFrame > 0) { cutoff = firstReflectFrame; @@ -353,12 +356,18 @@ public class TestReport { break; } } + if (cutoff == 0) { + while (--i >= 0 && ( stack[i].isNativeMethod() + || stack[i].getClassName().startsWith("java.lang.") + || stack[i].getClassName().startsWith("java.util."))); + cutoff = i + 1; + } thrown.setStackTrace(copyOf(stack, cutoff)); for (Throwable suppressed : thrown.getSuppressed()) - trimStackTraces(suppressed, testFrameworkRootClass); + trimStackTraces(suppressed); - trimStackTraces(thrown.getCause(), testFrameworkRootClass); + trimStackTraces(thrown.getCause()); } private static String toString(Suite suite) { diff --git a/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/AggregateTestRunnerTest.java b/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/AggregateTestRunnerTest.java index c54fb6abf37..9933e25b277 100644 --- a/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/AggregateTestRunnerTest.java +++ b/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/AggregateTestRunnerTest.java @@ -163,7 +163,7 @@ class AggregateTestRunnerTest { } } catch (Exception e) { - TestReport.trimStackTraces(e, "org.junit.platform.commons.util.ReflectionUtils"); + TestReport.trimStackTraces(e); assertEquals(""" java.lang.RuntimeException: java.lang.RuntimeException: inner \tat com.yahoo.vespa.testrunner.AggregateTestRunnerTest.testStackTrimming(AggregateTestRunnerTest.java:162) diff --git a/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/JunitRunnerTest.java b/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/JunitRunnerTest.java index bffcc75f160..fcf4403e3ab 100644 --- a/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/JunitRunnerTest.java +++ b/vespa-osgi-testrunner/src/test/java/com/yahoo/vespa/testrunner/JunitRunnerTest.java @@ -135,7 +135,7 @@ class JunitRunnerTest { } private TestIdentifier getTestIdentifier(TestDescriptor testDescriptor) { - return plan.getTestIdentifier(testDescriptor.getUniqueId().toString()); + return plan.getTestIdentifier(testDescriptor.getUniqueId()); } @Override public void dynamicTestRegistered(TestDescriptor testDescriptor) { diff --git a/vespa-osgi-testrunner/src/test/resources/output.json b/vespa-osgi-testrunner/src/test/resources/output.json index 79e9c544149..37c4ef094f9 100644 --- a/vespa-osgi-testrunner/src/test/resources/output.json +++ b/vespa-osgi-testrunner/src/test/resources/output.json @@ -1,136 +1,136 @@ { "logRecords": [ { - "id": 18, + "id": 2, "at": 0, "type": "info", "message": "spam" }, { - "id": 21, + "id": 5, "at": 0, "type": "info", "message": "spam" }, { - "id": 22, + "id": 6, "at": 0, "type": "error", "message": "java.lang.NoClassDefFoundError\n\tat com.yahoo.vespa.test.samples.SampleTest.error(SampleTest.java:88)\n" }, { - "id": 25, + "id": 9, "at": 0, "type": "info", "message": "spam" }, { - "id": 26, + "id": 10, "at": 0, "type": "info", "message": "I have a bad feeling about this" }, { - "id": 27, + "id": 11, "at": 0, "type": "error", - "message": "org.opentest4j.AssertionFailedError: baz ==> expected: <foo> but was: <bar>\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)\n\tat org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)\n\tat org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)\n\tat org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1152)\n\tat com.yahoo.vespa.test.samples.SampleTest.failing(SampleTest.java:82)\n" + "message": "org.opentest4j.AssertionFailedError: baz ==> expected: <foo> but was: <bar>\n\tat org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)\n\tat org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)\n\tat org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)\n\tat org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)\n\tat org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1156)\n\tat com.yahoo.vespa.test.samples.SampleTest.failing(SampleTest.java:82)\n" }, { - "id": 31, + "id": 15, "at": 0, "type": "info", "message": "spam" }, { - "id": 32, + "id": 16, "at": 0, "type": "info", "message": "I'm here with Erwin today; Erwin, what can you tell us about your cat?" }, { - "id": 33, + "id": 17, "at": 0, "type": "warning", "message": "ai.vespa.hosted.cd.InconclusiveTestException: the cat is both dead _and_ alive\n\tat com.yahoo.vespa.test.samples.SampleTest.inconclusive(SampleTest.java:94)\n" }, { - "id": 36, + "id": 20, "at": 0, "type": "info", "message": "spam" }, { - "id": 37, + "id": 21, "at": 0, "type": "info", "message": "<body />" }, { - "id": 38, + "id": 22, "at": 0, "type": "info", "message": "Very informative: \"\\n\": \n" }, { - "id": 39, + "id": 23, "at": 0, "type": "warning", "message": "Oh no\njava.lang.IllegalArgumentException: error\n\tat com.yahoo.vespa.test.samples.SampleTest.successful(SampleTest.java:76)\nCaused by: java.lang.RuntimeException: wrapped\n\t... 1 more\n" }, { - "id": 43, + "id": 27, "at": 0, "type": "info", "message": "spam" }, { - "id": 46, + "id": 30, "at": 0, "type": "info", "message": "Catch me if you can!" }, { - "id": 50, + "id": 34, "at": 0, "type": "error", - "message": "org.opentest4j.AssertionFailedError: no charm\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:39)\n\tat org.junit.jupiter.api.Assertions.fail(Assertions.java:134)\n\tat com.yahoo.vespa.test.samples.SampleTest$Inner.lambda$others$1(SampleTest.java:106)\n" + "message": "org.opentest4j.AssertionFailedError: no charm\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)\n\tat org.junit.jupiter.api.Assertions.fail(Assertions.java:138)\n\tat com.yahoo.vespa.test.samples.SampleTest$Inner.lambda$others$1(SampleTest.java:106)\n" }, { - "id": 54, + "id": 38, "at": 0, "type": "info", "message": "spam" }, { - "id": 2, + "id": 67, "at": 0, "type": "error", - "message": "org.opentest4j.AssertionFailedError\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:35)\n\tat org.junit.jupiter.api.Assertions.fail(Assertions.java:115)\n\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.test(FailingTestAndBothAftersTest.java:20)\n\tSuppressed: java.lang.RuntimeException\n\t\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.moreFail(FailingTestAndBothAftersTest.java:17)\n" + "message": "org.opentest4j.AssertionFailedError\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:34)\n\tat org.junit.jupiter.api.Assertions.fail(Assertions.java:119)\n\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.test(FailingTestAndBothAftersTest.java:20)\n\tSuppressed: java.lang.RuntimeException\n\t\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.moreFail(FailingTestAndBothAftersTest.java:17)\n" }, { - "id": 4, + "id": 69, "at": 0, "type": "error", "message": "java.lang.RuntimeException\n\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.fail(FailingTestAndBothAftersTest.java:14)\n" }, { - "id": 7, + "id": 72, "at": 0, "type": "error", "message": "org.junit.platform.commons.JUnitException: @BeforeAll method 'void com.yahoo.vespa.test.samples.WrongBeforeAllTest.wrong()' must be static unless the test class is annotated with @TestInstance(Lifecycle.PER_CLASS).\n" }, { - "id": 11, + "id": 76, "at": 0, "type": "error", "message": "java.lang.NullPointerException\n\tat com.yahoo.vespa.test.samples.FailingExtensionTest$FailingExtension.<init>(FailingExtensionTest.java:20)\n" }, { - "id": 15, + "id": 80, "at": 12000, "type": "error", - "message": "java.lang.ClassNotFoundException: School's out all summer!\n" + "message": "java.lang.ClassNotFoundException: School's out all summer!\n\tat com.yahoo.vespa.testrunner.TestRunnerHandlerTest.setup(TestRunnerHandlerTest.java:57)\n" } ] } diff --git a/vespa-osgi-testrunner/src/test/resources/report.json b/vespa-osgi-testrunner/src/test/resources/report.json index cf4868877a4..0252bfe565c 100644 --- a/vespa-osgi-testrunner/src/test/resources/report.json +++ b/vespa-osgi-testrunner/src/test/resources/report.json @@ -110,7 +110,7 @@ "type": "output", "children": [ { - "message": "org.opentest4j.AssertionFailedError: baz ==> expected: <foo> but was: <bar>\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:55)\n\tat org.junit.jupiter.api.AssertionUtils.failNotEqual(AssertionUtils.java:62)\n\tat org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)\n\tat org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1152)\n\tat com.yahoo.vespa.test.samples.SampleTest.failing(SampleTest.java:82)\n", + "message": "org.opentest4j.AssertionFailedError: baz ==> expected: <foo> but was: <bar>\n\tat org.junit.jupiter.api.AssertionFailureBuilder.build(AssertionFailureBuilder.java:151)\n\tat org.junit.jupiter.api.AssertionFailureBuilder.buildAndThrow(AssertionFailureBuilder.java:132)\n\tat org.junit.jupiter.api.AssertEquals.failNotEqual(AssertEquals.java:197)\n\tat org.junit.jupiter.api.AssertEquals.assertEquals(AssertEquals.java:182)\n\tat org.junit.jupiter.api.Assertions.assertEquals(Assertions.java:1156)\n\tat com.yahoo.vespa.test.samples.SampleTest.failing(SampleTest.java:82)\n", "at": 0, "level": "error" } @@ -265,7 +265,7 @@ "type": "output", "children": [ { - "message": "org.opentest4j.AssertionFailedError: no charm\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:39)\n\tat org.junit.jupiter.api.Assertions.fail(Assertions.java:134)\n\tat com.yahoo.vespa.test.samples.SampleTest$Inner.lambda$others$1(SampleTest.java:106)\n", + "message": "org.opentest4j.AssertionFailedError: no charm\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:38)\n\tat org.junit.jupiter.api.Assertions.fail(Assertions.java:138)\n\tat com.yahoo.vespa.test.samples.SampleTest$Inner.lambda$others$1(SampleTest.java:106)\n", "at": 0, "level": "error" } @@ -350,7 +350,7 @@ "type": "output", "children": [ { - "message": "org.opentest4j.AssertionFailedError\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:35)\n\tat org.junit.jupiter.api.Assertions.fail(Assertions.java:115)\n\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.test(FailingTestAndBothAftersTest.java:20)\n\tSuppressed: java.lang.RuntimeException\n\t\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.moreFail(FailingTestAndBothAftersTest.java:17)\n", + "message": "org.opentest4j.AssertionFailedError\n\tat org.junit.jupiter.api.AssertionUtils.fail(AssertionUtils.java:34)\n\tat org.junit.jupiter.api.Assertions.fail(Assertions.java:119)\n\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.test(FailingTestAndBothAftersTest.java:20)\n\tSuppressed: java.lang.RuntimeException\n\t\tat com.yahoo.vespa.test.samples.FailingTestAndBothAftersTest.moreFail(FailingTestAndBothAftersTest.java:17)\n", "at": 0, "level": "error" } @@ -473,7 +473,7 @@ "type": "output", "children": [ { - "message": "java.lang.ClassNotFoundException: School's out all summer!\n", + "message": "java.lang.ClassNotFoundException: School's out all summer!\n\tat com.yahoo.vespa.testrunner.TestRunnerHandlerTest.setup(TestRunnerHandlerTest.java:57)\n", "at": 12000, "level": "error" } |