Skip to content

Commit

Permalink
Fixes a bug where the configuration was not merged, closes #39.
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Mar 6, 2019
1 parent 992a1c6 commit 30fca26
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,16 @@ public string MacAddress

public async Task StartAsync()
{
this.id = await this.id.IfNoneAsync(() =>
{
return TestcontainersClient.Instance.RunAsync(this.Configuration);
});

var startTask = TestcontainersClient.Instance.StartAsync(this.Id);
await this.Create();

var waitTask = this.Configuration.WaitStrategy?.WaitUntil() ?? Wait.ForContainer(this.Id).WaitUntil();

await Task.WhenAll(startTask, waitTask);
await this.Start();

this.container = await MetaDataClientContainers.Instance.ByIdAsync(this.Id);
}

public async Task StopAsync()
{
await TestcontainersClient.Instance.StopAsync(this.Id);

this.id.IfSome(id =>
{
this.container = None;
});
await this.Stop();
}

public void Dispose()
Expand All @@ -109,18 +97,52 @@ public void Dispose()

protected virtual void Dispose(bool disposing)
{
this.id.IfSome(async id =>
if (this.Configuration.CleanUp)
{
Task.Run(this.CleanUp);
}
else
{
Task.Run(this.Stop);
}
}

private async Task Create()
{
this.id = await this.id.IfNoneAsync(() =>
{
return TestcontainersClient.Instance.RunAsync(this.Configuration);
});
}

private async Task Start()
{
await this.id.IfSomeAsync(async id =>
{
if (this.Configuration.CleanUp)
{
this.id = None;
this.container = None;
await TestcontainersClient.Instance.RemoveAsync(id);
}
else
{
await TestcontainersClient.Instance.StopAsync(id);
}
var startTask = TestcontainersClient.Instance.StartAsync(id);

var waitTask = this.Configuration.WaitStrategy?.WaitUntil() ?? Wait.ForContainer(id).WaitUntil();

await Task.WhenAll(startTask, waitTask);
});
}

private async Task Stop()
{
await this.id.IfSomeAsync(async id =>
{
this.container = None;
await TestcontainersClient.Instance.StopAsync(id);
});
}

private async Task CleanUp()
{
await this.id.IfSomeAsync(async id =>
{
this.id = None;
this.container = None;
await TestcontainersClient.Instance.RemoveAsync(id);
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static T Merge<T>(T myself, T old)
return myself ?? old;
}

private static IReadOnlyCollection<T> Merge<T>(IReadOnlyCollection<T> myself, ref IReadOnlyCollection<T> old)
private static IReadOnlyCollection<T> Merge<T>(IReadOnlyCollection<T> myself, IReadOnlyCollection<T> old)
where T : class
{
if (myself == null)
Expand Down

0 comments on commit 30fca26

Please sign in to comment.