testcontainers / testcontainers/moby-ryuk
Would love Reuse with Ryuk 🤝🥰
Nobody has claimed this yet.
- Dominant language
- Go
- Stars
- 244
- Forks
- 41
- PR merge metrics
- No merged PRs in 30d
Description
TestContainers accepts the experimental option of "Reuse" to help save you (startup) time.
An example of this is on each one of our developer machines, where we're constantly running tests and tap-tap-tapping away at code. Great!
Reuse option means the moby-ryuk reaper doesn't start. The instance(s) now never get destroyed.
But can we have our cake an eat it?
Would be really nice if there could be an option to have it tear down after 'x' seconds or minutes of no test calls. That last bit (emphasized by me) is the kicker.
MAGIC SAUCE
Every time a test is ran (which leverages their custom TestFixture), we can 'remember' that the test is using the container. The Reaper just sits there waiting to see if they haven't used the container for whatever time setting they asked.
The TestContainer SDK offers a new method which will allow us to tell the moby-ryuk instance that we're running a test now.
E.g.
Developer is using TestContainers with a Database (anything) running. Following the .NET documentation, I'll create the following class (stripped down/back, to reduce noise in this issue)
public class MyAwesomeFancyPantsDatabaseFixture : IAsyncLifetime
{
...
public async Task InitializeAsync()
{
await _reaper.PingAsync(); // <-- THIS
}
...
}
If I was using xUnit, then my test class will run this once per xunit COLLECTION. Which is ok. Would be nicer if it was per test. I guess I could expose that in the ctor of the test class like:
[Collection("MyAwesomeFancyPantsDatabase TestContainers Collection")]
public class EndpointTests : IClassFixture<MyAwesomeFancyPantsDatabaseFixture >, IAsyncLifetime
{
public async Task InitializeAsync()
{
await _myAwesomeFancyPantsDatabaseFixture.PingAsync(); // Or whatever...
};
....
}
So we don't get instant tear down .. but if the container hasn't been used after x seconds, minutes, whatever, then the Reaper does it stuff and tears the container down and then finally, itself.
EDIT: Forget to describe the setup..
Oh! and we can setup this magical setting like ..
public SqlServerFixture() =>
_msSqlContainer = new MsSqlBuilder()
.WithImage("fancypants:latest")
.WithExposedPort(10000)
.WithReuse(true, TimeSpan.FromMinutes(20)) // <-- 🪄 🌠 PEW PEW! MAGIC HAPPENS HERE
.Build();
Thoughts?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reviewing the reuse and container-cleanup behavior in moby-ryuk, then determine where an inactivity timeout and test-use ping would fit. Done means a reuse option can configure a timeout, test activity resets it, and an unused container and reaper are eventually torn down; the issue names no files or tests to run.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- docker, go
- Domain
- devops, testing
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100