diff --git a/src/Testcontainers.Db2/Db2Container.cs b/src/Testcontainers.Db2/Db2Container.cs index a52dd5642..660a388d1 100644 --- a/src/Testcontainers.Db2/Db2Container.cs +++ b/src/Testcontainers.Db2/Db2Container.cs @@ -42,7 +42,7 @@ public async Task ExecScriptAsync(string scriptContent, Cancellation await CopyAsync(Encoding.Default.GetBytes(scriptContent), scriptFilePath, Unix.FileMode644, ct) .ConfigureAwait(false); - return await ExecAsync(new [] { "/bin/sh", "-c", db2ShellCommand}, ct) + return await ExecAsync(new[] { "/bin/sh", "-c", db2ShellCommand}, ct) .ConfigureAwait(false); } } \ No newline at end of file diff --git a/src/Testcontainers.EventHubs/EventHubsBuilder.cs b/src/Testcontainers.EventHubs/EventHubsBuilder.cs index 3e8fb7476..87b207531 100644 --- a/src/Testcontainers.EventHubs/EventHubsBuilder.cs +++ b/src/Testcontainers.EventHubs/EventHubsBuilder.cs @@ -12,6 +12,8 @@ public sealed class EventHubsBuilder : ContainerBuilder /// Initializes a new instance of the class. /// @@ -135,9 +137,9 @@ protected override EventHubsBuilder Init() return base.Init() .WithImage(EventHubsImage) .WithPortBinding(EventHubsPort, true) - .WithWaitStrategy(Wait.ForUnixContainer() - .UntilMessageIsLogged("Emulator Service is Successfully Up!") - .AddCustomWaitStrategy(new WaitTwoSeconds())); + .WithPortBinding(EventHubsHttpPort, true) + .WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => + request.ForPort(EventHubsHttpPort).ForPath("/health"))); } /// @@ -157,22 +159,4 @@ protected override EventHubsBuilder Merge(EventHubsConfiguration oldValue, Event { return new EventHubsBuilder(new EventHubsConfiguration(oldValue, newValue)); } - - /// - /// - /// This is a workaround to ensure that the wait strategy does not indicate - /// readiness too early: - /// https://github.com/Azure/azure-service-bus-emulator-installer/issues/35#issuecomment-2497164533. - /// - private sealed class WaitTwoSeconds : IWaitUntil - { - /// - public async Task UntilAsync(IContainer container) - { - await Task.Delay(TimeSpan.FromSeconds(2)) - .ConfigureAwait(false); - - return true; - } - } } \ No newline at end of file diff --git a/src/Testcontainers.ServiceBus/ServiceBusBuilder.cs b/src/Testcontainers.ServiceBus/ServiceBusBuilder.cs index 2d6b0b930..1069802d3 100644 --- a/src/Testcontainers.ServiceBus/ServiceBusBuilder.cs +++ b/src/Testcontainers.ServiceBus/ServiceBusBuilder.cs @@ -12,6 +12,8 @@ public sealed class ServiceBusBuilder : ContainerBuilder /// Initializes a new instance of the class. /// @@ -115,9 +117,10 @@ protected override ServiceBusBuilder Init() return base.Init() .WithImage(ServiceBusImage) .WithPortBinding(ServiceBusPort, true) - .WithWaitStrategy(Wait.ForUnixContainer() - .UntilMessageIsLogged("Emulator Service is Successfully Up!") - .AddCustomWaitStrategy(new WaitTwoSeconds())); + .WithPortBinding(ServiceBusHttpPort, true) + .WithEnvironment("SQL_WAIT_INTERVAL", "0") + .WithWaitStrategy(Wait.ForUnixContainer().UntilHttpRequestIsSucceeded(request => + request.ForPort(ServiceBusHttpPort).ForPath("/health"))); } /// @@ -137,22 +140,4 @@ protected override ServiceBusBuilder Merge(ServiceBusConfiguration oldValue, Ser { return new ServiceBusBuilder(new ServiceBusConfiguration(oldValue, newValue)); } - - /// - /// - /// This is a workaround to ensure that the wait strategy does not indicate - /// readiness too early: - /// https://github.com/Azure/azure-service-bus-emulator-installer/issues/35#issuecomment-2497164533. - /// - private sealed class WaitTwoSeconds : IWaitUntil - { - /// - public async Task UntilAsync(IContainer container) - { - await Task.Delay(TimeSpan.FromSeconds(2)) - .ConfigureAwait(false); - - return true; - } - } } \ No newline at end of file diff --git a/src/Testcontainers/Containers/DockerContainer.cs b/src/Testcontainers/Containers/DockerContainer.cs index b1ea3907c..c916f12ec 100644 --- a/src/Testcontainers/Containers/DockerContainer.cs +++ b/src/Testcontainers/Containers/DockerContainer.cs @@ -505,7 +505,7 @@ await _client.AttachAsync(_container.ID, _configuration.OutputConsumer, ct) await _client.StartAsync(_container.ID, ct) .ConfigureAwait(false); - _ = await CheckReadinessAsync(new [] { portBindingsMapped }, ct) + _ = await CheckReadinessAsync(new[] { portBindingsMapped }, ct) .ConfigureAwait(false); Starting?.Invoke(this, EventArgs.Empty); diff --git a/src/Testcontainers/Images/DockerfileArchive.cs b/src/Testcontainers/Images/DockerfileArchive.cs index 884a1ff7b..500d49bcb 100644 --- a/src/Testcontainers/Images/DockerfileArchive.cs +++ b/src/Testcontainers/Images/DockerfileArchive.cs @@ -4,7 +4,6 @@ namespace DotNet.Testcontainers.Images using System.Collections.Generic; using System.IO; using System.Linq; - using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; using System.Threading; @@ -150,7 +149,7 @@ public async Task Tar(CancellationToken ct = default) { var entry = TarEntry.CreateTarEntry(relativeFilePath); entry.TarHeader.Size = inputStream.Length; - entry.TarHeader.Mode = GetFileMode(absoluteFilePath); + entry.TarHeader.Mode = GetUnixFileMode(absoluteFilePath); await tarOutputStream.PutNextEntryAsync(entry, ct) .ConfigureAwait(false); @@ -188,21 +187,22 @@ private static IEnumerable GetFiles(string directory) } /// - /// Gets the file mode for a given file. + /// Gets the Unix file mode of the file on the path. /// - /// The path to the file. - /// The file mode for the - private static int GetFileMode(string path) + /// The path to the file. + /// The Unix file mode of the file on the path. + private static int GetUnixFileMode(string filePath) { #if NET7_0_OR_GREATER - if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + if (!OperatingSystem.IsWindows()) { - return (int)File.GetUnixFileMode(path); + return (int)File.GetUnixFileMode(filePath); } #endif - // Default to 755 for Windows and fallback to 755 for Unix when - // `GetUnixFileMode` is not available. + // Default to 755 for Windows and fall back to 755 for Unix when `GetUnixFileMode` + // is not available. + _ = filePath; return (int)Unix.FileMode755; } }