#!/bin/sh # Never connects to the production socket/server. Fresh no-defaults, socket-only # instance, with its own data/pid/log files; preserve evidence after shutdown. set -eu repo_dir=$(CDPATH= cd -- "$(dirname -- "$0")/../.." && pwd) test_dir=$(mktemp -d /tmp/ch5-cube-mysql.XXXXXX) test_socket="$test_dir/mysql.sock" printf 'Isolated Cube MySQL evidence: %s\n' "$test_dir" mysql_install_db --no-defaults --basedir=/usr/local --datadir="$test_dir/data" --user=root > "$test_dir/install.log" 2>&1 mysqld_path=/usr/local/libexec/mysqld "$mysqld_path" --no-defaults --basedir=/usr/local --datadir="$test_dir/data" --socket="$test_socket" \ --pid-file="$test_dir/mysql.pid" --log-error="$test_dir/mysql.log" --skip-networking --user=root \ --innodb-buffer-pool-size=32M --innodb-log-file-size=16M --key-buffer-size=8M --max-connections=10 \ > "$test_dir/console.log" 2>&1 & cleanup() { mysqladmin --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot shutdown >/dev/null 2>&1 || true; } trap cleanup EXIT HUP INT TERM ready=0 while [ "$ready" -lt 30 ]; do if mysqladmin --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot ping > /dev/null 2>&1; then break; fi ready=$((ready+1)); sleep 1 done mysqladmin --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot ping mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot -e 'CREATE DATABASE cube_batch_test' c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_batch_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-batch" "$test_dir/cube-batch" "$test_socket" base mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_batch_test < "$repo_dir/tools/cube/schema.sql" "$test_dir/cube-batch" "$test_socket" > "$test_dir/result.log" 2>&1 "$test_dir/cube-batch" "$test_socket" fence >> "$test_dir/result.log" 2>&1 cat "$test_dir/result.log" # Base/lifecycle probes above intentionally run with the addon absent. New # optional schema and its exactly-once credit probes use this same isolated DB. mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_batch_test < "$repo_dir/tools/cube/gold-schema.sql" c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_gold_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-gold" "$test_dir/cube-gold" "$test_socket" > "$test_dir/gold-result.log" 2>&1 cat "$test_dir/gold-result.log" c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_outbox_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-outbox" "$test_dir/cube-outbox" "$test_socket" > "$test_dir/outbox-result.log" 2>&1 cat "$test_dir/outbox-result.log" c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_source_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-source" "$test_dir/cube-source" "$test_socket" > "$test_dir/source-result.log" 2>&1 cat "$test_dir/source-result.log" mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_batch_test < "$repo_dir/tools/cube/owner-schema.sql" c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_owner_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-owner" "$test_dir/cube-owner" "$test_socket" > "$test_dir/owner-result.log" 2>&1 cat "$test_dir/owner-result.log" c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_image_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-image" "$test_dir/cube-image" "$test_socket" > "$test_dir/image-result.log" 2>&1 cat "$test_dir/image-result.log" mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_batch_test < "$repo_dir/tools/cube/image-ack-schema.sql" c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_image_ack_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-image-ack" "$test_dir/cube-image-ack" "$test_socket" > "$test_dir/image-ack-result.log" 2>&1 cat "$test_dir/image-ack-result.log" mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_batch_test < "$repo_dir/tools/cube/release-schema.sql" c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_release_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-release" "$test_dir/cube-release" "$test_socket" > "$test_dir/release-result.log" 2>&1 cat "$test_dir/release-result.log" c++ -std=c++17 -O1 -g -DPORT_CUBE_MYSQL -I"$repo_dir" $(mysql_config --cflags) \ "$repo_dir/tests/features/fixtures/cube_craft_probe.cpp" $(mysql_config --libs) -o "$test_dir/cube-craft" "$test_dir/cube-craft" "$test_socket" > "$test_dir/craft-result.log" 2>&1 cat "$test_dir/craft-result.log" # Only full source/build trees have the platform-matched internal libraries. # Do not silently claim a worker test on the smaller SQL-store-only staging tree. if [ "${CUBE_TEST_SQL_WORKER:-0}" = 1 ]; then c++ -std=c++17 -O1 -g -pthread -I"$repo_dir" -I/usr/local/include \ "$repo_dir/tests/features/fixtures/sql_fence_mysql_probe.cpp" \ "$repo_dir/src/server/libsql/libsql.a" "$repo_dir/src/server/libthecore/lib/libthecore.a" \ $(mysql_config --libs) -o "$test_dir/sql-fence-worker" "$test_dir/sql-fence-worker" "$test_socket" > "$test_dir/sql-worker.log" 2>&1 cat "$test_dir/sql-worker.log" fi # Separate legacy fixture database tests the actual explicit upgrade, including # refusal to drop unresolved fences, partial-DDL retry and preserved history. mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot <<'SQL' CREATE DATABASE cube_upgrade_test; USE cube_upgrade_test; CREATE TABLE port_cube_version(id INT PRIMARY KEY,version INT) ENGINE=InnoDB; INSERT INTO port_cube_version VALUES(1,1); CREATE TABLE port_cube_requests(token VARCHAR(32) PRIMARY KEY,state ENUM('PREPARED','DONE'),body MEDIUMBLOB) ENGINE=InnoDB; INSERT INTO port_cube_requests VALUES('history','DONE',X'010203'); CREATE TABLE port_cube_fences(pid INT PRIMARY KEY,account INT,epoch BIGINT,owner VARCHAR(32),request VARCHAR(32),phase ENUM('FROZEN','RESYNC') NOT NULL) ENGINE=InnoDB; INSERT INTO port_cube_fences VALUES(1,1,1,'owner','request','FROZEN'); SQL if mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_upgrade_test < "$repo_dir/tools/cube/upgrade-v2.sql" > "$test_dir/upgrade-refused.log" 2>&1; then echo 'ERROR: migration accepted unresolved v1 fence'; exit 1 fi grep -F 'Resolve v1 fences before migration' "$test_dir/upgrade-refused.log" > /dev/null mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_upgrade_test -e "DELETE FROM port_cube_fences; INSERT INTO port_cube_requests VALUES('pending','PREPARED',X'00')" if mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_upgrade_test < "$repo_dir/tools/cube/upgrade-v2.sql" > "$test_dir/upgrade-pending-refused.log" 2>&1; then echo 'ERROR: migration accepted prepared v1 batch'; exit 1 fi grep -F 'Resolve v1 prepared batches before migration' "$test_dir/upgrade-pending-refused.log" > /dev/null mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_upgrade_test -e "DELETE FROM port_cube_requests WHERE token='pending'; ALTER TABLE port_cube_fences ADD body MEDIUMBLOB NOT NULL" mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_upgrade_test < "$repo_dir/tools/cube/upgrade-v2.sql" mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_upgrade_test < "$repo_dir/tools/cube/upgrade-v2.sql" upgraded=$(mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot -N cube_upgrade_test -e "SELECT CONCAT(version,':',(SELECT HEX(body) FROM port_cube_requests WHERE token='history')) FROM port_cube_version WHERE id=1") [ "$upgraded" = '2:010203' ] echo 'PASS v1 upgrade: refuses unresolved state, retries partial DDL, retains history, idempotent v2' # Separate old-addon fixture; never infer a closed source for preserved v1 # intentions. The new source table must remain empty after metadata migration. mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot <<'SQL' CREATE DATABASE cube_gold_upgrade_test; USE cube_gold_upgrade_test; CREATE TABLE port_cube_gold_version(id INT UNSIGNED PRIMARY KEY,version INT UNSIGNED NOT NULL) ENGINE=InnoDB; INSERT INTO port_cube_gold_version VALUES(1,1); CREATE TABLE port_cube_gold_intents(event CHAR(32) PRIMARY KEY,request CHAR(32) NOT NULL,seq INT UNSIGNED NOT NULL,account INT UNSIGNED NOT NULL,pid INT UNSIGNED NOT NULL,body VARBINARY(129) NOT NULL,state ENUM('QUEUED','APPLIED') NOT NULL,before_gold BIGINT UNSIGNED NOT NULL DEFAULT 0,after_gold BIGINT UNSIGNED NOT NULL DEFAULT 0,UNIQUE(request,seq),INDEX player_pending(pid,state)) ENGINE=InnoDB; INSERT INTO port_cube_gold_intents VALUES('history','request',1,1,1,X'010203','QUEUED',0,0); SQL mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test < "$repo_dir/tools/cube/gold-upgrade-v2.sql" mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test -e 'UPDATE port_cube_gold_version SET version=3' if mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test < "$repo_dir/tools/cube/gold-upgrade-v2.sql" > "$test_dir/gold-upgrade-version-refused.log" 2>&1; then echo 'ERROR gold migration accepted unknown version'; exit 1 fi mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test -e 'UPDATE port_cube_gold_version SET version=1; ALTER TABLE port_cube_gold_sources DROP COLUMN manifest' if mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test < "$repo_dir/tools/cube/gold-upgrade-v2.sql" > "$test_dir/gold-upgrade-partial-refused.log" 2>&1; then echo 'ERROR gold migration accepted partial source metadata'; exit 1 fi mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test -e 'ALTER TABLE port_cube_gold_sources ADD manifest VARBINARY(32772) NOT NULL; ALTER TABLE port_cube_gold_intents ENGINE=MyISAM' if mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test < "$repo_dir/tools/cube/gold-upgrade-v2.sql" > "$test_dir/gold-upgrade-engine-refused.log" 2>&1; then echo 'ERROR gold migration accepted nontransactional foundation'; exit 1 fi mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test -e 'ALTER TABLE port_cube_gold_intents ENGINE=InnoDB' mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test < "$repo_dir/tools/cube/gold-upgrade-v2.sql" mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot cube_gold_upgrade_test < "$repo_dir/tools/cube/gold-upgrade-v2.sql" gold_upgraded=$(mysql --no-defaults --protocol=SOCKET --socket="$test_socket" -uroot -N cube_gold_upgrade_test -e "SELECT CONCAT(version,':',(SELECT HEX(body) FROM port_cube_gold_intents WHERE event='history'),':',(SELECT COUNT(*) FROM port_cube_gold_sources)) FROM port_cube_gold_version WHERE id=1") [ "$gold_upgraded" = '2:010203:0' ] echo 'PASS gold-addon v1->v2 migration: history retained, no manufactured closure, unknown/partial/MyISAM refused, explicit repair/retry and idempotence' printf 'PASS; dedicated instance will shut down, data retained at %s\n' "$test_dir"