From 21787cf1cd022587058c5c8af8157fa9282ad538 Mon Sep 17 00:00:00 2001 From: heehehe Date: Sat, 23 Sep 2023 15:36:56 +0900 Subject: [PATCH 01/11] feat: add config.yml to set dbms --- pymysqlreplication/tests/config.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 pymysqlreplication/tests/config.yml diff --git a/pymysqlreplication/tests/config.yml b/pymysqlreplication/tests/config.yml new file mode 100644 index 00000000..e9af3b35 --- /dev/null +++ b/pymysqlreplication/tests/config.yml @@ -0,0 +1,24 @@ +mysql-5: + host: "localhost" + user: "root" + passwd: "" + port: 3306 + use_unicode: True + charset: "utf8" + db: "pymysqlreplication_test" +mariadb-10: + host: "localhost" + user: "root" + passwd: "" + port: 3308 + use_unicode: True + charset: "utf8" + db: "pymysqlreplication_test" +mysql-8: + host: "localhost" + user: "root" + passwd: "" + port: 3309 + use_unicode: True + charset: "utf8" + db: "pymysqlreplication_test" From 7c17af18b9c5e7ce3330d6c60cf80dbadb04a654 Mon Sep 17 00:00:00 2001 From: heehehe Date: Sat, 23 Sep 2023 15:56:02 +0900 Subject: [PATCH 02/11] feat: change config yml to json --- pymysqlreplication/tests/config.json | 29 ++++++++++++++++++++++++++++ pymysqlreplication/tests/config.yml | 24 ----------------------- 2 files changed, 29 insertions(+), 24 deletions(-) create mode 100644 pymysqlreplication/tests/config.json delete mode 100644 pymysqlreplication/tests/config.yml diff --git a/pymysqlreplication/tests/config.json b/pymysqlreplication/tests/config.json new file mode 100644 index 00000000..358a7538 --- /dev/null +++ b/pymysqlreplication/tests/config.json @@ -0,0 +1,29 @@ +{ + "mysql-5": { + "host": "localhost", + "user": "root", + "passwd": "", + "port": 3306, + "use_unicode": true, + "charset": "utf8", + "db": "pymysqlreplication_test" + }, + "mariadb-10": { + "host": "localhost", + "user": "root", + "passwd": "", + "port": 3308, + "use_unicode": true, + "charset": "utf8", + "db": "pymysqlreplication_test" + }, + "mysql-8": { + "host": "localhost", + "user": "root", + "passwd": "", + "port": 3308, + "use_unicode": true, + "charset": "utf8", + "db": "pymysqlreplication_test" + } +} diff --git a/pymysqlreplication/tests/config.yml b/pymysqlreplication/tests/config.yml deleted file mode 100644 index e9af3b35..00000000 --- a/pymysqlreplication/tests/config.yml +++ /dev/null @@ -1,24 +0,0 @@ -mysql-5: - host: "localhost" - user: "root" - passwd: "" - port: 3306 - use_unicode: True - charset: "utf8" - db: "pymysqlreplication_test" -mariadb-10: - host: "localhost" - user: "root" - passwd: "" - port: 3308 - use_unicode: True - charset: "utf8" - db: "pymysqlreplication_test" -mysql-8: - host: "localhost" - user: "root" - passwd: "" - port: 3309 - use_unicode: True - charset: "utf8" - db: "pymysqlreplication_test" From b80fa343ef0a773430913b877b91ca4bf2855678 Mon Sep 17 00:00:00 2001 From: mikaniz Date: Sat, 23 Sep 2023 16:55:12 +0900 Subject: [PATCH 03/11] feat: add pytest dbms argument --- .github/workflows/pytest.yml | 2 +- pymysqlreplication/tests/config.json | 2 +- pymysqlreplication/tests/conftest.py | 10 ++++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 pymysqlreplication/tests/conftest.py diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 33b8f63c..31fb07af 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -47,4 +47,4 @@ jobs: - name: Run test suite run: | - pytest -k "not test_no_trailing_rotate_event and not test_end_log_pos" + pytest -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" diff --git a/pymysqlreplication/tests/config.json b/pymysqlreplication/tests/config.json index 358a7538..fd51d29c 100644 --- a/pymysqlreplication/tests/config.json +++ b/pymysqlreplication/tests/config.json @@ -21,7 +21,7 @@ "host": "localhost", "user": "root", "passwd": "", - "port": 3308, + "port": 3309, "use_unicode": true, "charset": "utf8", "db": "pymysqlreplication_test" diff --git a/pymysqlreplication/tests/conftest.py b/pymysqlreplication/tests/conftest.py new file mode 100644 index 00000000..fb3a2a72 --- /dev/null +++ b/pymysqlreplication/tests/conftest.py @@ -0,0 +1,10 @@ +import pytest + + +def pytest_addoption(parser): + parser.addoption("--dbms", action="store", default="mysql-5") + + +@pytest.fixture +def get_dbms(request): + return request.config.getoption("--dbms") From ec268ff4a8c13d36525a715dcced6f1c7181eb5b Mon Sep 17 00:00:00 2001 From: mikaniz Date: Sat, 30 Sep 2023 01:39:39 +0900 Subject: [PATCH 04/11] test: remove TestCase class for mariadb and mysql8 --- pymysqlreplication/tests/base.py | 59 ---------------------- pymysqlreplication/tests/test_basic.py | 6 +-- pymysqlreplication/tests/test_data_type.py | 2 +- 3 files changed, 4 insertions(+), 63 deletions(-) diff --git a/pymysqlreplication/tests/base.py b/pymysqlreplication/tests/base.py index ac842011..dce6b27f 100644 --- a/pymysqlreplication/tests/base.py +++ b/pymysqlreplication/tests/base.py @@ -122,62 +122,3 @@ def bin_log_basename(self): bin_log_basename = cursor.fetchone()[0] bin_log_basename = bin_log_basename.split("/")[-1] return bin_log_basename - - -class PyMySQLReplicationMariaDbTestCase(PyMySQLReplicationTestCase): - def setUp(self): - # default - self.database = { - "host": os.environ.get("MARIADB_10_6") or "localhost", - "user": "root", - "passwd": "", - "port": int(os.environ.get("MARIADB_10_6_PORT") or 3308), - "use_unicode": True, - "charset": "utf8", - "db": "pymysqlreplication_test", - } - - self.conn_control = None - db = copy.copy(self.database) - db["db"] = None - self.connect_conn_control(db) - self.execute("DROP DATABASE IF EXISTS pymysqlreplication_test") - self.execute("CREATE DATABASE pymysqlreplication_test") - db = copy.copy(self.database) - self.connect_conn_control(db) - self.stream = None - self.resetBinLog() - - def bin_log_basename(self): - cursor = self.execute("SELECT @@log_bin_basename") - bin_log_basename = cursor.fetchone()[0] - bin_log_basename = bin_log_basename.split("/")[-1] - return bin_log_basename - - -class PyMySQLReplicationVersion8TestCase(PyMySQLReplicationTestCase): - def setUp(self): - super().setUp() - # default - self.database = { - "host": os.environ.get("MYSQL_8_0") or "localhost", - "user": "root", - "passwd": "", - "port": int(os.environ.get("MYSQL_8_0_PORT") or 3309), - "use_unicode": True, - "charset": "utf8", - "db": "pymysqlreplication_test", - } - - self.conn_control = None - db = copy.copy(self.database) - db["db"] = None - self.connect_conn_control(db) - self.execute("DROP DATABASE IF EXISTS pymysqlreplication_test") - self.execute("CREATE DATABASE pymysqlreplication_test") - db = copy.copy(self.database) - self.connect_conn_control(db) - self.stream = None - self.resetBinLog() - self.isMySQL80AndMore() - self.__is_mariaDB = None diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index f38d4be7..eec3a9ca 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1322,7 +1322,7 @@ def tearDown(self): super(TestStatementConnectionSetting, self).tearDown() -class TestMariadbBinlogStreamReader(base.PyMySQLReplicationMariaDbTestCase): +class TestMariadbBinlogStreamReader(base.PyMySQLReplicationTestCase): def test_binlog_checkpoint_event(self): self.stream.close() self.stream = BinLogStreamReader( @@ -1353,7 +1353,7 @@ def test_binlog_checkpoint_event(self): self.assertEqual(event.filename, self.bin_log_basename() + ".000001") -class TestMariadbBinlogStreamReader2(base.PyMySQLReplicationMariaDbTestCase): +class TestMariadbBinlogStreamReader2(base.PyMySQLReplicationTestCase): def test_annotate_rows_event(self): query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))" self.execute(query) @@ -1498,7 +1498,7 @@ def test_query_event_latin1(self): assert event.query == r"CREATE TABLE test_latin1_\xd6\xc6\xdb (a INT)" -class TestOptionalMetaData(base.PyMySQLReplicationVersion8TestCase): +class TestOptionalMetaData(base.PyMySQLReplicationTestCase): def setUp(self): super(TestOptionalMetaData, self).setUp() self.stream.close() diff --git a/pymysqlreplication/tests/test_data_type.py b/pymysqlreplication/tests/test_data_type.py index 6a18aca2..e4ddd659 100644 --- a/pymysqlreplication/tests/test_data_type.py +++ b/pymysqlreplication/tests/test_data_type.py @@ -943,7 +943,7 @@ def test_varbinary(self): self.assertEqual(event.rows[0]["values"]["b"], b"\xff\x01\x00\x00") -class TestDataTypeVersion8(base.PyMySQLReplicationVersion8TestCase): +class TestDataTypeVersion8(base.PyMySQLReplicationTestCase): def ignoredEvents(self): return [GtidEvent, PreviousGtidsEvent] From f4d300ad5208476aae3388960c0f5dbcb0180f1e Mon Sep 17 00:00:00 2001 From: mikaniz Date: Sun, 1 Oct 2023 02:31:55 +0900 Subject: [PATCH 05/11] test: fix to check whether it is mariadb or not --- pymysqlreplication/tests/test_basic.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index eec3a9ca..bae970e0 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1324,6 +1324,8 @@ def tearDown(self): class TestMariadbBinlogStreamReader(base.PyMySQLReplicationTestCase): def test_binlog_checkpoint_event(self): + if not self.isMariaDB(): + self.skipTest("Database is not mariadb") self.stream.close() self.stream = BinLogStreamReader( self.database, server_id=1023, blocking=False, is_mariadb=True @@ -1355,6 +1357,8 @@ def test_binlog_checkpoint_event(self): class TestMariadbBinlogStreamReader2(base.PyMySQLReplicationTestCase): def test_annotate_rows_event(self): + if not self.isMariaDB(): + self.skipTest("Database is not mariadb") query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))" self.execute(query) # Insert first event @@ -1383,6 +1387,8 @@ def test_annotate_rows_event(self): self.assertIsInstance(event, MariadbAnnotateRowsEvent) def test_start_encryption_event(self): + if not self.isMariaDB(): + self.skipTest("Database is not mariadb") query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))" self.execute(query) query = "INSERT INTO test (data) VALUES('Hello World')" @@ -1421,6 +1427,8 @@ def test_start_encryption_event(self): self.assertEqual(len(nonce), 12) def test_gtid_list_event(self): + if not self.isMariaDB(): + self.skipTest("Database is not mariadb") # set max_binlog_size to create new binlog file query = "SET GLOBAL max_binlog_size=4096" self.execute(query) From 4b8833b33f1798fd163d479956e186018ffe3e69 Mon Sep 17 00:00:00 2001 From: starcat37 Date: Sun, 1 Oct 2023 23:03:23 +0900 Subject: [PATCH 06/11] test: move mysql-5-ctl setting to config.json and modify tests --- pymysqlreplication/tests/base.py | 23 +++++++++++++++++-- pymysqlreplication/tests/config.json | 9 ++++++++ pymysqlreplication/tests/test_basic.py | 31 ++++---------------------- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/pymysqlreplication/tests/base.py b/pymysqlreplication/tests/base.py index dce6b27f..2dd9ab16 100644 --- a/pymysqlreplication/tests/base.py +++ b/pymysqlreplication/tests/base.py @@ -2,8 +2,22 @@ import copy from pymysqlreplication import BinLogStreamReader import os +import json +import pytest + import unittest + +def get_databases(): + databases = {} + with open( + os.path.join(os.path.dirname(os.path.abspath(__file__)), "config.json") + ) as f: + databases = json.load(f) + return databases + + +databases = get_databases() base = unittest.TestCase @@ -11,8 +25,10 @@ class PyMySQLReplicationTestCase(base): def ignoredEvents(self): return [] - def setUp(self, charset="utf8"): - # default + @pytest.fixture(autouse=True) + def setUpDBMS(self, get_dbms): + self.database = databases[get_dbms] + """ self.database = { "host": os.environ.get("MYSQL_5_7") or "localhost", "user": "root", @@ -22,7 +38,10 @@ def setUp(self, charset="utf8"): "charset": charset, "db": "pymysqlreplication_test", } + """ + def setUp(self, charset="utf8"): + # default self.conn_control = None db = copy.copy(self.database) db["db"] = None diff --git a/pymysqlreplication/tests/config.json b/pymysqlreplication/tests/config.json index fd51d29c..5bfd93a4 100644 --- a/pymysqlreplication/tests/config.json +++ b/pymysqlreplication/tests/config.json @@ -8,6 +8,15 @@ "charset": "utf8", "db": "pymysqlreplication_test" }, + "mysql-5-ctl": { + "host": "localhost", + "user": "root", + "passwd": "", + "port": 3307, + "use_unicode": true, + "charset": "utf8", + "db": "pymysqlreplication_test" + }, "mariadb-10": { "host": "localhost", "user": "root", diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index bae970e0..850f4d6e 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1,8 +1,5 @@ -import copy import io -import os import time -import pymysql import unittest from pymysqlreplication.tests import base @@ -826,42 +823,22 @@ def test_alter_column(self): class TestCTLConnectionSettings(base.PyMySQLReplicationTestCase): - def setUp(self): + def setUp(self, charset="utf8"): super().setUp() - self.stream.close() - ctl_db = copy.copy(self.database) - ctl_db["db"] = None - ctl_db["port"] = int(os.environ.get("MYSQL_5_7_CTL_PORT") or 3307) - ctl_db["host"] = os.environ.get("MYSQL_5_7_CTL") or "localhost" - self.ctl_conn_control = pymysql.connect(**ctl_db) - self.ctl_conn_control.cursor().execute( - "DROP DATABASE IF EXISTS pymysqlreplication_test" - ) - self.ctl_conn_control.cursor().execute( - "CREATE DATABASE pymysqlreplication_test" - ) - self.ctl_conn_control.close() - ctl_db["db"] = "pymysqlreplication_test" - self.ctl_conn_control = pymysql.connect(**ctl_db) self.stream = BinLogStreamReader( self.database, - ctl_connection_settings=ctl_db, server_id=1024, only_events=(WriteRowsEvent,), ) - def tearDown(self): - super().tearDown() - self.ctl_conn_control.close() - def test_separate_ctl_settings_no_error(self): self.execute("CREATE TABLE test (id INTEGER(11))") self.execute("INSERT INTO test VALUES (1)") self.execute("DROP TABLE test") self.execute("COMMIT") - self.ctl_conn_control.cursor().execute("CREATE TABLE test (id INTEGER(11))") - self.ctl_conn_control.cursor().execute("INSERT INTO test VALUES (1)") - self.ctl_conn_control.cursor().execute("COMMIT") + self.conn_control.cursor().execute("CREATE TABLE test (id INTEGER(11))") + self.conn_control.cursor().execute("INSERT INTO test VALUES (1)") + self.conn_control.cursor().execute("COMMIT") try: self.stream.fetchone() except Exception as e: From cb0a486353d52c1990666efffc9184e5fe611eb6 Mon Sep 17 00:00:00 2001 From: mikaniz Date: Mon, 2 Oct 2023 00:55:03 +0900 Subject: [PATCH 07/11] test: fix to check in setUp method whether it is mariadb or not --- pymysqlreplication/tests/test_basic.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index 850f4d6e..f3b94783 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -1300,9 +1300,12 @@ def tearDown(self): class TestMariadbBinlogStreamReader(base.PyMySQLReplicationTestCase): - def test_binlog_checkpoint_event(self): + def setUp(self): + super().setUp() if not self.isMariaDB(): - self.skipTest("Database is not mariadb") + self.skipTest("Skipping the entire class for MariaDB") + + def test_binlog_checkpoint_event(self): self.stream.close() self.stream = BinLogStreamReader( self.database, server_id=1023, blocking=False, is_mariadb=True @@ -1333,9 +1336,12 @@ def test_binlog_checkpoint_event(self): class TestMariadbBinlogStreamReader2(base.PyMySQLReplicationTestCase): - def test_annotate_rows_event(self): + def setUp(self): + super().setUp() if not self.isMariaDB(): - self.skipTest("Database is not mariadb") + self.skipTest("Skipping the entire class for MariaDB") + + def test_annotate_rows_event(self): query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))" self.execute(query) # Insert first event @@ -1364,8 +1370,6 @@ def test_annotate_rows_event(self): self.assertIsInstance(event, MariadbAnnotateRowsEvent) def test_start_encryption_event(self): - if not self.isMariaDB(): - self.skipTest("Database is not mariadb") query = "CREATE TABLE test (id INT NOT NULL AUTO_INCREMENT, data VARCHAR (50) NOT NULL, PRIMARY KEY (id))" self.execute(query) query = "INSERT INTO test (data) VALUES('Hello World')" @@ -1404,8 +1408,6 @@ def test_start_encryption_event(self): self.assertEqual(len(nonce), 12) def test_gtid_list_event(self): - if not self.isMariaDB(): - self.skipTest("Database is not mariadb") # set max_binlog_size to create new binlog file query = "SET GLOBAL max_binlog_size=4096" self.execute(query) From de228fc656f2a48874441ec33413b7a678f8a451 Mon Sep 17 00:00:00 2001 From: mjs Date: Mon, 2 Oct 2023 14:23:25 +0900 Subject: [PATCH 08/11] feat: add logging for dbms and github actions for test --- .github/workflows/pytest.yml | 10 +++++++++- pymysqlreplication/tests/base.py | 4 +++- pymysqlreplication/tests/test_basic.py | 4 ++++ 3 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 31fb07af..7e635451 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -46,5 +46,13 @@ jobs: pip install pytest - name: Run test suite + working-directory: pymysqlreplication/tests run: | - pytest -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" + dbms_versions=("mysql-5" "mysql-8") + for version in "${dbms_versions[@]}"; do + pytest -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" --dbms=$version + done + + - name: Run tests for MariaDB + run: | + pytest -m mariadb -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" \ No newline at end of file diff --git a/pymysqlreplication/tests/base.py b/pymysqlreplication/tests/base.py index 2dd9ab16..1850cfd3 100644 --- a/pymysqlreplication/tests/base.py +++ b/pymysqlreplication/tests/base.py @@ -17,7 +17,6 @@ def get_databases(): return databases -databases = get_databases() base = unittest.TestCase @@ -27,6 +26,9 @@ def ignoredEvents(self): @pytest.fixture(autouse=True) def setUpDBMS(self, get_dbms): + databases = get_databases() + # For local testing, set the get_dbms parameter to one of the following values: 'mysql-5', 'mysql-8', mariadb-10'. + # This value should correspond to the desired database configuration specified in the 'config.json' file. self.database = databases[get_dbms] """ self.database = { diff --git a/pymysqlreplication/tests/test_basic.py b/pymysqlreplication/tests/test_basic.py index f3b94783..13f79b1c 100644 --- a/pymysqlreplication/tests/test_basic.py +++ b/pymysqlreplication/tests/test_basic.py @@ -10,6 +10,7 @@ from pymysqlreplication.row_event import * from pymysqlreplication.packet import BinLogPacketWrapper from pymysql.protocol import MysqlPacket +import pytest __all__ = [ "TestBasicBinLogStreamReader", @@ -1299,6 +1300,7 @@ def tearDown(self): super(TestStatementConnectionSetting, self).tearDown() +@pytest.mark.mariadb class TestMariadbBinlogStreamReader(base.PyMySQLReplicationTestCase): def setUp(self): super().setUp() @@ -1335,6 +1337,7 @@ def test_binlog_checkpoint_event(self): self.assertEqual(event.filename, self.bin_log_basename() + ".000001") +@pytest.mark.mariadb class TestMariadbBinlogStreamReader2(base.PyMySQLReplicationTestCase): def setUp(self): super().setUp() @@ -1485,6 +1488,7 @@ def test_query_event_latin1(self): assert event.query == r"CREATE TABLE test_latin1_\xd6\xc6\xdb (a INT)" +@pytest.mark.mariadb class TestOptionalMetaData(base.PyMySQLReplicationTestCase): def setUp(self): super(TestOptionalMetaData, self).setUp() From 61781e70ecabdd9d96badf2e5c283a957b78eaf0 Mon Sep 17 00:00:00 2001 From: mjs Date: Mon, 2 Oct 2023 16:19:14 +0900 Subject: [PATCH 09/11] feat: add step mysql-5-ctl --- .github/workflows/pytest.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 7e635451..0d7ae280 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -48,7 +48,7 @@ jobs: - name: Run test suite working-directory: pymysqlreplication/tests run: | - dbms_versions=("mysql-5" "mysql-8") + dbms_versions=("mysql-5" "mysql-5-ctl" "mysql-8") for version in "${dbms_versions[@]}"; do pytest -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" --dbms=$version done From 76b5a3f2730d1db4b7e30da981aed93b88a968b4 Mon Sep 17 00:00:00 2001 From: mjs Date: Mon, 2 Oct 2023 16:38:46 +0900 Subject: [PATCH 10/11] feat: add dbms mariadb --- .github/workflows/pytest.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 0d7ae280..3070def6 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -54,5 +54,6 @@ jobs: done - name: Run tests for MariaDB + working-directory: pymysqlreplication/tests run: | - pytest -m mariadb -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" \ No newline at end of file + pytest -m mariadb -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" --dbms=mariadb-10 \ No newline at end of file From 387ab3ecc75d3e557968b01d51fe53434ba72613 Mon Sep 17 00:00:00 2001 From: heehehe Date: Tue, 3 Oct 2023 12:13:37 +0900 Subject: [PATCH 11/11] refactor: split tests by db --- .github/workflows/pytest.yml | 30 ++++++++++++++++------------ pymysqlreplication/tests/base.py | 4 ++-- pymysqlreplication/tests/conftest.py | 6 +++--- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/.github/workflows/pytest.yml b/.github/workflows/pytest.yml index 3070def6..23a24e34 100644 --- a/.github/workflows/pytest.yml +++ b/.github/workflows/pytest.yml @@ -1,6 +1,7 @@ name: PyTest on: [push, pull_request] - +env: + PYTEST_SKIP_OPTION: "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" jobs: test: strategy: @@ -29,15 +30,15 @@ jobs: docker compose create docker compose start echo "wait mysql server" - + while : do - if mysql -h 127.0.0.1 --user=root --execute "SELECT version();" 2>&1 >/dev/null && mysql -h 127.0.0.1 --port=3307 --user=root --execute "SELECT version();" 2>&1 >/dev/null; then + if mysql -h 127.0.0.1 --user=root --execute "SELECT version();" 2>&1 >/dev/null && mysql -h 127.0.0.1 --port=3307 --user=root --execute "SELECT version();" 2>&1 >/dev/null; then break fi sleep 1 done - + echo "run pytest" - name: Install dependencies @@ -45,15 +46,18 @@ jobs: pip install . pip install pytest - - name: Run test suite + - name: Run tests for mysql-5 working-directory: pymysqlreplication/tests - run: | - dbms_versions=("mysql-5" "mysql-5-ctl" "mysql-8") - for version in "${dbms_versions[@]}"; do - pytest -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" --dbms=$version - done + run: pytest -k "$PYTEST_SKIP_OPTION" --db=mysql-5 - - name: Run tests for MariaDB + - name: Run tests for mysql-5-ctl working-directory: pymysqlreplication/tests - run: | - pytest -m mariadb -k "not test_no_trailing_rotate_event and not test_end_log_pos and not test_query_event_latin1" --dbms=mariadb-10 \ No newline at end of file + run: pytest -k "$PYTEST_SKIP_OPTION" --db=mysql-5-ctl + + - name: Run tests for mysql-8 + working-directory: pymysqlreplication/tests + run: pytest -k "$PYTEST_SKIP_OPTION" --db=mysql-8 + + - name: Run tests for mariadb-10 + working-directory: pymysqlreplication/tests + run: pytest -k "$PYTEST_SKIP_OPTION" -m mariadb --db=mariadb-10 diff --git a/pymysqlreplication/tests/base.py b/pymysqlreplication/tests/base.py index 1850cfd3..b288be84 100644 --- a/pymysqlreplication/tests/base.py +++ b/pymysqlreplication/tests/base.py @@ -25,11 +25,11 @@ def ignoredEvents(self): return [] @pytest.fixture(autouse=True) - def setUpDBMS(self, get_dbms): + def setUpDatabase(self, get_db): databases = get_databases() # For local testing, set the get_dbms parameter to one of the following values: 'mysql-5', 'mysql-8', mariadb-10'. # This value should correspond to the desired database configuration specified in the 'config.json' file. - self.database = databases[get_dbms] + self.database = databases[get_db] """ self.database = { "host": os.environ.get("MYSQL_5_7") or "localhost", diff --git a/pymysqlreplication/tests/conftest.py b/pymysqlreplication/tests/conftest.py index fb3a2a72..8e1b55b7 100644 --- a/pymysqlreplication/tests/conftest.py +++ b/pymysqlreplication/tests/conftest.py @@ -2,9 +2,9 @@ def pytest_addoption(parser): - parser.addoption("--dbms", action="store", default="mysql-5") + parser.addoption("--db", action="store", default="mysql-5") @pytest.fixture -def get_dbms(request): - return request.config.getoption("--dbms") +def get_db(request): + return request.config.getoption("--db")