Skip to content

[Core] Synchronize event bus before use #2358

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

Merged
merged 1 commit into from
Aug 10, 2021
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
### Removed

### Fixed
* [Core] Synchronize event bus before use ([#2358](https://github.com/cucumber/cucumber-jvm/pull/2358)) M.P. Korstanje)

## [6.11.0] (2021-08-05)

Expand Down
4 changes: 4 additions & 0 deletions core/src/main/java/io/cucumber/core/runtime/Runtime.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import static io.cucumber.core.runtime.SynchronizedEventBus.synchronize;
import static java.util.Collections.emptyList;
import static java.util.stream.Collectors.collectingAndThen;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -174,6 +175,9 @@ public Runtime build() {
}
final ExitStatus exitStatus = new ExitStatus(runtimeOptions);
plugins.addPlugin(exitStatus);

final EventBus eventBus = synchronize(this.eventBus);

if (runtimeOptions.isMultiThreaded()) {
plugins.setSerialEventBusOnEventListenerPlugins(eventBus);
} else {
Expand Down
4 changes: 3 additions & 1 deletion junit/src/main/java/io/cucumber/junit/Cucumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.cucumber.core.runtime.ObjectFactoryServiceLoader;
import io.cucumber.core.runtime.ObjectFactorySupplier;
import io.cucumber.core.runtime.ScanningTypeRegistryConfigurerSupplier;
import io.cucumber.core.runtime.SynchronizedEventBus;
import io.cucumber.core.runtime.ThreadLocalObjectFactorySupplier;
import io.cucumber.core.runtime.ThreadLocalRunnerSupplier;
import io.cucumber.core.runtime.TimeServiceEventBus;
Expand All @@ -44,6 +45,7 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import static io.cucumber.core.runtime.SynchronizedEventBus.synchronize;
import static io.cucumber.junit.FileNameCompatibleNames.uniqueSuffix;
import static java.util.stream.Collectors.groupingBy;
import static java.util.stream.Collectors.toList;
Expand Down Expand Up @@ -148,7 +150,7 @@ public Cucumber(Class<?> clazz) throws InitializationError {
.parse(CucumberProperties.fromSystemProperties())
.build(junitEnvironmentOptions);

this.bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
this.bus = synchronize(new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID));

// Parse the features early. Don't proceed when there are lexer errors
FeatureParser parser = new FeatureParser(bus::generateId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import io.cucumber.core.runtime.ObjectFactoryServiceLoader;
import io.cucumber.core.runtime.ObjectFactorySupplier;
import io.cucumber.core.runtime.ScanningTypeRegistryConfigurerSupplier;
import io.cucumber.core.runtime.SynchronizedEventBus;
import io.cucumber.core.runtime.ThreadLocalObjectFactorySupplier;
import io.cucumber.core.runtime.ThreadLocalRunnerSupplier;
import io.cucumber.core.runtime.TimeServiceEventBus;
Expand All @@ -33,6 +34,7 @@
import java.util.function.Predicate;
import java.util.function.Supplier;

import static io.cucumber.core.runtime.SynchronizedEventBus.synchronize;
import static io.cucumber.testng.TestCaseResultObserver.observe;
import static java.util.stream.Collectors.toList;

Expand Down Expand Up @@ -99,7 +101,7 @@ public TestNGCucumberRunner(Class<?> clazz, CucumberPropertiesProvider propertie
.enablePublishPlugin()
.build(environmentOptions);

EventBus bus = new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID);
EventBus bus = synchronize(new TimeServiceEventBus(Clock.systemUTC(), UUID::randomUUID));

Supplier<ClassLoader> classLoader = ClassLoaders::getDefaultClassLoader;
FeatureParser parser = new FeatureParser(bus::generateId);
Expand Down