-
-
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
Best way to tear down Step classes and their dependencies? #993
Comments
I have created a pull request to address item 3 above: #994 |
Hi @RichardBradley , We've been using See also the discussion we've had at our software testing course on Cucumber usage of |
That's a separate issue to the one I'm discussing here, which is about how to ensure that To avoid derailing this issue, please could you raise a new issue about that? If you CC me on there, I'll add my thoughts about it. |
merged as of c0ffacd |
The The
No, not as far as I know. |
I'm afraid I don't have any advice here, I generally have avoided using injection systems in my cucumber step definitions :) Sorry. |
OK, thanks. The changes in my PR have fixed this enough for me, and hopefully the extra docs will suffice for anyone with similar issues in future. |
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
Hi,
I have a medium / large webapp using
cucumber-jvm
for integration testing.We have 38 Step definition classes (one for each feature group, and a few common step groups), which use 23 "connector" type dependency classes. The connectors do things like connecting directly to the database of the app under test for steps like "given I have a widget of type X".
The step code looks a bit like:
We are using
cucumber-picocontainer
as recommended at https://cucumber.io/docs/reference/java-diI have recently noticed that
cucumber-jvm
creates a new set of Step classes for every single Scenario, as discussed at http://stackoverflow.com/a/33063300/8261 . It also creates all Step classes (and their dependencies) for all scenarios, even if they are not needed.This is fairly inefficient for us, as we are forever creating and tearing down database connections even for Scenarios that don't use the database. I have refactored our connectors to create connections lazily to help with this.
At the same time, I noticed that we were leaking loads of database connections because of there being one instance of
DatabaseTestConnector
for each Scenario. As noted at #992, the Picocontainer used by cucumber-jvm is configured to not use its Lifecycle annotations. I tried to fix the leak by adding the "@after" annotations toDatabaseTestConnector
as shown above, but it seems that the order of @after annotations is not guaranteed or stable, so my DB connection is now sometimes closed before the Step tries to do its cleanup.So:
DatabaseTestConnector
runs after the @after onWidgetSteps
?cucumber-jvm
picocontainer is configured with aNullLifecycleStrategy
? I think the easiest fix here would be to change that and to use Disposeable onDatabaseTestConnector
instead of @after.Thanks
The text was updated successfully, but these errors were encountered: