cucumber-jvm
cucumber-jvm copied to clipboard
@Singleton instances are broken in parallel execution
👓 What did you see?
@Singleton instances do not work in parallel execution, instead one instance per thread is created.
✅ What did you expect to see?
I expected only one instance of @Singleton bound classes to be created:
https://github.com/cucumber/cucumber-jvm/blob/6ec14f7edce8d9c8a5d679b3d1eae22fbc7b8675/cucumber-guice/README.md?plain=1#L72-L81
📦 Which tool/library version are you using?
cucumber-jvm (core+guice) 7.20.1
🔬 How could we reproduce it?
Test case that reproduce the bug: https://github.com/loveleif/cucumber-jvm/commit/1a52642a50dbea3d15185713fb18f3dbd07cc1bf.
- Bind a class in
Singletonscope. - Inject the singleton class in a scenario.
- Start a test suite with parallel execution.
- There will be multiple instances created, depending on how many threads are used.
📚 Any additional context?
My use case is query language testing for a database. Starting and stopping the database is time consuming, so we re-use the dbms between scenarios to drastically reduce execution time. A custom backend registers before/after all hooks to the glue that starts/stops the database (since regular before/after all hooks can't use dependency injection, but backends have access to Lookup).