Skip to content
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

Reduce Container Usage #106

Open
michaelstaib opened this issue Nov 15, 2021 · 5 comments
Open

Reduce Container Usage #106

michaelstaib opened this issue Nov 15, 2021 · 5 comments
Assignees
Labels
enhancement New feature or request

Comments

@michaelstaib
Copy link
Member

At the moment we are using one container per class instance since in most cases we inject a resource as a IClassFixture. This can really drag down test performance. In many cases, for the test, it would be enough to create a new database within the container.

So the question is should we have some kind of a runtime state and reuse a container instance through multiple resources. I think the main issue why we did not do that was that we could not determine when the last test has be run and we can get rid of the container. Essentially a test run wide init.

@michaelstaib michaelstaib added the enhancement New feature or request label Nov 15, 2021
@michaelstaib
Copy link
Member Author

michaelstaib commented Nov 15, 2021

Something like this could be a way forward on this:
https://github.com/devlooped/xunit.assemblyfixture

@nscheibe, @philbir, @PascalSenn what do you guys think on this?

@michaelstaib michaelstaib self-assigned this Nov 15, 2021
@glucaci
Copy link
Member

glucaci commented Nov 15, 2021

This can be tackled with ICollectionFixture.

You can create for example a ICollectionFixture for MongoDB

[CollectionDefinition("MongoContainer")]
public class MongoCollectionFixture : ICollectionFixture<MongoResource> { }

and than use MongoCollectionFixture in all test classes which needs a MongoResource. This will create only one container for all classes which are using it.

[Collection("MongoContainer")]
public class RepositoryTests 
{
   public RepositoryTests (MongoResource mongoResource) { }
}

@michaelstaib
Copy link
Member Author

Collection fixture will not allow for parallel test runs.

@glucaci
Copy link
Member

glucaci commented Nov 15, 2021

Yes, that's right you don't have support for parallel test runs but at least for non-parallel ones that will help you.

Here is a sample from xUnit how we could do assembly fixture.

@michaelstaib
Copy link
Member Author

michaelstaib commented Nov 15, 2021

@glucaci this looks interesting :) It's much simpler then the repo I posted earlier. Still, the question remains if we want to build this into Squadron. We could register the attributes with the package installation and make it very simple for the consumer.

Still pondering if we in this case still want to inject the resource just to keep it the same and underneath have a pool that handles the running containers. This would then allow us to either create a container per test/class/assembly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants