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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Core] Emit exceptions on failure to handle test run finished events #2651

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Enabled reproducible builds ([2641](https://github.com/cucumber/cucumber-jvm/issues/2641) Herv茅 Boutemy )
- [Core] Mark Allure 5 and 6 plugins as incompatible ([2652](https://github.com/cucumber/cucumber-jvm/issues/2652) M.P. Korstanje)

## Fixed
- [Core] Emit exceptions on failure to handle test run finished events ([2651](https://github.com/cucumber/cucumber-jvm/issues/2651) M.P. Korstanje)

## [7.9.0] - 2022-11-01
### Changed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,11 @@ public void run() {
context.runBeforeAllHooks();
runFeatures(features);
});
execute(context::runAfterAllHooks);
execute(context::finishTestRun);
try {
execute(context::runAfterAllHooks);
} finally {
context.finishTestRun();
}
Throwable exception = context.getThrowable();
if (exception != null) {
throwAsUncheckedException(exception);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

import io.cucumber.core.backend.Pending;

import java.io.PrintStream;
import java.io.PrintWriter;

@Pending
public final class StubPendingException extends RuntimeException {

Expand All @@ -13,4 +16,14 @@ public StubPendingException(String message) {
super(message);
}

@Override
public void printStackTrace(PrintWriter printWriter) {
printWriter.print(getMessage());
}

@Override
public void printStackTrace(PrintStream printStream) {
printStream.print(getMessage());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import io.cucumber.plugin.event.TestRunStarted;
import io.cucumber.plugin.event.TestStepFinished;
import io.cucumber.plugin.event.TestStepStarted;
import org.hamcrest.CoreMatchers;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.function.Executable;
import org.mockito.ArgumentCaptor;
Expand Down Expand Up @@ -366,6 +367,40 @@ void should_fail_on_event_listener_exception_when_running_in_parallel() {
assertThat(actualThrown.getSuppressed(), is(arrayWithSize(3)));
}

@Test
void should_fail_on_event_listener_exception_at_test_run_started() {
RuntimeException expectedException = new RuntimeException("This exception is expected");
ConcurrentEventListener brokenEventListener = publisher -> publisher.registerHandlerFor(TestRunStarted.class,
(TestRunStarted event) -> {
throw expectedException;
});

Executable testMethod = () -> Runtime.builder()
.withFeatureSupplier(new StubFeatureSupplier())
.withAdditionalPlugins(brokenEventListener)
.build()
.run();
RuntimeException actualThrown = assertThrows(RuntimeException.class, testMethod);
assertThat(actualThrown, equalTo(expectedException));
}

@Test
void should_fail_on_event_listener_exception_at_test_run_finished() {
RuntimeException expectedException = new RuntimeException("This exception is expected");
ConcurrentEventListener brokenEventListener = publisher -> publisher.registerHandlerFor(TestRunFinished.class,
(TestRunFinished event) -> {
throw expectedException;
});

Executable testMethod = () -> Runtime.builder()
.withFeatureSupplier(new StubFeatureSupplier())
.withAdditionalPlugins(brokenEventListener)
.build()
.run();
RuntimeException actualThrown = assertThrows(RuntimeException.class, testMethod);
assertThat(actualThrown, equalTo(expectedException));
}

@Test
void should_interrupt_waiting_plugins() throws InterruptedException {
final Feature feature1 = TestFeatureParser.parse("path/test.feature", "" +
Expand Down
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<groupId>io.cucumber</groupId>
<artifactId>cucumber-parent</artifactId>
<version>4.1.1</version>
<relativePath/>
</parent>
<artifactId>cucumber-jvm</artifactId>
<version>7.10.0-SNAPSHOT</version>
Expand Down