karatelabs/karate · error · RuntimeException

Interrupted while publishing test event

Error message

Interrupted while publishing test event

What it means

JUnitBridgeListener queues test events (feature start/end, scenario end, completion) onto a blocking queue for the JUnit streamer to consume. If the publishing thread is interrupted while blocking on the queue, the listener restores the interrupt flag and rethrows as a RuntimeException.

Solutions

  1. Let the JVM shutdown proceed; this error usually signals an external interruption, not a bug
  2. Check for build/test timeouts that interrupt the reporting thread and raise them
  3. Ensure no custom code shuts down the executor/threads while Karate features are still running

Example fix

// build config before
<timeout>30</timeout>
// after
<timeout>300</timeout> <!-- allow long feature runs to finish -->
Defensive patterns

Strategy: try-catch

Validate before calling

// before shutdown, ensure reporting has drained
boolean idle = bridgeListener != null && bridgeListener.isIdle();

Type guard

null

Try / catch

try {
  runKarateSuite();
} catch (RuntimeException e) {
  if (e.getMessage() != null && e.getMessage().contains("Interrupted while publishing test event")) {
    Thread.interrupted(); // acknowledge and continue shutdown
    return;
  }
  throw e;
}

Prevention

When it happens

Trigger: The thread calling putEvent (via onFeatureStart/onFeatureEnd/onScenarioEnd/complete) is interrupted while the event queue is full or the JVM is shutting down.

Common situations: Build cancellation (Ctrl+C in Maven/Gradle), test timeouts that interrupt worker threads, executor shutdown while a feature is still reporting.

Related errors


AI-assisted analysis of karatelabs/karate@a22eb90246 (2026-09-12). Data as JSON: /api/errors/b7a7093ff054a842. Report an issue: GitHub.

Appendix: source

Thrown at karate-junit6/src/main/java/io/karatelabs/junit6/JUnitBridgeListener.java:103

     * Deliberately <em>not</em> driven by {@link #onSuiteEnd(SuiteResult)}: that callback
     * fires while the suite is still running its listener chain, so report writers (JUnit
     * XML, Cucumber JSON) registered after this bridge may not have flushed their
     * asynchronous per-feature writes yet. Emitting the terminal event from here — invoked
     * only once {@code Runner.Builder.parallel(...)} has fully returned — guarantees that
     * when the JUnit {@code @TestFactory} stream completes, all report files are on disk.
     *
     * @param result the suite result (may be null if execution failed before completing)
     */
    public void complete(SuiteResult result) {
        putEvent(new TestEvent.SuiteEnd(result));
    }

    private void putEvent(TestEvent event) {
        try {
            eventQueue.put(event);
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw new RuntimeException("Interrupted while publishing test event", e);
        }
    }

}

View on GitHub (pinned to a22eb90246)