Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MalformedInputException seen when running forked JUnit5 tests. #100

Open
sageserpent-open opened this issue Aug 19, 2024 · 5 comments
Open

Comments

@sageserpent-open
Copy link

Bug first seen in upgrade to version 0.13.0 (was 0.11.4 for last successful build).

Repository - Americium

Observed in Git commit SHA: 36f61a49a58c29fa083385924bf372334b2ba42f

Log of failing build: https://github.com/sageserpent-open/americium/runs/28895471763

This is also reproducible locally.

@sageserpent-open
Copy link
Author

Excerpt from build.sbt (mixed Scala and Java project, uses both JUnit5 suites and Scalatest suites):

  Test / testOptions += Tests.Argument(jupiterTestFramework, "-q"),
  Test / testGrouping := {
    val tests = (Test / definedTests).value

    tests
      .groupBy(_.name)
      .map { case (groupName, group) =>
        new Group(
          groupName,
          group,
          SubProcess(
            (Test / forkOptions).value
              .withRunJVMOptions(
                Vector(
                  s"-Dtrials.runDatabase=trialsRunDatabaseForGroup$groupName"
                )
              )
              .withOutputStrategy(
                OutputStrategy.CustomOutput(OutputStream.nullOutputStream)
              )
          )
        )
      }
      .toSeq
  },
  Global / concurrentRestrictions := Seq(Tags.limit(Tags.ForkedTestGroup, 6)),
  Test / fork                     := true,
  Test / testForkedParallel       := false,

  ....

  libraryDependencies += "org.scalatest"  %% "scalatest"  % "3.2.19" % Test,
  libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.18.0" % Test,
  libraryDependencies += "org.scalatestplus" %% "scalacheck-1-16" % "3.2.14.0" % Test,
  libraryDependencies += "org.mockito" % "mockito-core" % "5.12.0" % Test,
  libraryDependencies += "org.mockito" % "mockito-junit-jupiter" % "5.12.0" % Test,
  libraryDependencies += "com.github.seregamorph" % "hamcrest-more-matchers" % "0.1" % Test,
  libraryDependencies += "com.github.sbt.junit" % "jupiter-interface" % JupiterKeys.jupiterVersion.value % Test,
  libraryDependencies ++= Seq(
    "org.junit.platform" % "junit-platform-runner" % "1.11.0" % Test,
    "org.junit.jupiter"  % "junit-jupiter-engine"  % "5.11.0" % Test
  ),
  libraryDependencies += "org.hamcrest"          % "hamcrest" % "3.0"    % Test,
  libraryDependencies += "com.eed3si9n.expecty" %% "expecty"  % "0.16.0" % Test

Plugins.sbt:

addDependencyTreePlugin

addSbtPlugin("com.github.sbt.junit" % "sbt-jupiter-interface" % "0.13.0")
addSbtPlugin("org.scalameta"        % "sbt-scalafmt"          % "2.5.2")
addSbtPlugin("com.github.sbt"       % "sbt-release"           % "1.4.0")
addSbtPlugin("com.github.sbt"       % "sbt-pgp"               % "2.2.1")
addSbtPlugin("org.xerial.sbt"       % "sbt-sonatype"          % "3.11.2")
addSbtPlugin("org.scoverage"        % "sbt-scoverage"         % "2.1.0")

@sageserpent-open
Copy link
Author

Also seen in version 0.12.0.

I shall try to debug into this with a local build / minimize the failure.

@sageserpent-open
Copy link
Author

This is being thrown as part of saving the XML for the test suite result.

An excerpt from this shows:

    <testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="casesUsingACountedStrategy(long):20" time="0.001">
                      
                    </testcase>
    <testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="casesUsingACountedStrategy(long):21" time="0.001">
                      
                    </testcase>
    <testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="casesUsingACountedStrategy(long):22" time="0.001">
                      
                    </testcase>
    <testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="casesUsingACountedStrategy(long):23" time="0.001">
                      
                    </testcase>
              
    <system-out/>
              
    <system-err/>
            
</testsuite>

The exception is thrown down in StreamEncoder.implWrite, which is using a UTF-8 encoder.

Looking at the char buffer being encoded, we have:

</testcase><testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="dynamicTestsExampleUsingATriple():[5] [1265385001,ᠸ鹃謘,false]" time="0.001">
                      
                    </testcase><testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="dynamicTestsExampleUsingATriple():[6] [-2145422663,,false]" time="0.003">
                      
                    </testcase><testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="dynamicTestsExampleUsingATriple():[7] [616424561,,false]" time="0.002">
                      
                    </testcase><testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="dynamicTestsExampleUsingATriple():[8] [-1414906528,,false]" time="0.003">
                      
                    </testcase><testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="dynamicTestsExampleUsingATriple():[9] [-832980694,,false]" time="0.001">
                      
                    </testcase><testcase classname="com.sageserpent.americium.java.examples.junit5.DemonstrateJUnit5Integration" name="dynamicTestsExampleUsingATriple():[10] [146406663,޾⬨,false]" time="0.002">

The dynamic test names generated include test parameter values that are non UTF-8 strings; I'm assuming this is causing the problem.

@sageserpent-open
Copy link
Author

sageserpent-open commented Aug 19, 2024

Presumably the changes made in https://github.com/sbt/sbt-jupiter-interface/pull/94/files#diff-114898290f2f9ece1e9a21ec71f569775778ad0464e713a10ec28771a4f9ca29 as part of the 0.12.0 release started passing the full test names down to saving the XML?

This would then expose them to the invocation here: https://github.com/sbt/sbt/blob/aaa68883aab4b3eb65de954253e9765cd09d7c36/testing/src/main/scala/sbt/JUnitXmlTestsListener.scala#L262 using UTF-8.

@sageserpent-open
Copy link
Author

Tweaking the project definition in build.sbt by disabling the XML report generation (.disablePlugins(plugins.JUnitXmlReportPlugin)) was an effective workaround for this.

I'll leave this issue open in case it's of wider interest, but feel free to close it otherwise.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant