cucumber-jvm icon indicating copy to clipboard operation
cucumber-jvm copied to clipboard

@Singleton instances are broken in parallel execution

Open loveleif opened this issue 9 months ago • 4 comments

👓 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.

  1. Bind a class in Singleton scope.
  2. Inject the singleton class in a scenario.
  3. Start a test suite with parallel execution.
  4. 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).

loveleif avatar Jan 13 '25 17:01 loveleif