Last active
May 19, 2026 17:49
-
-
Save ronaldbradford/2d6441ac11922d9946508876a8c4cac6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/bash | |
| [[ -n ${TRACE:-} ]] && set -x | |
| # DBDeployer - The MySQL Sandbox | |
| # Copyright (C) 2006-2020 Giuseppe Maxia | |
| # Creator: Ronald Bradford | |
| # | |
| # Licensed under the Apache License, Version 2.0 (the "License"); | |
| # you may not use this file except in compliance with the License. | |
| # You may obtain a copy of the License at | |
| # | |
| # http://www.apache.org/licenses/LICENSE-2.0 | |
| # | |
| # Unless required by applicable law or agreed to in writing, software | |
| # distributed under the License is distributed on an "AS IS" BASIS, | |
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
| # See the License for the specific language governing permissions and | |
| # limitations under the License. | |
| SBDIR=$(pwd) | |
| cd "$SBDIR" | |
| FAILED=0 | |
| PASSED=0 | |
| function ok_equal | |
| { | |
| fact="$1" | |
| expected="$2" | |
| msg="$3" | |
| if [ "$fact" == "$expected" ] | |
| then | |
| echo -n "ok (expected: <$expected>)" | |
| PASSED=$(($PASSED+1)) | |
| else | |
| echo -n "not ok - (expected: <$expected> found: <$fact>) " | |
| FAILED=$(($FAILED+1)) | |
| fi | |
| echo " - $msg" | |
| } | |
| if [ -x ./m ] | |
| then | |
| PRIMARY=./m | |
| elif [ -x ./n1 ] | |
| then | |
| PRIMARY=./n1 | |
| else | |
| echo "# No master found" | |
| exit 1 | |
| fi | |
| YYYY_MM=$(date +%Y-%m) | |
| echo "Creating and populating table..." | |
| $PRIMARY -qc 'DROP TABLE IF EXISTS t1' | |
| $PRIMARY -qc 'CREATE TABLE t1 (i INT NOT NULL PRIMARY KEY, msg VARCHAR(50), d DATE, t TIME, dt TIMESTAMP, ts TIMESTAMP)' | |
| for N in $(seq -f '%02.0f' 1 20) | |
| do | |
| $PRIMARY -qc "INSERT INTO t1 VALUES ($N, 'test sandbox $N', '${YYYY_MM}-$N', '11:23:$N', '${YYYY_MM}-01 12:34:$N', NULL)" | |
| done | |
| sleep 0.5 | |
| PRIMARY_RECS=$($PRIMARY -Atqc 'select count(*) from t1') | |
| PRIMARY_POS=$($PRIMARY -Atqc 'SELECT pg_current_wal_lsn()') | |
| for N in $(seq 1 9); do | |
| unset REPLICA | |
| if [ -x ./n$N ] | |
| then | |
| REPLICA=./n$N | |
| fi | |
| [ -z "$REPLICA" ] && continue | |
| echo "# Testing replica #$N" | |
| #STATUS=$($REPICA -At -c 'SELECT pg_last_wal_replay_lsn(), pg_is_in_recovery(), now() - pg_last_xact_replay_timestamp() AS lag;') | |
| REPLICA_POS=$($REPLICA -Atqc 'SELECT pg_last_wal_replay_lsn()') | |
| REPLICA_RECS=$($REPLICA -Atqc 'SELECT count(*) FROM t1') | |
| ok_equal ${PRIMARY_POS} ${REPLICA_POS} "$N LSN" | |
| ok_equal ${PRIMARY_RECS} ${REPLICA_RECS} "$N records" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment