Skip to content

Commit 174c5bd

Browse files
committed
test: expand zstd_compression_level test with MySQL 8.4 C API and timing benchmark
The existing test only verified admin variable behavior (default, range, independence). It did not prove that ZSTD compression was actually active on the wire. Two new test variants address this: MariaDB connector path (mysql-zstd_compression_level-t): - Tests 1-9: unchanged (variable defaults, range validation, independence) - Tests 10-11: use mysql CLI via execvp with --compression-algorithms=zstd and --zstd-compression-level={3,19}. Each call spawns a new process (= new connection). Verifies CONNECTION_ID() retrieval and large resultset transfer. Skipped if mysql CLI lacks zstd support. MySQL 8.4 connector path (mysql-zstd_compression_level_libmysql-t): - Tests 1-9: same as MariaDB path - Test 10: establishes a ZSTD connection using mysql_options( MYSQL_OPT_COMPRESSION_ALGORITHMS, "zstd") and prints mysql_thread_id() without running any query. - Test 11: timing benchmark proving compression is active. Creates a query rule (rule_id=1, cache_ttl=60000) to cache all SELECTs, then runs a 576-row resultset query 1000 times on a plain connection and 1000 times on a ZSTD level 22 connection. ZSTD level 22 is extremely CPU-intensive: observed 40122ms vs 858ms (46.7x ratio). A ratio >= 3x proves compression is really running on the client<->ProxySQL link. Other changes: - MySQL_Protocol.cpp: simplify redundant clamping to a simple cast (the variable is already validated at SET time) - Makefile: add build rule for _libmysql variant linking against MySQL 8.4 connector - groups.json: register _libmysql variant for mysql84/90/95-g1 - CLAUDE.md: update testing section with CI script usage and DO NOT list
1 parent f9f6f74 commit 174c5bd

5 files changed

Lines changed: 310 additions & 32 deletions

File tree

CLAUDE.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -55,22 +55,39 @@ The same codebase produces three product tiers via feature flags:
5555

5656
Tests use TAP (Test Anything Protocol) with Docker-based backend infrastructure.
5757

58+
### Running TAP tests — DO NOT manually set up Docker containers
59+
60+
**ALWAYS use `run-tests-isolated.bash`**. It handles infrastructure setup, ProxySQL start, test execution, and cleanup. Never manually create Docker networks, start containers, or run init scripts — the runner does all of that.
61+
5862
```bash
59-
# Build and run all TAP tests
60-
make build_tap_tests
61-
cd test/tap && make
63+
# Set up infrastructure (backends + ProxySQL container)
64+
WORKSPACE=$(pwd) INFRA_ID=dev-$USER TAP_GROUP=mysql84-g1 test/infra/control/ensure-infras.bash
6265

63-
# Run specific test groups
64-
cd test/tap/tests && make
65-
cd test/tap/tests_with_deps && make
66+
# Run all tests for a TAP group
67+
WORKSPACE=$(pwd) INFRA_ID=dev-$USER TAP_GROUP=mysql84-g1 test/infra/control/run-tests-isolated.bash
6668

67-
# Test infrastructure (Docker environments)
68-
# Located in test/infra/ with docker-compose configs for:
69-
# mysql57, mysql84, mariadb10, pgsql16, pgsql17, clickhouse23, etc.
69+
# Build test binaries first (requires proxysql binary)
70+
make build_tap_tests # release
71+
make build_tap_test_debug # debug
7072
```
7173

74+
Available TAP groups are defined in `test/tap/groups/groups.json`. Group names follow the pattern `<infra>-g<N>` (e.g., `mysql84-g1`, `legacy-g2`, `pgsql16-g1`).
75+
76+
### DO NOT
77+
78+
- **DO NOT** manually create Docker networks (`docker network create`)
79+
- **DO NOT** manually start containers (`docker start`, `docker run`)
80+
- **DO NOT** run `docker-compose-init.bash` directly — use `ensure-infras.bash`
81+
- **DO NOT** symlink build artifacts between worktrees — build in each worktree separately
82+
- **DO NOT** copy source files between worktrees or repos
83+
- **DO NOT** run `cd test/tap/tests && make` and expect tests to pass without infrastructure
84+
85+
### Test file conventions
86+
7287
Test files follow the naming pattern `test_*.cpp` or `*-t.cpp` in `test/tap/tests/`.
7388

