Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ jobs:
- uses: actions/checkout@v3
- name: run_tests
run: >
ls -la &&
cd tests &&
ls -la &&
docker compose -f docker-compose-tests.yaml up --force-recreate --no-deps --wait -d &&
sudo docker exec -w /app/ -i `docker ps | grep mysql_ch_replicator-replicator | awk '{print $1;}'` python3 -m pytest -x -v -s test_mysql_ch_replicator.py
sudo docker exec -w /app/ -i `docker ps | grep tests-replicator | awk '{print $1;}'` python3 -m pytest -x -v -s tests/test_mysql_ch_replicator.py
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -331,15 +331,16 @@ pip install -r requirements.txt

1. Use docker-compose to install all requirements:
```bash
sudo docker compose -f docker-compose-tests.yaml up
cd tests/
docker compose -f docker-compose-tests.yaml up
```
2. Run tests with:
```bash
sudo docker exec -w /app/ -it mysql_ch_replicator-replicator-1 python3 -m pytest -v -s test_mysql_ch_replicator.py
docker exec -w /app/ -it tests-replicator-1 python3 -m pytest -v -s tests/test_mysql_ch_replicator.py
```
3. To run a single test:
```bash
sudo docker exec -w /app/ -it mysql_ch_replicator-replicator-1 python3 -m pytest -v -s test_mysql_ch_replicator.py -k test_your_test_name
docker exec -w /app/ -it tests-replicator-1 python3 -m pytest -v -s tests/test_mysql_ch_replicator.py -k test_your_test_name
```

## Contribution
Expand Down
4 changes: 2 additions & 2 deletions docker-compose-tests.yaml → tests/docker-compose-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,11 @@ services:

replicator:
build:
context: .
context: ..
dockerfile: Dockerfile
network_mode: host
volumes:
- ./:/app/
- ../:/app/
entrypoint: ["/bin/bash"]
command: ["-c", "touch /tmp/ready && tail -f /dev/null"]
healthcheck:
Expand Down
File renamed without changes.
File renamed without changes.
46 changes: 23 additions & 23 deletions test_mysql_ch_replicator.py → tests/test_mysql_ch_replicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@
from mysql_ch_replicator.runner import ProcessRunner


CONFIG_FILE = 'tests_config.yaml'
CONFIG_FILE_MARIADB = 'tests_config_mariadb.yaml'
CONFIG_FILE = 'tests/tests_config.yaml'
CONFIG_FILE_MARIADB = 'tests/tests_config_mariadb.yaml'
TEST_DB_NAME = 'replication-test_db'
TEST_DB_NAME_2 = 'replication-test_db_2'
TEST_DB_NAME_2_DESTINATION = 'replication-destination'
Expand Down Expand Up @@ -323,7 +323,7 @@ def get_db_replicator_pid(cfg: config.Settings, db_name: str):
return state.pid


