2016-08-22 07:20:17 +00:00
|
|
|
#!/bin/bash
|
|
|
|
|
2016-08-24 10:51:01 +00:00
|
|
|
# Local integration tests. To be used by CI.
|
|
|
|
# See https://github.com/github/gh-ost/tree/doc/local-tests.md
|
|
|
|
#
|
2016-08-22 07:20:17 +00:00
|
|
|
|
2016-09-06 07:46:11 +00:00
|
|
|
# Usage: localtests/test/sh [filter]
|
|
|
|
# By default, runs all tests. Given filter, will only run tests matching given regep
|
|
|
|
|
2016-08-22 07:20:17 +00:00
|
|
|
tests_path=$(dirname $0)
|
2016-08-22 09:13:18 +00:00
|
|
|
test_logfile=/tmp/gh-ost-test.log
|
2016-08-22 10:18:02 +00:00
|
|
|
exec_command_file=/tmp/gh-ost-test.bash
|
2016-08-22 07:20:17 +00:00
|
|
|
|
2016-09-06 07:36:29 +00:00
|
|
|
test_pattern="${1:-.}"
|
|
|
|
|
2016-08-22 09:13:18 +00:00
|
|
|
master_host=
|
|
|
|
master_port=
|
|
|
|
replica_host=
|
|
|
|
replica_port=
|
2016-08-22 07:20:17 +00:00
|
|
|
|
2016-08-22 09:13:18 +00:00
|
|
|
verify_master_and_replica() {
|
|
|
|
if [ "$(gh-ost-test-mysql-master -e "select 1" -ss)" != "1" ] ; then
|
|
|
|
echo "Cannot verify gh-ost-test-mysql-master"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
read master_host master_port <<< $(gh-ost-test-mysql-master -e "select @@hostname, @@port" -ss)
|
|
|
|
if [ "$(gh-ost-test-mysql-replica -e "select 1" -ss)" != "1" ] ; then
|
|
|
|
echo "Cannot verify gh-ost-test-mysql-replica"
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
read replica_host replica_port <<< $(gh-ost-test-mysql-replica -e "select @@hostname, @@port" -ss)
|
|
|
|
}
|
|
|
|
|
2016-08-22 09:51:03 +00:00
|
|
|
exec_cmd() {
|
|
|
|
echo "$@"
|
|
|
|
command "$@" 1> $test_logfile 2>&1
|
|
|
|
return $?
|
|
|
|
}
|
|
|
|
|
2016-09-06 07:36:29 +00:00
|
|
|
echo_dot() {
|
|
|
|
echo -n "."
|
|
|
|
}
|
|
|
|
|
2016-08-22 09:13:18 +00:00
|
|
|
test_single() {
|
|
|
|
local test_name
|
|
|
|
test_name="$1"
|
2016-08-22 07:20:17 +00:00
|
|
|
|
2016-09-06 07:36:29 +00:00
|
|
|
echo -n "Testing: $test_name"
|
2016-08-22 09:13:18 +00:00
|
|
|
|
2016-09-06 07:36:29 +00:00
|
|
|
echo_dot
|
2016-08-22 09:13:18 +00:00
|
|
|
gh-ost-test-mysql-replica -e "start slave"
|
2016-09-06 07:36:29 +00:00
|
|
|
echo_dot
|
2016-09-07 12:24:11 +00:00
|
|
|
gh-ost-test-mysql-master --default-character-set=utf8mb4 test < $tests_path/$test_name/create.sql
|
2016-08-22 09:13:18 +00:00
|
|
|
|
2016-08-22 09:51:03 +00:00
|
|
|
extra_args=""
|
2016-08-22 09:13:18 +00:00
|
|
|
if [ -f $tests_path/$test_name/extra_args ] ; then
|
2016-08-22 10:18:02 +00:00
|
|
|
extra_args=$(cat $tests_path/$test_name/extra_args)
|
2016-08-22 09:13:18 +00:00
|
|
|
fi
|
|
|
|
columns="*"
|
|
|
|
if [ -f $tests_path/$test_name/test_columns ] ; then
|
|
|
|
columns=$(cat $tests_path/$test_name/test_columns)
|
|
|
|
fi
|
2016-08-24 12:18:49 +00:00
|
|
|
# graceful sleep for replica to catch up
|
2016-09-06 07:36:29 +00:00
|
|
|
echo_dot
|
2016-08-24 12:18:49 +00:00
|
|
|
sleep 1
|
|
|
|
#
|
2016-08-22 10:18:02 +00:00
|
|
|
cmd="go run go/cmd/gh-ost/main.go \
|
2016-08-22 09:13:18 +00:00
|
|
|
--user=gh-ost \
|
|
|
|
--password=gh-ost \
|
|
|
|
--host=$replica_host \
|
|
|
|
--port=$replica_port \
|
|
|
|
--database=test \
|
|
|
|
--table=gh_ost_test \
|
2016-08-22 10:18:02 +00:00
|
|
|
--alter='engine=innodb' \
|
2016-08-22 09:13:18 +00:00
|
|
|
--exact-rowcount \
|
|
|
|
--switch-to-rbr \
|
|
|
|
--initially-drop-old-table \
|
|
|
|
--initially-drop-ghost-table \
|
2016-08-22 10:18:02 +00:00
|
|
|
--throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _gh_ost_test_ghc' \
|
2016-08-22 09:13:18 +00:00
|
|
|
--serve-socket-file=/tmp/gh-ost.test.sock \
|
|
|
|
--initially-drop-socket-file \
|
2016-09-07 12:24:11 +00:00
|
|
|
--postpone-cut-over-flag-file="" \
|
2016-08-22 09:13:18 +00:00
|
|
|
--test-on-replica \
|
2016-08-22 13:43:00 +00:00
|
|
|
--default-retries=1 \
|
2016-08-22 09:13:18 +00:00
|
|
|
--verbose \
|
|
|
|
--debug \
|
|
|
|
--stack \
|
2016-08-22 10:18:02 +00:00
|
|
|
--execute ${extra_args[@]}"
|
2016-09-06 07:36:29 +00:00
|
|
|
echo_dot
|
2016-08-22 10:18:02 +00:00
|
|
|
echo $cmd > $exec_command_file
|
2016-09-06 07:36:29 +00:00
|
|
|
echo_dot
|
2016-08-22 13:43:00 +00:00
|
|
|
bash $exec_command_file 1> $test_logfile 2>&1
|
2016-08-22 09:13:18 +00:00
|
|
|
|
2016-08-22 10:18:02 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
2016-09-06 07:36:29 +00:00
|
|
|
echo
|
|
|
|
echo "ERROR $test_name execution failure. cat $test_logfile"
|
2016-08-22 10:18:02 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2016-08-22 09:13:18 +00:00
|
|
|
|
2016-09-06 07:36:29 +00:00
|
|
|
echo_dot
|
2016-09-08 07:27:18 +00:00
|
|
|
orig_checksum=$(gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${columns} from gh_ost_test" -ss | md5sum)
|
|
|
|
ghost_checksum=$(gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${columns} from _gh_ost_test_gho" -ss | md5sum)
|
2016-08-22 09:13:18 +00:00
|
|
|
|
2016-08-22 10:18:02 +00:00
|
|
|
if [ "$orig_checksum" != "$ghost_checksum" ] ; then
|
|
|
|
echo "ERROR $test_name: checksum mismatch"
|
2016-08-22 13:43:00 +00:00
|
|
|
echo "---"
|
2016-09-08 07:27:18 +00:00
|
|
|
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${columns} from gh_ost_test" -ss
|
2016-08-22 13:43:00 +00:00
|
|
|
echo "---"
|
2016-09-08 07:27:18 +00:00
|
|
|
gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "select ${columns} from _gh_ost_test_gho" -ss
|
2016-08-22 10:18:02 +00:00
|
|
|
return 1
|
|
|
|
fi
|
2016-08-22 09:13:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
test_all() {
|
2016-09-06 07:36:29 +00:00
|
|
|
find $tests_path ! -path . -type d -mindepth 1 -maxdepth 1 | cut -d "/" -f 3 | egrep "$test_pattern" | while read test_name ; do
|
2016-08-22 09:13:18 +00:00
|
|
|
test_single "$test_name"
|
2016-08-22 09:51:03 +00:00
|
|
|
if [ $? -ne 0 ] ; then
|
2016-09-07 12:24:11 +00:00
|
|
|
create_statement=$(gh-ost-test-mysql-replica test -t -e "show create table _gh_ost_test_gho \G")
|
|
|
|
echo "$create_statement" >> $test_logfile
|
2016-08-22 09:51:03 +00:00
|
|
|
echo "+ FAIL"
|
|
|
|
return 1
|
|
|
|
else
|
2016-09-07 12:24:11 +00:00
|
|
|
echo
|
2016-08-22 09:51:03 +00:00
|
|
|
echo "+ pass"
|
|
|
|
fi
|
2016-08-22 13:43:00 +00:00
|
|
|
gh-ost-test-mysql-replica -e "start slave"
|
2016-08-22 09:13:18 +00:00
|
|
|
done
|
|
|
|
}
|
|
|
|
|
|
|
|
verify_master_and_replica
|
|
|
|
test_all
|