Skip to content

Commit

Permalink
fix: Add MySql default port to readiness check
Browse files Browse the repository at this point in the history
  • Loading branch information
HofmeisterAn committed Feb 8, 2023
1 parent 83361f9 commit 29ee750
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions src/Testcontainers.MySql/MySqlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -132,11 +132,10 @@ private sealed class WaitUntil : IWaitUntil
/// <summary>
/// Initializes a new instance of the <see cref="WaitUntil" /> class.
/// </summary>
/// <param name="username">The MySql username.</param>
/// <param name="password">The MySql password.</param>
public WaitUntil(string username, string password)
/// <param name="configuration">The container configuration.</param>
public WaitUntil(MySqlConfiguration configuration)
{
_command = new List<string> { "mysql", $"--user={username}", $"--password={password}", "--execute=SELECT 1;" };
_command = new List<string> { "mysql", $"--port={MySqlPort}", $"--user={configuration.Username}", $"--password={configuration.Password}", configuration.Database, "--execute=SELECT 1;" };
}

/// <inheritdoc />
Expand Down
2 changes: 1 addition & 1 deletion src/Testcontainers.MySql/MySqlContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public async Task<ExecResult> 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);
}
}

0 comments on commit 29ee750

Please sign in to comment.