-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Add DeleteIfExist to prior creating a container make sure it is deleted. #205
Comments
That's true, if you have it in a That is a really good idea!! Hmm... I would vote for But it has to be on named containers only! Cheers, |
Hi @DrLeh, I've implemented the Cheers, 🐅 Sample usage var name = Guid.NewGuid().ToString();
var container = Fd.UseContainer()
.UseImage("postgres:9.6-alpine")
.WithName($"name-{name}")
.Build();
var id = container.Id;
using (var c = Fd
.UseContainer()
.DeleteIfExists() // <-- It will delete the named container if it exists *before* it creates the new one.
.UseImage("postgres:9.6-alpine")
.WithName($"name-{name}")
.Build())
{
// Ids should not be equal - since deleted and then created.
AreNotEqual(id, c.Id);
} |
@mariotoffia looks like i'm still getting an error when the container is still running. Is there an option to stop it if it's running to delete it? My code has IDisposable but it seems when i stop debugging it doesn't get called: public class ElasticContainerFixture : IDisposable
{
public string ClusterName = "es-docker-cluster-elastic-ci-tests";
public IContainerService Container;
public void Dispose()
{
Container.Dispose();
}
public ElasticContainerFixture()
{
var b = new Builder().UseContainer()
.UseImage("elasticsearch:7.14.1")
.WithEnvironment(@"node.name=elastic-ci-tests",
@$"cluster.name={ClusterName}",
@"discovery.type=single-node",
@"""ES_JAVA_OPTS=-Xms512m -Xmx512m""")
.ExposePort(9800, 9200)
.ExposePort(9900, 9300)
.WithName($"elastic-ci-tests_{Environment.MachineName.Replace(" ", "_")}")
.DeleteIfExists()
.WaitForHttp("http://localhost:9800", continuation: (req, i) =>
{
//this is ultimately the same code they have in WaitForHttp with
//no continuation: specified. We might want to check a different url
if (req.Code == System.Net.HttpStatusCode.OK)
return 0L;
return 2000;
});
Container = b.Build();
Container.Start();
}
} |
Hi @DrLeh try to use option force: true when doing DeleteIfExists if that Will solve your problem. Yes, when you break, it Will not call dispose - if you just continue - it will call it :) I always let the test run or throw so it Will cleanup properly but curious if force: true will solve the problem - could you please respond if it worked or not - if not, I’ll fix it now that I’ve got a unit test. |
Thanks I didn't see that force option! Thanks for the incredibly quick turnaround, loving this library! |
I'm working on putting in FluentDocker into some unit tests for elasticsearch. Under some circumstances, the container sometimes isn't getting disposed. Like if I'm debugging through the test and stop debugging, sometimes it seems Dispose() is not getting called.
I see we have the
ReuseIfExists()
method, which is nice, but is there any way to doDeleteIfExists()
/ReCreateIfExists()
? For a unit test I always want the container to be fresh, so I don't want.Build()
orStart()
to fail.I could presumably do something like this but it feels really janky:
The text was updated successfully, but these errors were encountered: