|
83 | 83 | from . import check_tls_versions_support
|
84 | 84 |
|
85 | 85 | try:
|
| 86 | + from _mysql_connector import MySQL |
| 87 | + |
86 | 88 | from mysql.connector.connection_cext import CMySQLConnection, MySQLInterfaceError
|
87 | 89 | except ImportError:
|
88 | 90 | # Test without C Extension
|
89 | 91 | CMySQLConnection = None
|
90 | 92 | MySQLInterfaceError = None
|
| 93 | + MySQL = None |
91 | 94 |
|
92 | 95 | ERR_NO_CEXT = "C Extension not available"
|
93 | 96 |
|
@@ -7523,3 +7526,64 @@ def test_connect_database_name(self):
|
7523 | 7526 | config["database"] = self.database
|
7524 | 7527 | with self.cnx.__class__(**config) as cnx:
|
7525 | 7528 | self.assertTrue(cnx.is_connected())
|
| 7529 | + |
| 7530 | + |
| 7531 | +class BugOra35349093(tests.MySQLConnectorTests): |
| 7532 | + """BUG#35349093: Compression doesn't work with C extension API |
| 7533 | +
|
| 7534 | + Compression is not enabled when using the C API implementation directly |
| 7535 | + with the connection option `compress=True`. |
| 7536 | +
|
| 7537 | + This patch fixes this issue by adding CLIENT_COMPRESS to client flags. |
| 7538 | +
|
| 7539 | + Thank you for your contribution. |
| 7540 | + """ |
| 7541 | + |
| 7542 | + def _get_compression_status(self): |
| 7543 | + with self.cnx.cursor() as cur: |
| 7544 | + cur.execute("SHOW SESSION STATUS LIKE 'Compression'") |
| 7545 | + return cur.fetchone() |
| 7546 | + |
| 7547 | + @staticmethod |
| 7548 | + def _test_compression_status_cext(compress): |
| 7549 | + config = tests.get_mysql_config() |
| 7550 | + del config["connection_timeout"] |
| 7551 | + config["compress"] = compress |
| 7552 | + cnx = MySQL() |
| 7553 | + cnx.connect(**config) |
| 7554 | + cnx.query("SHOW SESSION STATUS LIKE 'Compression'") |
| 7555 | + res = cnx.fetch_row() |
| 7556 | + cnx.close() |
| 7557 | + return res |
| 7558 | + |
| 7559 | + @foreach_cnx() |
| 7560 | + def test_set_compress_default(self): |
| 7561 | + """Test default `compress` option.""" |
| 7562 | + res = self._get_compression_status() |
| 7563 | + self.assertEqual(res, ("Compression", "OFF")) |
| 7564 | + |
| 7565 | + @cnx_config(compress=False) |
| 7566 | + @foreach_cnx() |
| 7567 | + def test_set_compress_false(self): |
| 7568 | + """Test setting `compress=False`.""" |
| 7569 | + res = self._get_compression_status() |
| 7570 | + self.assertEqual(res, ("Compression", "OFF")) |
| 7571 | + |
| 7572 | + @cnx_config(compress=True) |
| 7573 | + @foreach_cnx() |
| 7574 | + def test_set_compress_true(self): |
| 7575 | + """Test setting `compress=True`.""" |
| 7576 | + res = self._get_compression_status() |
| 7577 | + self.assertEqual(res, ("Compression", "ON")) |
| 7578 | + |
| 7579 | + @unittest.skipIf(not CMySQLConnection, ERR_NO_CEXT) |
| 7580 | + def test_set_compress_cext_true(self): |
| 7581 | + """Test setting `compress=True` in the C extension directly.""" |
| 7582 | + res = self._test_compression_status_cext(True) |
| 7583 | + self.assertEqual(res, ("Compression", "ON")) |
| 7584 | + |
| 7585 | + @unittest.skipIf(not CMySQLConnection, ERR_NO_CEXT) |
| 7586 | + def test_set_compress_cext_false(self): |
| 7587 | + """Test setting `compress=False` in the C extension directly.""" |
| 7588 | + res = self._test_compression_status_cext(False) |
| 7589 | + self.assertEqual(res, ("Compression", "OFF")) |
0 commit comments