-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
@Singleton instances are broken in parallel execution #2961
Comments
I'm tempted to attempt to try to fix this, if no one else wants to and you agree that this really is an issue :). As far as I can see, the heart of the issue is that One possible solution might be to let users specify a custom |
I'm afraid this will be harder then it looks. The current architecture is reaching its limits. But we can definitely update the documentation to describe that an object is a singleton w.r.t to the injector. For any other fixes it will depend a bit.
So if you think you can fix it within the current framework with an opt-in solution that still isolates the scenario scopes, I'd be happy to consider a pull request.
I'd like to avoid opening up the internals for extension. For any solution in this direction I think it would be better to take a page from JUnit Jupiters extension model and use a hierarchical context store that extensions can use to store state. But that is a much bigger project. I think a more feasible solution would be to consider reusing injectors that have the same configuration. Similar to how Spring reuses application contexts between tests. This could be achieved with a |
Thanks @mpkorstanje, I appreciate the feedback. I can see where you're coming from, even though exposing
For me personally, I would rather keep my current workaround. Which is a similar concept, I have a custom implementation of // ObjectFactory for testing with db conf A
class DbConfAObjectFactory extends MyCustomGuiceFactory {
private final static Injector DB_CONF_A_INJECTOR = createInjectorWithDbConf(...);
@Override
Injector injector() {
return DB_CONF_A_INJECTOR;
}
}
// ObjectFactory for testing with db conf B
class DbConfBObjectFactory extends MyCustomGuiceFactory {
private final static Injector DB_CONF_B_INJECTOR = createInjectorWithDbConf(...);
@Override
Injector injector() {
return DB_CONF_B_INJECTOR;
}
}
... Anyway, feels like I'm in too deep for a first contribution. So I will keep my workaround, it works so it's not a big issue (thanks to the generous extensibility already provided π). And by the way, generally I've been very pleased with the library so far, thanks for all the work (I'm moving our gherkin tests from a custom framework we have used before to the standard cucumber-jvm one). |
As a smaller contribution, would you like to update the documentation instead? |
π 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
π¦ 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.
Singleton
scope.π 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
).The text was updated successfully, but these errors were encountered: