From 29ee7505ec685a64581b9ea2f2c45ceda58d0b9b Mon Sep 17 00:00:00 2001 From: Andre Hofmeister <9199345+HofmeisterAn@users.noreply.github.com> Date: Wed, 8 Feb 2023 08:38:48 +0100 Subject: [PATCH] fix: Add MySql default port to readiness check --- src/Testcontainers.MySql/MySqlBuilder.cs | 11 +++++------ src/Testcontainers.MySql/MySqlContainer.cs | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Testcontainers.MySql/MySqlBuilder.cs b/src/Testcontainers.MySql/MySqlBuilder.cs index 73fbbe4d1..896dbff24 100644 --- a/src/Testcontainers.MySql/MySqlBuilder.cs +++ b/src/Testcontainers.MySql/MySqlBuilder.cs @@ -75,9 +75,9 @@ public override MySqlContainer Build() { Validate(); - // By default, the base builder waits until the container is running. However, for MySql, a more advanced waiting strategy is necessary that requires access to the configured username and password. + // By default, the base builder waits until the container is running. However, for MySql, a more advanced waiting strategy is necessary that requires access to the configured database, username and password. // If the user does not provide a custom waiting strategy, append the default MySql waiting strategy. - var mySqlBuilder = DockerResourceConfiguration.WaitStrategies.Count().Equals(1) ? WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil(DockerResourceConfiguration.Username, DockerResourceConfiguration.Password))) : this; + var mySqlBuilder = DockerResourceConfiguration.WaitStrategies.Count() > 1 ? this : WithWaitStrategy(Wait.ForUnixContainer().AddCustomWaitStrategy(new WaitUntil(DockerResourceConfiguration))); return new MySqlContainer(mySqlBuilder.DockerResourceConfiguration, TestcontainersSettings.Logger); } @@ -132,11 +132,10 @@ private sealed class WaitUntil : IWaitUntil /// /// Initializes a new instance of the class. /// - /// The MySql username. - /// The MySql password. - public WaitUntil(string username, string password) + /// The container configuration. + public WaitUntil(MySqlConfiguration configuration) { - _command = new List { "mysql", $"--user={username}", $"--password={password}", "--execute=SELECT 1;" }; + _command = new List { "mysql", $"--port={MySqlPort}", $"--user={configuration.Username}", $"--password={configuration.Password}", configuration.Database, "--execute=SELECT 1;" }; } /// diff --git a/src/Testcontainers.MySql/MySqlContainer.cs b/src/Testcontainers.MySql/MySqlContainer.cs index a8e2faede..b57f10ca6 100644 --- a/src/Testcontainers.MySql/MySqlContainer.cs +++ b/src/Testcontainers.MySql/MySqlContainer.cs @@ -45,7 +45,7 @@ public async Task ExecScriptAsync(string scriptContent, Cancellation await CopyFileAsync(scriptFilePath, Encoding.Default.GetBytes(scriptContent), 493, 0, 0, ct) .ConfigureAwait(false); - return await ExecAsync(new[] { "mysql", $"--user={_configuration.Username}", $"--password={_configuration.Password}", _configuration.Database, $"--execute=source {scriptFilePath}" }, ct) + return await ExecAsync(new[] { "mysql", $"--port={MySqlBuilder.MySqlPort}", $"--user={_configuration.Username}", $"--password={_configuration.Password}", _configuration.Database, $"--execute=source {scriptFilePath}" }, ct) .ConfigureAwait(false); } } \ No newline at end of file