Skip to content

Commit 39c6453

Browse files
authored
Moved tests into separate directory (#200)
1 parent c234f10 commit 39c6453

15 files changed

+32
-29
lines changed

.github/workflows/tests.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515
- uses: actions/checkout@v3
1616
- name: run_tests
1717
run: >
18+
ls -la &&
19+
cd tests &&
1820
ls -la &&
1921
docker compose -f docker-compose-tests.yaml up --force-recreate --no-deps --wait -d &&
20-
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
22+
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

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -331,15 +331,16 @@ pip install -r requirements.txt
331331

332332
1. Use docker-compose to install all requirements:
333333
```bash
334-
sudo docker compose -f docker-compose-tests.yaml up
334+
cd tests/
335+
docker compose -f docker-compose-tests.yaml up
335336
```
336337
2. Run tests with:
337338
```bash
338-
sudo docker exec -w /app/ -it mysql_ch_replicator-replicator-1 python3 -m pytest -v -s test_mysql_ch_replicator.py
339+
docker exec -w /app/ -it tests-replicator-1 python3 -m pytest -v -s tests/test_mysql_ch_replicator.py
339340
```
340341
3. To run a single test:
341342
```bash
342-
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
343+
docker exec -w /app/ -it tests-replicator-1 python3 -m pytest -v -s tests/test_mysql_ch_replicator.py -k test_your_test_name
343344
```
344345

345346
## Contribution

docker-compose-tests.yaml renamed to tests/docker-compose-tests.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,11 @@ services:
5858

5959
replicator:
6060
build:
61-
context: .
61+
context: ..
6262
dockerfile: Dockerfile
6363
network_mode: host
6464
volumes:
65-
- ./:/app/
65+
- ../:/app/
6666
entrypoint: ["/bin/bash"]
6767
command: ["-c", "touch /tmp/ready && tail -f /dev/null"]
6868
healthcheck:
File renamed without changes.
File renamed without changes.

test_mysql_ch_replicator.py renamed to tests/test_mysql_ch_replicator.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
from mysql_ch_replicator.runner import ProcessRunner
2323

2424

25-
CONFIG_FILE = 'tests_config.yaml'
26-
CONFIG_FILE_MARIADB = 'tests_config_mariadb.yaml'
25+
CONFIG_FILE = 'tests/tests_config.yaml'
26+
CONFIG_FILE_MARIADB = 'tests/tests_config_mariadb.yaml'
2727
TEST_DB_NAME = 'replication-test_db'
2828
TEST_DB_NAME_2 = 'replication-test_db_2'
2929
TEST_DB_NAME_2_DESTINATION = 'replication-destination'
@@ -323,7 +323,7 @@ def get_db_replicator_pid(cfg: config.Settings, db_name: str):
323323
return state.pid
324324

325325

326-
@pytest.mark.parametrize('cfg_file', [CONFIG_FILE, 'tests_config_parallel.yaml'])
326+
@pytest.mark.parametrize('cfg_file', [CONFIG_FILE, 'tests/tests_config_parallel.yaml'])
327327
def test_runner(cfg_file):
328328
cfg = config.Settings()
329329
cfg.load(cfg_file)
@@ -587,7 +587,7 @@ def test_parallel_initial_replication_record_versions():
587587
after parallel initial replication.
588588
"""
589589
# Only run this test with parallel configuration
590-
cfg_file = 'tests_config_parallel.yaml'
590+
cfg_file = 'tests/tests_config_parallel.yaml'
591591
cfg = config.Settings()
592592
cfg.load(cfg_file)
593593

@@ -706,7 +706,7 @@ def test_parallel_initial_replication_record_versions():
706706

707707
def test_database_tables_filtering():
708708
cfg = config.Settings()
709-
cfg.load('tests_config_databases_tables.yaml')
709+
cfg.load('tests/tests_config_databases_tables.yaml')
710710

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

780-
run_all_runner = RunAllRunner(cfg_file='tests_config_databases_tables.yaml')
780+
run_all_runner = RunAllRunner(cfg_file='tests/tests_config_databases_tables.yaml')
781781
run_all_runner.run()
782782

783783
assert_wait(lambda: 'test_db_2' in ch.get_databases())
@@ -1180,7 +1180,7 @@ def test_json():
11801180

11811181
def test_string_primary_key(monkeypatch):
11821182
cfg = config.Settings()
1183-
cfg.load('tests_config_string_primary_key.yaml')
1183+
cfg.load('tests/tests_config_string_primary_key.yaml')
11841184

11851185
mysql = mysql_api.MySQLApi(
11861186
database=None,
@@ -1215,9 +1215,9 @@ def test_string_primary_key(monkeypatch):
12151215
commit=True,
12161216
)
12171217

1218-
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests_config_string_primary_key.yaml')
1218+
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests/tests_config_string_primary_key.yaml')
12191219
binlog_replicator_runner.run()
1220-
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests_config_string_primary_key.yaml')
1220+
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests/tests_config_string_primary_key.yaml')
12211221
db_replicator_runner.run()
12221222

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

12411241
def test_if_exists_if_not_exists(monkeypatch):
12421242
cfg = config.Settings()
1243-
cfg.load('tests_config_string_primary_key.yaml')
1243+
cfg.load('tests/tests_config_string_primary_key.yaml')
12441244

12451245
mysql = mysql_api.MySQLApi(
12461246
database=None,
@@ -1254,9 +1254,9 @@ def test_if_exists_if_not_exists(monkeypatch):
12541254

12551255
prepare_env(cfg, mysql, ch)
12561256

1257-
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests_config_string_primary_key.yaml')
1257+
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests/tests_config_string_primary_key.yaml')
12581258
binlog_replicator_runner.run()
1259-
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests_config_string_primary_key.yaml')
1259+
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests/tests_config_string_primary_key.yaml')
12601260
db_replicator_runner.run()
12611261

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

12801280
def test_percona_migration(monkeypatch):
12811281
cfg = config.Settings()
1282-
cfg.load('tests_config_string_primary_key.yaml')
1282+
cfg.load('tests/tests_config_string_primary_key.yaml')
12831283

12841284
mysql = mysql_api.MySQLApi(
12851285
database=None,
@@ -1304,9 +1304,9 @@ def test_percona_migration(monkeypatch):
13041304
commit=True,
13051305
)
13061306

1307-
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests_config_string_primary_key.yaml')
1307+
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests/tests_config_string_primary_key.yaml')
13081308
binlog_replicator_runner.run()
1309-
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests_config_string_primary_key.yaml')
1309+
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests/tests_config_string_primary_key.yaml')
13101310
db_replicator_runner.run()
13111311

13121312
assert_wait(lambda: TEST_DB_NAME in ch.get_databases())
@@ -1355,7 +1355,7 @@ def test_percona_migration(monkeypatch):
13551355

13561356
def test_add_column_first_after_and_drop_column(monkeypatch):
13571357
cfg = config.Settings()
1358-
cfg.load('tests_config_string_primary_key.yaml')
1358+
cfg.load('tests/tests_config_string_primary_key.yaml')
13591359

13601360
mysql = mysql_api.MySQLApi(
13611361
database=None,
@@ -1380,9 +1380,9 @@ def test_add_column_first_after_and_drop_column(monkeypatch):
13801380
commit=True,
13811381
)
13821382

1383-
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests_config_string_primary_key.yaml')
1383+
binlog_replicator_runner = BinlogReplicatorRunner(cfg_file='tests/tests_config_string_primary_key.yaml')
13841384
binlog_replicator_runner.run()
1385-
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests_config_string_primary_key.yaml')
1385+
db_replicator_runner = DbReplicatorRunner(TEST_DB_NAME, cfg_file='tests/tests_config_string_primary_key.yaml')
13861386
db_replicator_runner.run()
13871387

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

15071507
@pytest.mark.optional
15081508
def test_performance_realtime_replication():
1509-
config_file = 'tests_config_perf.yaml'
1509+
config_file = 'tests/tests_config_perf.yaml'
15101510
num_records = 100000
15111511

15121512
cfg = config.Settings()
@@ -2196,7 +2196,7 @@ def test_year_type():
21962196

21972197
@pytest.mark.optional
21982198
def test_performance_initial_only_replication():
2199-
config_file = 'tests_config_perf.yaml'
2199+
config_file = 'tests/tests_config_perf.yaml'
22002200
num_records = 300000
22012201

22022202
cfg = config.Settings()
@@ -2281,7 +2281,7 @@ def test_performance_initial_only_replication():
22812281
t1 = time.time()
22822282

22832283
# Create a custom config file for testing with parallel replication
2284-
parallel_config_file = 'tests_config_perf_parallel.yaml'
2284+
parallel_config_file = 'tests/tests_config_perf_parallel.yaml'
22852285
if os.path.exists(parallel_config_file):
22862286
os.remove(parallel_config_file)
22872287

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

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

24352435
cfg = config.Settings()
24362436
cfg.load(config_path)
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)