use of io.cucumber.plugin.ConcurrentEventListener in project cucumber-jvm by cucumber.
the class RuntimeTest method should_fail_on_event_listener_exception_when_running_in_parallel.
@Test
void should_fail_on_event_listener_exception_when_running_in_parallel() {
Feature feature1 = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name 1\n" + " Scenario: scenario_1 name\n" + " Given first step\n" + " Scenario: scenario_2 name\n" + " Given first step\n");
Feature feature2 = TestFeatureParser.parse("path/test2.feature", "" + "Feature: feature name 2\n" + " Scenario: scenario_2 name\n" + " Given first step\n");
ConcurrentEventListener brokenEventListener = publisher -> publisher.registerHandlerFor(TestStepFinished.class, (TestStepFinished event) -> {
throw new RuntimeException("This exception is expected");
});
Executable testMethod = () -> Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2)).withAdditionalPlugins(brokenEventListener).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(2).build()).build().run();
CompositeCucumberException actualThrown = assertThrows(CompositeCucumberException.class, testMethod);
assertThat(actualThrown.getMessage(), is(equalTo("There were 3 exceptions. The details are in the stacktrace below.")));
assertThat(actualThrown.getSuppressed(), is(arrayWithSize(3)));
}
use of io.cucumber.plugin.ConcurrentEventListener in project cucumber-jvm by cucumber.
the class RuntimeTest method should_interrupt_waiting_plugins.
@Test
void should_interrupt_waiting_plugins() throws InterruptedException {
final Feature feature1 = TestFeatureParser.parse("path/test.feature", "" + "Feature: feature name 1\n" + " Scenario: scenario_1 name\n" + " Given first step\n" + " Scenario: scenario_2 name\n" + " Given first step\n");
final Feature feature2 = TestFeatureParser.parse("path/test2.feature", "" + "Feature: feature name 2\n" + " Scenario: scenario_2 name\n" + " Given first step\n");
final CountDownLatch threadBlocked = new CountDownLatch(1);
final CountDownLatch interruptHit = new CountDownLatch(1);
final ConcurrentEventListener brokenEventListener = publisher -> publisher.registerHandlerFor(TestStepFinished.class, (TestStepFinished event) -> {
try {
threadBlocked.countDown();
HOURS.sleep(1);
} catch (InterruptedException ignored) {
interruptHit.countDown();
}
});
Thread thread = new Thread(() -> Runtime.builder().withFeatureSupplier(new StubFeatureSupplier(feature1, feature2)).withAdditionalPlugins(brokenEventListener).withRuntimeOptions(new RuntimeOptionsBuilder().setThreads(2).build()).build().run());
thread.start();
threadBlocked.await(1, SECONDS);
thread.interrupt();
interruptHit.await(1, SECONDS);
assertThat(interruptHit.getCount(), is(equalTo(0L)));
}
use of io.cucumber.plugin.ConcurrentEventListener in project cucumber-jvm by cucumber.
the class PluginsTest method shouldSetConcurrentEventListener.
@Test
void shouldSetConcurrentEventListener() {
RuntimeOptions runtimeOptions = RuntimeOptions.defaultOptions();
Plugins plugins = new Plugins(pluginFactory, runtimeOptions);
ConcurrentEventListener plugin = mock(ConcurrentEventListener.class);
plugins.addPlugin(plugin);
plugins.setEventBusOnEventListenerPlugins(rootEventPublisher);
verify(plugin, times(1)).setEventPublisher(rootEventPublisher);
}
Aggregations