Add scripts/dockerfile for running _a_ localtest in docker

This commit is contained in:
Andrew Mason 2020-07-06 08:49:39 -04:00
parent 84f083dbdd
commit 7585b12bce
3 changed files with 141 additions and 0 deletions

33
Dockerfile.itest Normal file
View File

@ -0,0 +1,33 @@
# See https://gist.github.com/ajm188/9488bc9c2b5b10d645f5e168e94cfb77
# for why this is xenial
FROM ubuntu:xenial
ARG DBDEPLOYER_VERSION=1.52.0
ARG MYSQL_VERSION_APT=5.7
ARG MYSQL_VERSION=5.7.26
RUN echo ${MYSQL_VERSION} > /mysql_version
# We install mysql-server as a hack to make sure dbdeployer has all libs it
# needs to run mysqls.
RUN apt-get update \
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
ca-certificates \
mysql-server-${MYSQL_VERSION_APT} \
wget \
&& apt-get autoremove
RUN wget https://github.com/datacharmer/dbdeployer/releases/download/v${DBDEPLOYER_VERSION}/dbdeployer-${DBDEPLOYER_VERSION}.linux.tar.gz \
&& tar -xzvf dbdeployer-${DBDEPLOYER_VERSION}.linux.tar.gz \
&& chmod +x dbdeployer-${DBDEPLOYER_VERSION}.linux \
&& mv dbdeployer-${DBDEPLOYER_VERSION}.linux /usr/local/bin/dbdeployer
RUN dbdeployer init --skip-all-downloads --skip-shell-completion \
&& dbdeployer downloads get-by-version ${MYSQL_VERSION} --minimal \
&& dbdeployer unpack mysql-${MYSQL_VERSION}.tar.xz --unpack-version ${MYSQL_VERSION}
ADD itest.sh /itest.sh
ADD bin/gh-ost /usr/local/bin/gh-ost
ADD localtests /localtests
CMD ["/itest.sh"]

100
itest.sh Executable file
View File

@ -0,0 +1,100 @@
#!/bin/bash
#
#/ Usage: itest.sh [opts] [test_pattern]
#/
#/ Options:
#/ --gh-ost-binary | -b path to gh-ost binary. defaults to /tmp/gh-ost-test
usage() {
code="$1"
u="$(grep "^#/" "$0" | cut -c"4-")"
if [ "$code" -ne 0 ]; then echo "$u" >&2; else echo "$u"; fi
exit "$code"
}
GHOST_BINARY=
while [ "$#" -gt 0 ];
do
case "$1" in
--gh-ost-binary|-b) GHOST_BINARY="$2"; shift 2;;
--gh-ost-binary=*) GHOST_BINARY="$(echo "$1" | cut -d"=" -f"2-")"; shift;;
--help|-h) usage 0;;
-*) usage 1;;
*) ;;
esac
done
TEST_PATTERN="${1:-.}"
if [ -f /mysql_version ];
then
MYSQL_VERSION="$(cat /mysql_version)"
else
MYSQL_VERSION="5.7.26"
fi
echo "Creating replication sandbox"
dbdeployer deploy replication $MYSQL_VERSION \
--my-cnf-options log_slave_updates \
--my-cnf-options log_bin \
--my-cnf-options binlog_format=ROW \
--sandbox-directory gh-ost-test
echo "Creating gh-ost user"
/root/sandboxes/gh-ost-test/m -uroot -e"CREATE USER IF NOT EXISTS 'gh-ost'@'%' IDENTIFIED BY 'gh-ost'"
/root/sandboxes/gh-ost-test/m -uroot -e"GRANT ALL ON *.* TO 'gh-ost'@'%'"
echo "Reading database topology"
master_host="127.0.0.1"
master_port="$(/root/sandboxes/gh-ost-test/m -e"select @@port" -ss)"
replica_host="127.0.0.1"
replica_port="$(/root/sandboxes/gh-ost-test/s1 -e"select @@port" -ss)"
test_path=localtests/trivial
throttle_flag_file=trivial.trottle-flag
extra_args=""
if [ -f $test_path/extra_args ];
then
extra_args="$(cat $test_path/extra_args)"
fi
echo "Setting up test case"
/root/sandboxes/gh-ost-test/m -uroot test <$test_path/create.sql
echo "Running gh-ost"
/usr/local/bin/gh-ost \
--user=gh-ost \
--password=gh-ost \
--host="$replica_host" \
--port="$replica_port" \
--assume-master-host="${master_host}:${master_port}" \
--database=test \
--table=gh_ost_test \
--alter='engine=innodb' \
--exact-rowcount \
--assume-rbr \
--initially-drop-old-table \
--initially-drop-ghost-table \
--throttle-query='select timestampdiff(second, min(last_update), now()) < 5 from _gh_ost_test_ghc' \
--throttle-flag-file=$throttle_flag_file \
--serve-socket-file=/tmp/gh-ost.test.sock \
--initially-drop-socket-file \
--test-on-replica \
--default-retries=3 \
--chunk-size=10 \
--verbose \
--debug \
--stack \
--execute "${extra_args[@]}" 1>trivial.log 2>&1
result=$?
if [ $result -ne 0 ];
then
echo
echo "ERROR execution failure"
cat trivial.log
exit 1
fi
echo "Success!"

8
script/itest Executable file
View File

@ -0,0 +1,8 @@
#!/bin/sh
#
# Wrapper for running integration tests in docker.
./script/dock pkg $(pwd)/bin
docker build -t itest -f Dockerfile.itest .
docker run --rm itest