Documents
Database Test Container Configuration
Database Test Container Configuration
Type
Document
Status
Published
Created
Oct 31, 2025
Updated
Oct 31, 2025
Updated by
Dosu Bot

The gold_digger project transitioned from MySQL to MariaDB testcontainers for integration tests to improve container readiness and reliability. The MariaDB testcontainer module provides built-in ready conditions, specifically waiting for mariadbd: ready for connections. and port: 3306 on stderr, which results in more reliable container startup and reduces flaky tests. This change ensures that integration tests consistently wait for the database to be fully available before executing, leading to fewer intermittent failures and smoother CI runs PR #96.

Configuring MariaDB Testcontainers#

To use MariaDB containers in integration tests, update your Cargo.toml to enable the mariadb feature instead of mysql:

[dependencies]
testcontainers-modules = { version = "x.y", features = ["mariadb"] }

In your test code, replace any usage of Mysql::default() with Mariadb::default(). For example:

use testcontainers_modules::mariadb::Mariadb;

// Start a MariaDB container for testing
let container = Mariadb::default()
    .with_env_var("MARIADB_ALLOW_EMPTY_ROOT_PASSWORD", "yes")
    .with_env_var("MARIADB_ROOT_HOST", "%")
    .start()?;

// Get the mapped host port
let host_port = container.get_host_port_ipv4(3306)?;

// Construct the connection URL
let connection_url = format!("mysql://root@127.0.0.1:{}/mysql", host_port);

The integration test framework in gold_digger abstracts container management, so you typically create a MariaDB container using a helper such as:

let db = TestDatabase::MariaDB { tls_enabled: false };
let container = DatabaseContainer::new(db)?;

Updating Test Code#

To migrate existing tests from MySQL to MariaDB containers:

  1. Change feature flags in Cargo.toml from mysql to mariadb.
  2. Replace Mysql::default() with Mariadb::default() in test setup code.
  3. Update any references to MySQL-specific environment variables to their MariaDB equivalents (e.g., MYSQL_ALLOW_EMPTY_PASSWORDMARIADB_ALLOW_EMPTY_ROOT_PASSWORD).
  4. Ensure connection URLs use the correct port and credentials, typically mysql://root@127.0.0.1:<port>/mysql.

All test files in gold_digger were updated to use Mariadb::default() and the new configuration, and all tests pass successfully with the MariaDB setup PR #96.

Reliability and Ready Conditions#

MariaDB testcontainers improve reliability by implementing robust ready conditions. The container startup waits for explicit signals that the database is ready to accept connections, reducing the likelihood of tests failing due to premature connection attempts. The framework also includes adaptive retry logic and health checks, further increasing test stability in both local and CI environments integration-testing.md.

Example: Running Integration Tests#

To run integration tests with MariaDB containers:

cargo test --features integration_tests

Or, to run specific test categories:

cargo test --features integration_tests --test tls_variants_test
cargo test --features integration_tests --test integration_tests

Compatibility Notes#

MariaDB is a drop-in replacement for MySQL in most testing scenarios. The gold_digger framework includes compatibility handling for minor differences in SQL syntax and feature support between MySQL and MariaDB. The container management utilities automatically detect the database type and version, applying compatibility adjustments as needed during schema creation and data seeding containers.rs.

For advanced scenarios, such as TLS-enabled containers or custom certificate management, refer to the integration testing documentation and code examples for further configuration options tls-variants.md.

References#