-
-
Notifications
You must be signed in to change notification settings - Fork 2k
Open
Labels
π documentationImprovements or additions to documentationImprovements or additions to documentation
Description
π 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:
cucumber-jvm/cucumber-guice/README.md
Lines 72 to 81 in 6ec14f7
#### Singleton scope | |
Cucumber will create just one instance of a class bound in singleton scope | |
that will last for the lifetime of all test scenarios in the test run. You | |
should use singleton scope if your classes are stateless. You can also use | |
singleton scope when your classes contain state but with caution. You should | |
be absolutely sure that a state change in one scenario could not possibly | |
influence the success or failure of a subsequent scenario. As an example of | |
when you might use a singleton, imagine you have an http client that is | |
expensive to create. By holding a reference to the client in a class bound in | |
singleton scope, you can reuse the client in multiple scenarios. |
π¦ 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: loveleif@1a52642.
- Bind a class in
Singleton
scope. - 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
).
Metadata
Metadata
Assignees
Labels
π documentationImprovements or additions to documentationImprovements or additions to documentation