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

Forward test events to listener as they're emitted #7435

Open
Duhemm opened this issue Nov 21, 2023 · 0 comments
Open

Forward test events to listener as they're emitted #7435

Duhemm opened this issue Nov 21, 2023 · 0 comments
Assignees

Comments

@Duhemm
Copy link
Contributor

Duhemm commented Nov 21, 2023

Current situation

sbt provides an API to register test event listeners which help better understand test execution. At the moment, it's impossible to rely on the timing of these events, because:

  • they're not passed on to the listeners at the time they're emitted
  • startGroup and endGroup events are received by listeners at different times depending on whether the tests run in-process or in a forked JVM.

What I'd like to do

I would like to fix this by:

  • changing the in-process test runner so that events are immediately sent to the listeners as they're produced by the test frameworks.
  • slightly change the communication protocol between sbt and the forked JVM:
    • introduce new StartGroup and EndGroup messages, which sbt will map to the eponymous events of the test listeners.
    • send test events immediately as they're produced by the test frameworks.
    • Increase the priority of the thread reading messages from the forked JVM, so that they're handled as early as possible.

No API changes are envisioned for this work.

Benefits

This change will make it possible to measure how much time is spent doing test class setup and cleanup. Currently, it's not possible to get this information, because the startGroup, testEvent and endGroup callbacks are called together and their payloads don't contain this information.

Limitations

The test events have no timestamp, so it's impossible for test events listeners to know accurately when an event was emitted. The proposed changes improves the situation, but the results cannot be 100% accurate. It'd be good to look into this for sbt 2.

Details of current implementation

When forking

  • All events are collected for a given test group:
    final EventHandler handler =
    new EventHandler() {
    public void handle(final Event e) {
    eventList.add(new ForkEvent(e));
    }
    };
  • The events are sent back together to sbt:
    writeEvents(os, taskDef, events);
  • sbt reads the events and emits the startGroup, testEvent and endGroup events all together:
    case Array(group: String, tEvents: Array[Event]) =>
    listeners.foreach(_ startGroup group)
    val event = TestEvent(tEvents)
    listeners.foreach(_ testEvent event)
    val suiteResult = SuiteResult(tEvents)
    results += group -> suiteResult
    listeners.foreach(_.endGroup(group, suiteResult.result))

When running in-process

@Duhemm Duhemm self-assigned this Nov 21, 2023
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