@pytest.mark.parametrize('cfg_file', [CONFIG_FILE, 'tests_config_parallel.yaml'])
@pytest.mark.parametrize('cfg_file', [CONFIG_FILE, 'tests/tests_config_parallel.yaml'])
def test_runner(cfg_file):
cfg = config.Settings()
cfg.load(cfg_file)
Expand Down Expand Up @@ -587,7 +587,7 @@ def test_parallel_initial_replication_record_versions():
after parallel initial replication.
"""
# Only run this test with parallel configuration
cfg_file = 'tests_config_parallel.yaml'
cfg_file = 'tests/tests_config_parallel.yaml'
cfg = config.Settings()
cfg.load(cfg_file)

Expand Down Expand Up @@ -706,7 +706,7 @@ def test_parallel_initial_replication_record_versions():

def test_database_tables_filtering():
cfg = config.Settings()
cfg.load('tests_config_databases_tables.yaml')
cfg.load('tests/tests_config_databases_tables.yaml')

mysql = mysql_api.MySQLApi(
database=None,
Expand Down Expand Up @@ -777,7 +777,7 @@ def test_database_tables_filtering():
mysql.execute(f"INSERT INTO test_table_3 (name, age) VALUES ('Ivan', 42);", commit=True)
mysql.execute(f"INSERT INTO test_table_2 (name, age) VALUES ('Ivan', 42);", commit=True)

run_all_runner = RunAllRunner(cfg_file='tests_config_databases_tables.yaml')
run_all_runner = RunAllRunner(cfg_file='tests/tests_config_databases_tables.yaml')
run_all_runner.run()

assert_wait(lambda: 'test_db_2' in ch.get_databases())
Expand Down Expand Up @@ -1180,7 +1180,7 @@ def test_json():

def test_string_primary_key(monkeypatch):
cfg = config.Settings()
cfg.load('tests_config_string_primary_key.yaml')
cfg.load('tests/tests_config_string_primary_key.yaml')

mysql = mysql_api.MySQLApi(
database=None,
Expand Down Expand Up @@ -1215,9 +1215,9 @@ def test_string_primary_key(monkeypatch):
commit=True,
)

binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests_config_string_primary_key.yaml')
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests/tests_config_string_primary_key.yaml')
binlog_replicator_runner.run()
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests_config_string_primary_key.yaml')
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests/tests_config_string_primary_key.yaml')
db_replicator_runner.run()

assert_wait(lambda: TEST_DB_NAME in ch.get_databases())
Expand All @@ -1240,7 +1240,7 @@ def test_string_primary_key(monkeypatch):

def test_if_exists_if_not_exists(monkeypatch):
cfg = config.Settings()
cfg.load('tests_config_string_primary_key.yaml')
cfg.load('tests/tests_config_string_primary_key.yaml')

mysql = mysql_api.MySQLApi(
database=None,
Expand All @@ -1254,9 +1254,9 @@ def test_if_exists_if_not_exists(monkeypatch):

prepare_env(cfg, mysql, ch)

binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests_config_string_primary_key.yaml')
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests/tests_config_string_primary_key.yaml')
binlog_replicator_runner.run()
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests_config_string_primary_key.yaml')
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests/tests_config_string_primary_key.yaml')
db_replicator_runner.run()

assert_wait(lambda: TEST_DB_NAME in ch.get_databases())
Expand All @@ -1279,7 +1279,7 @@ def test_if_exists_if_not_exists(monkeypatch):

def test_percona_migration(monkeypatch):
cfg = config.Settings()
cfg.load('tests_config_string_primary_key.yaml')
cfg.load('tests/tests_config_string_primary_key.yaml')

mysql = mysql_api.MySQLApi(
database=None,
Expand All @@ -1304,9 +1304,9 @@ def test_percona_migration(monkeypatch):
commit=True,
)

binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests_config_string_primary_key.yaml')
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests/tests_config_string_primary_key.yaml')
binlog_replicator_runner.run()
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests_config_string_primary_key.yaml')
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests/tests_config_string_primary_key.yaml')
db_replicator_runner.run()

assert_wait(lambda: TEST_DB_NAME in ch.get_databases())
Expand Down Expand Up @@ -1355,7 +1355,7 @@ def test_percona_migration(monkeypatch):

def test_add_column_first_after_and_drop_column(monkeypatch):
cfg = config.Settings()
cfg.load('tests_config_string_primary_key.yaml')
cfg.load('tests/tests_config_string_primary_key.yaml')

mysql = mysql_api.MySQLApi(
database=None,
Expand All @@ -1380,9 +1380,9 @@ def test_add_column_first_after_and_drop_column(monkeypatch):
commit=True,
)

binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests_config_string_primary_key.yaml')
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests/tests_config_string_primary_key.yaml')
binlog_replicator_runner.run()
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests_config_string_primary_key.yaml')
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests/tests_config_string_primary_key.yaml')
db_replicator_runner.run()

assert_wait(lambda: TEST_DB_NAME in ch.get_databases())
Expand Down Expand Up @@ -1506,7 +1506,7 @@ def get_last_insert_from_binlog(cfg: config.Settings, db_name: str):

@pytest.mark.optional
def test_performance_realtime_replication():
config_file = 'tests_config_perf.yaml'
config_file = 'tests/tests_config_perf.yaml'
num_records = 100000

cfg = config.Settings()
Expand Down Expand Up @@ -2196,7 +2196,7 @@ def test_year_type():

@pytest.mark.optional
def test_performance_initial_only_replication():
config_file = 'tests_config_perf.yaml'
config_file = 'tests/tests_config_perf.yaml'
num_records = 300000

cfg = config.Settings()
Expand Down Expand Up @@ -2281,7 +2281,7 @@ def test_performance_initial_only_replication():
t1 = time.time()

# Create a custom config file for testing with parallel replication
parallel_config_file = 'tests_config_perf_parallel.yaml'
parallel_config_file = 'tests/tests_config_perf_parallel.yaml'
if os.path.exists(parallel_config_file):
os.remove(parallel_config_file)

Expand Down Expand Up @@ -2329,7 +2329,7 @@ def test_performance_initial_only_replication():
def test_schema_evolution_with_db_mapping():
"""Test case to reproduce issue where schema evolution doesn't work with database mapping."""
# Use the predefined config file with database mapping
config_file = "tests_config_db_mapping.yaml"
config_file = "tests/tests_config_db_mapping.yaml"

cfg = config.Settings()
cfg.load(config_file)
Expand Down Expand Up @@ -2430,7 +2430,7 @@ def test_dynamic_column_addition_user_config():
This test reproduces the issue where columns are added on-the-fly via UPDATE
rather than through ALTER TABLE statements, leading to an index error in the converter.
"""
config_path = 'tests_config_dynamic_column.yaml'
config_path = 'tests/tests_config_dynamic_column.yaml'

cfg = config.Settings()
cfg.load(config_path)
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.