Skip to content

Commit

Permalink
feat(#493): Add container lifecycle events (#743)
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn authored Jan 26, 2023
1 parent eb4a6d9 commit 478efc5
Show file tree
Hide file tree
Showing 31 changed files with 373 additions and 305 deletions.
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mkdocs==1.4.1
mkdocs==1.4.2
mkdocs-codeinclude-plugin==0.2.0
mkdocs-markdownextradata-plugin==0.2.5
mkdocs-material==8.5.6
mkdocs-material==8.5.11
3 changes: 2 additions & 1 deletion src/Testcontainers/Builders/AbstractBuilder`2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@ protected virtual TBuilderEntity Init()
/// <exception cref="ArgumentException">Thrown when a mandatory Docker resource configuration is not set.</exception>
protected virtual void Validate()
{
const string message = "Cannot detect the Docker endpoint. Use either the environment variables or the ~/.testcontainers.properties file to customize your configuration:\nhttps://dotnet.testcontainers.org/custom_configuration/";
_ = Guard.Argument(this.DockerResourceConfiguration.DockerEndpointAuthConfig, nameof(IResourceConfiguration<TCreateResourceEntity>.DockerEndpointAuthConfig))
.DockerEndpointAuthConfigIsSet();
.ThrowIf(argument => argument.Value == null, argument => new ArgumentException(message, argument.Name));
}

/// <summary>
Expand Down
8 changes: 0 additions & 8 deletions src/Testcontainers/Clients/ITestcontainersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,6 @@ internal interface ITestcontainersClient
/// <returns>Task that gets the Testcontainers logs.</returns>
Task<(string Stdout, string Stderr)> GetContainerLogs(string id, DateTime since = default, DateTime until = default, CancellationToken ct = default);

/// <summary>
/// Gets the Testcontainers.
/// </summary>
/// <param name="id">Docker container id.</param>
/// <param name="ct">Cancellation token.</param>
/// <returns>Task that gets the Testcontainers.</returns>
Task<ContainerListResponse> GetContainer(string id, CancellationToken ct = default);

/// <summary>
/// Gets the Testcontainers inspect information.
/// </summary>
Expand Down
6 changes: 0 additions & 6 deletions src/Testcontainers/Clients/TestcontainersClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,6 @@ public Task<bool> GetIsWindowsEngineEnabled(CancellationToken ct = default)
return this.system.GetIsWindowsEngineEnabled(ct);
}

/// <inheritdoc />
public Task<ContainerListResponse> GetContainer(string id, CancellationToken ct = default)
{
return this.containers.ByIdAsync(id, ct);
}

/// <inheritdoc />
public Task<ContainerInspectResponse> InspectContainer(string id, CancellationToken ct = default)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

/// <summary>
/// Wait for an HTTP(S) endpoint to return a particular status code.
Expand Down Expand Up @@ -43,7 +42,7 @@ public HttpWaitStrategy()
}

/// <inheritdoc />
public async Task<bool> Until(IContainer container, ILogger logger)
public async Task<bool> UntilAsync(IContainer container)
{
// Java falls back to the first exposed port. The .NET wait strategies do not have access to the exposed port information yet.
var containerPort = this.portNumber.GetValueOrDefault(Uri.UriSchemeHttp.Equals(this.schemeName, StringComparison.OrdinalIgnoreCase) ? HttpPort : HttpsPort);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ namespace DotNet.Testcontainers.Configurations
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

[PublicAPI]
public interface IWaitUntil
{
Task<bool> Until(IContainer container, ILogger logger);
Task<bool> UntilAsync(IContainer container);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@ namespace DotNet.Testcontainers.Configurations
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using JetBrains.Annotations;
using Microsoft.Extensions.Logging;

[PublicAPI]
public interface IWaitWhile
{
Task<bool> While(IContainer container, ILogger logger);
Task<bool> WhileAsync(IContainer container);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace DotNet.Testcontainers.Configurations
using System;
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using Microsoft.Extensions.Logging;

internal class UntilContainerIsHealthy : IWaitUntil
{
Expand All @@ -14,7 +13,7 @@ public UntilContainerIsHealthy(long failingStreak)
this.failingStreak = failingStreak;
}

public Task<bool> Until(IContainer container, ILogger logger)
public Task<bool> UntilAsync(IContainer container)
{
if (TestcontainersStates.Exited.Equals(container.State))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,12 @@ namespace DotNet.Testcontainers.Configurations
{
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using Microsoft.Extensions.Logging;

internal class UntilContainerIsRunning : IWaitUntil
{
private const TestcontainersStates ContainerHasBeenRunningStates = TestcontainersStates.Running | TestcontainersStates.Exited;

public Task<bool> Until(IContainer container, ILogger logger)
public Task<bool> UntilAsync(IContainer container)
{
return Task.FromResult(ContainerHasBeenRunningStates.HasFlag(container.State));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace DotNet.Testcontainers.Configurations
using System.IO;
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using Microsoft.Extensions.Logging;

internal class UntilFilesExists : IWaitUntil
{
Expand All @@ -14,7 +13,7 @@ public UntilFilesExists(string file)
this.file = file;
}

public Task<bool> Until(IContainer container, ILogger logger)
public Task<bool> UntilAsync(IContainer container)
{
return Task.FromResult(File.Exists(this.file));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ namespace DotNet.Testcontainers.Configurations
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using Microsoft.Extensions.Logging;

internal class UntilMessageIsLogged : IWaitUntil
{
Expand All @@ -20,7 +19,7 @@ public UntilMessageIsLogged(Stream stream, string message)
this.message = message;
}

public async Task<bool> Until(IContainer container, ILogger logger)
public async Task<bool> UntilAsync(IContainer container)
{
this.stream.Seek(0, SeekOrigin.Begin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ namespace DotNet.Testcontainers.Configurations
using System;
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using Microsoft.Extensions.Logging;

internal class UntilOperationIsSucceeded : IWaitUntil
{
Expand All @@ -19,7 +18,7 @@ public UntilOperationIsSucceeded(Func<bool> operation, int maxCallCount)
this.maxCallCount = maxCallCount;
}

public Task<bool> Until(IContainer container, ILogger logger)
public Task<bool> UntilAsync(IContainer container)
{
if (++this.tryCount > this.maxCallCount)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ namespace DotNet.Testcontainers.Configurations
{
using System.Threading.Tasks;
using DotNet.Testcontainers.Containers;
using Microsoft.Extensions.Logging;

internal class UntilUnixCommandIsCompleted : IWaitUntil
{
Expand All @@ -18,7 +17,7 @@ public UntilUnixCommandIsCompleted(params string[] command)
this.command = command;
}

public virtual async Task<bool> Until(IContainer container, ILogger logger)
public virtual async Task<bool> UntilAsync(IContainer container)
{
var execResult = await container.ExecAsync(this.command)
.ConfigureAwait(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ internal static class WaitStrategy
/// <exception cref="TimeoutException">Thrown as soon as the timeout expires.</exception>
/// <returns>A task that represents the asynchronous block operation.</returns>
[PublicAPI]
public static async Task WaitWhile(Func<Task<bool>> wait, int frequency = 25, int timeout = -1, CancellationToken ct = default)
public static async Task WaitWhileAsync(Func<Task<bool>> wait, int frequency = 25, int timeout = -1, CancellationToken ct = default)
{
var waitTask = Task.Run(
async () =>
Expand Down Expand Up @@ -51,7 +51,7 @@ await Task.Delay(frequency, ct)
/// <exception cref="TimeoutException">Thrown as soon as the timeout expires.</exception>
/// <returns>A task that represents the asynchronous block operation.</returns>
[PublicAPI]
public static async Task WaitUntil(Func<Task<bool>> wait, int frequency = 25, int timeout = -1, CancellationToken ct = default)
public static async Task WaitUntilAsync(Func<Task<bool>> wait, int frequency = 25, int timeout = -1, CancellationToken ct = default)
{
var waitTask = Task.Run(
async () =>
Expand Down
Loading

0 comments on commit 478efc5

Please sign in to comment.