Skip to content

munit and junit test reporting does not work when sbt runs tests in fork mode #8665

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

Open
mwisnicki opened this issue Apr 2, 2025 · 11 comments
Assignees
Labels
comp: ci visibility Continuous Integration Visibility type: bug

Comments

@mwisnicki
Copy link

mwisnicki commented Apr 2, 2025

Tracer Version(s)

1.47.3~4a85e1fff5

Java Version(s)

21.0.2

JVM Vendor

Eclipse Adoptium / Temurin

Bug Report

When sbt is configured to run tests in fork mode, neither munit nor junit tests are reported to datadog.
Forking mode works for scalatest.

Expected Behavior

munit with Test/fork := true reports tests to datadog.

Reproduction Code

build.sbt

scalaVersion := "3.3.5"
Test / fork := true // comment it out to make this work
libraryDependencies ++= Seq(
  "junit" % "junit" % "4.13.2" % Test,
  "com.github.sbt" % "junit-interface" % "0.13.3" % Test,
  "org.scalameta" %% "munit" % "1.1.0" % Test,
)

src/test/scala/ExampleTest.scala

class ExampleJunitTest {
  @org.junit.Test
  def hello(): Unit = {
    println("Hello from JUnit")
  }
}

class ExampleMunitTest extends munit.FunSuite {
  test("hello") {
    println("Hello from MUnit")
  }
}

project/build.properties

sbt.version=1.10.11

Simplified snippet from .github/workflows/test.yaml

jobs:
  tests:
    steps:
      - uses: sbt/setup-sbt@v1
      - uses: actions/setup-java@v4
        with:
          distribution: temurin
          java-version: 21
      - uses: datadog/test-visibility-github-action@v2
        with:
          languages: java
          api_key: ${{ secrets.DATADOG_API_KEY }}
          service: foo
      - run: sbt test
@nikita-tkachenko-datadog nikita-tkachenko-datadog added the comp: ci visibility Continuous Integration Visibility label Apr 3, 2025
@nikita-tkachenko-datadog
Copy link
Contributor

nikita-tkachenko-datadog commented Apr 3, 2025

Hi @mwisnicki, thank you for reporting this!
The reason tests are not reported to Datadog is that the DD tracer is only injected into the parent SBT process, and not into the forked JVMs that execute the tests.
Could you please try using the java-instrumented-build-system: all GitHub Action setting? That will ensure the tracer is injected into every JVM.

- uses: datadog/test-visibility-github-action@v2
  with:
    languages: java
    api_key: ${{ secrets.DATADOG_API_KEY }}
    service: foo
    java-instrumented-build-system: all

@mwisnicki
Copy link
Author

java-instrumented-build-system seems to have helped getting test results in fork mode however I've noticed that regardless of this setting and whether forking is enabled, test runs and test suites are disconnected from test session and module. Both for munit and junit. I'm surprised that session didn't propagate even in non-fork mode.


Additional minor problem is that I have warning Warning: dd-java-agent is being initialized more than once but that's understandable, it's injected by github action and by sbt-datadog plugin. I'll have to figure out how to disable injection from the latter in tests but for now I disabled it completely to eliminate any interference.

Finally there's I think unrelated issue that DataDog sometimes stops updating github comment with reports. I think I saw it before so it's likely not caused by this.

@mwisnicki
Copy link
Author

It's interesting that even with Test/fork := false I see two OpenJDK and dd.trace startup messages as well as

Warning: dd-java-agent is being initialized more than once. 

@mwisnicki
Copy link
Author

mwisnicki commented Apr 4, 2025

So an example test run has following tag:

test_session:
  fingerprint_v2: 7db8218e3ff2e7d4
  name: test-codegen

while disconnected but probably related test session looks like this:

test_session:
  fingerprint: 89df8bdf5ab3d8eb
  fingerprint_v2: 7db8218e3ff2e7d4
  name: test-codegen

Month ago with library_version: 1.46.1~8e0205904b (now 1.47.3) it looked similar but used to work.

@mwisnicki
Copy link
Author

Another strange problem - I have 2 jobs in workflow triggered by PR but now only see reports from one of them.
They are set up identically except 2nd one uses branch instead of branch merged to main.
The logs from both seem correct.

@mwisnicki
Copy link
Author

I'll try to narrow down which version introduced the break.

@nikita-tkachenko-datadog
Copy link
Contributor

test runs and test suites are disconnected from test session and module

Could you provide more context here please?

@mwisnicki
Copy link
Author

mwisnicki commented Apr 7, 2025

test runs and test suites are disconnected from test session and module

Could you provide more context here please?

All test runs are present but around half of individual test runs have their Session Trace tab empty (it never arrives):

Image

It's even weirder when I go see sessions.

My workflow has 2 jobs so I expect 2 sessions.

Instead there are 2-3 sessions. Sometimes one is green but most of them grey and marked as skipped although they took more or less same time.
Their test suites and test runs tabs are empty (no matching results found).

When I downgrade to 1.46.1 things start to work:

Image

@mwisnicki
Copy link
Author

1.47.0 introduced the break

@mwisnicki
Copy link
Author

Which is a shame since it also introduced much needed fix for #8445

@nikita-tkachenko-datadog
Copy link
Contributor

Hi @mwisnicki, thank you for these details, they helped a lot with reproducing the problem! The fix is included in the Java tracer release v1.48.0 that was rolled out yesterday. Could you please try it out and let me know if it fixes the issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
comp: ci visibility Continuous Integration Visibility type: bug
Projects
None yet
Development

No branches or pull requests

2 participants