89+
Test binaries are built via a pattern rule in `test/tap/tests/Makefile`: `make <testname>-t` compiles `<testname>-t.cpp` into `<testname>-t`. No special Makefile target is needed for new tests — just add the `.cpp` file and register it in `groups.json`.
90+
7491
## Architecture
7592

7693
### Build Pipeline

lib/MySQL_Protocol.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2300,7 +2300,7 @@ void MySQL_Protocol::PPHR_SetConnAttrs(MyProt_tmp_auth_vars& vars1, account_deta
23002300
const uint8_t zstd_compression_level =
23012301
(vars1.zstd_compression_level > 0 && vars1.zstd_compression_level <= ZSTD_maxCLevel())
23022302
? vars1.zstd_compression_level
2303-
: static_cast<uint8_t>(std::min<int>(ZSTD_maxCLevel(), std::max<int>(1, mysql_thread___zstd_compression_level)));
2303+
: static_cast<uint8_t>(mysql_thread___zstd_compression_level);
23042304

23052305
myconn->options.compression_zstd = false;
23062306
myconn->options.zstd_compression_level = 0;

test/tap/groups/groups.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
"mysql-test_ssl_CA-t" : [ "legacy-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1","mysql84-g1","mysql90-g1","mysql95-g1" ],
101101
"mysql-watchdog_test-t" : [ "legacy-g4","mysql-auto_increment_delay_multiplex=0-g4","mysql-multiplexing=false-g4","mysql-query_digests=0-g4","mysql-query_digests_keep_comment=1-g4","mysql84-g4","mysql90-g4","mysql95-g4" ],
102102
"mysql-zstd_compression_level-t" : [ "legacy-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1","mysql84-g1","mysql90-g1","mysql95-g1" ],
103+
"mysql-zstd_compression_level_libmysql-t" : [ "mysql84-g1","mysql90-g1","mysql95-g1" ],
103104
"mysql_encode_unit-t" : [ "unit-tests-g1" ],
104105
"mysql_error_classifier_unit-t" : [ "unit-tests-g1" ],
105106
"mysql_hostgroup_attributes-servers_defaults-t" : [ "legacy-g1","mysql-auto_increment_delay_multiplex=0-g1","mysql-multiplexing=false-g1","mysql-query_digests=0-g1","mysql-query_digests_keep_comment=1-g1","mysql84-g1","mysql90-g1","mysql95-g1" ],

test/tap/tests/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,9 @@ mysql_reconnect_libmariadb-t: mysql_reconnect.cpp $(TAP_LDIR)/libtap.so
263263
mysql_reconnect_libmysql-t: mysql_reconnect.cpp $(TAP_LDIR)/libtap_mysql8.a
264264
$(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -o $@
265265

266+
mysql-zstd_compression_level_libmysql-t: mysql-zstd_compression_level-t.cpp $(TAP_LDIR)/libtap_mysql8.a
267+
$(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -o $@
268+
266269
fast_forward_grace_close_libmysql-t: fast_forward_grace_close.cpp $(TAP_LDIR)/libtap_mysql8.a
267270
$(CXX) -DLIBMYSQL_HELPER8 -DDISABLE_WARNING_COUNT_LOGGING $< -I$(TEST_MYSQL8_IDIR) -I$(TEST_MYSQL8_EDIR) -L$(TEST_MYSQL8_LDIR) -lmysqlclient -ltap_mysql8 -lresolv $(CUSTOMARGS) -o $@
268271

0 commit comments

Comments
 (0)