diff --git a/src/Testcontainers/Configurations/WaitStrategies/HttpWaitStrategy.cs b/src/Testcontainers/Configurations/WaitStrategies/HttpWaitStrategy.cs new file mode 100644 index 000000000..9153ae987 --- /dev/null +++ b/src/Testcontainers/Configurations/WaitStrategies/HttpWaitStrategy.cs @@ -0,0 +1,29 @@ +namespace DotNet.Testcontainers.Configurations +{ + using System; + using System.Threading.Tasks; + using DotNet.Testcontainers.Containers; + using Microsoft.Extensions.Logging; + + public sealed class HttpWaitStrategy : IWaitUntil + { + private readonly UriBuilder uriBuilder = new UriBuilder(Uri.UriSchemeHttp, "127.0.0.1"); + + public Task Until(ITestcontainersContainer testcontainers, ILogger logger) + { + return Task.FromResult(false); + } + + public HttpWaitStrategy ForPath(string path) + { + this.uriBuilder.Path = path; + return this; + } + + public HttpWaitStrategy UsingTls(bool tlsEnabled = true) + { + this.uriBuilder.Scheme = tlsEnabled ? Uri.UriSchemeHttps : Uri.UriSchemeHttp; + return this; + } + } +} diff --git a/src/Testcontainers/Configurations/WaitStrategies/IWaitForContainerOS.cs b/src/Testcontainers/Configurations/WaitStrategies/IWaitForContainerOS.cs index 8ed758b94..dbdc9996e 100644 --- a/src/Testcontainers/Configurations/WaitStrategies/IWaitForContainerOS.cs +++ b/src/Testcontainers/Configurations/WaitStrategies/IWaitForContainerOS.cs @@ -6,8 +6,7 @@ namespace DotNet.Testcontainers.Configurations using JetBrains.Annotations; /// - /// Collection of pre-configured strategies to wait until the Testcontainer is up and running. - /// Waits until all wait strategies are completed. + /// Collection of pre-configured strategies to wait until the container is up and running. /// [PublicAPI] public interface IWaitForContainerOS @@ -42,6 +41,14 @@ public interface IWaitForContainerOS [PublicAPI] IWaitForContainerOS UntilCommandIsCompleted(params string[] command); + /// + /// Waits until the port is available. + /// + /// The port to be checked. + /// A configured instance of . + [PublicAPI] + IWaitForContainerOS UntilPortIsAvailable(int port); + /// /// Waits until the file exists. /// @@ -70,12 +77,12 @@ public interface IWaitForContainerOS IWaitForContainerOS UntilOperationIsSucceeded(Func operation, int maxCallCount); /// - /// Waits until the port is available. + /// Waits until the http request is completed successfully. /// - /// The port to be checked. + /// The http request to be executed. /// A configured instance of . [PublicAPI] - IWaitForContainerOS UntilPortIsAvailable(int port); + IWaitForContainerOS UntilHttpRequestIsSucceeded(Func request); /// /// Waits until the container is healthy. diff --git a/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerOS.cs b/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerOS.cs index 9991c0eae..b7a9873d2 100644 --- a/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerOS.cs +++ b/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerOS.cs @@ -52,7 +52,13 @@ public virtual IWaitForContainerOS UntilOperationIsSucceeded(Func operatio } /// - public virtual IWaitForContainerOS UntilContainerIsHealthy(long failingStreak = 20) + public virtual IWaitForContainerOS UntilHttpRequestIsSucceeded(Func request) + { + return this.AddCustomWaitStrategy(request.Invoke(new HttpWaitStrategy())); + } + + /// + public virtual IWaitForContainerOS UntilContainerIsHealthy(long failingStreak = 3) { return this.AddCustomWaitStrategy(new UntilContainerIsHealthy(failingStreak)); } diff --git a/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerUnix.cs b/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerUnix.cs index 87444d6c5..01653e28e 100644 --- a/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerUnix.cs +++ b/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerUnix.cs @@ -6,22 +6,19 @@ internal sealed class WaitForContainerUnix : WaitForContainerOS /// public override IWaitForContainerOS UntilCommandIsCompleted(string command) { - this.AddCustomWaitStrategy(new UntilUnixCommandIsCompleted(command)); - return this; + return this.AddCustomWaitStrategy(new UntilUnixCommandIsCompleted(command)); } /// public override IWaitForContainerOS UntilCommandIsCompleted(params string[] command) { - this.AddCustomWaitStrategy(new UntilUnixCommandIsCompleted(command)); - return this; + return this.AddCustomWaitStrategy(new UntilUnixCommandIsCompleted(command)); } /// public override IWaitForContainerOS UntilPortIsAvailable(int port) { - this.AddCustomWaitStrategy(new UntilUnixPortIsAvailable(port)); - return this; + return this.AddCustomWaitStrategy(new UntilUnixPortIsAvailable(port)); } } } diff --git a/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerWindows.cs b/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerWindows.cs index 71014d990..a3a45cd77 100644 --- a/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerWindows.cs +++ b/src/Testcontainers/Configurations/WaitStrategies/WaitForContainerWindows.cs @@ -6,22 +6,19 @@ internal sealed class WaitForContainerWindows : WaitForContainerOS /// public override IWaitForContainerOS UntilCommandIsCompleted(string command) { - this.AddCustomWaitStrategy(new UntilWindowsCommandIsCompleted(command)); - return this; + return this.AddCustomWaitStrategy(new UntilWindowsCommandIsCompleted(command)); } /// public override IWaitForContainerOS UntilCommandIsCompleted(params string[] command) { - this.AddCustomWaitStrategy(new UntilWindowsCommandIsCompleted(command)); - return this; + return this.AddCustomWaitStrategy(new UntilWindowsCommandIsCompleted(command)); } /// public override IWaitForContainerOS UntilPortIsAvailable(int port) { - this.AddCustomWaitStrategy(new UntilWindowsPortIsAvailable(port)); - return this; + return this.AddCustomWaitStrategy(new UntilWindowsPortIsAvailable(port)); } } }