From 1572e088bf9fe801c6862520170de70825c718a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Sat, 11 Aug 2018 22:42:22 +0300 Subject: [PATCH] Run REST API and MaxCtrl unit tests Install Docker when building on CentOS 7. This allows the REST API and MaxCtrl unit tests to be run. --- BUILD/build_rpm_local.sh | 16 ++++++++++++++++ BUILD/install_build_deps.sh | 8 ++++++++ test/run_npm_test.sh | 12 +++++++++++- test/start_double_maxscale.sh | 21 ++++++++++----------- test/start_maxscale.sh | 7 +++++-- 5 files changed, 50 insertions(+), 14 deletions(-) diff --git a/BUILD/build_rpm_local.sh b/BUILD/build_rpm_local.sh index 42d9e7798..07b6492d1 100755 --- a/BUILD/build_rpm_local.sh +++ b/BUILD/build_rpm_local.sh @@ -16,6 +16,22 @@ if [[ "$cmake_flags" =~ "BUILD_TESTS" ]] then # All tests must pass otherwise the build is considered a failure ctest --output-on-failure || exit 1 + + # See if docker is installed and run REST API and MaxCtrl tests if it is + command -v docker + if [ $? -eq 0 ] + then + export SKIP_SHUTDOWN=Y + make test_rest_api && make test_maxctrl + rc=$? + #docker ps -aq|xargs docker rm -vf + + if [ $rc -ne 0 ] + then + cat maxscale_test/*.output maxscale_test/log/maxscale/*.log + exit 1 + fi + fi fi # Never strip binaries diff --git a/BUILD/install_build_deps.sh b/BUILD/install_build_deps.sh index 1a89a53e5..64d54048e 100755 --- a/BUILD/install_build_deps.sh +++ b/BUILD/install_build_deps.sh @@ -86,6 +86,14 @@ else # Enable it by default echo "source /opt/rh/devtoolset-7/enable" >> ~/.bashrc + else + # Installed for REST API and MaxCtrl unit tests + sudo yum -y install docker epel-release + sudo yum -y install docker-compose + sudo groupadd docker + sudo usermod -a -G docker `whoami` + sudo sed -i 's/--selinux-enabled/--selinux-enabled=false/' /etc/sysconfig/docker + sudo systemctl start docker fi fi diff --git a/test/run_npm_test.sh b/test/run_npm_test.sh index 9070e0b0f..8cd614f5b 100755 --- a/test/run_npm_test.sh +++ b/test/run_npm_test.sh @@ -84,7 +84,17 @@ do docker exec -i $node mysql -umaxuser -pmaxpwd -e "select 1" >& /dev/null && break sleep 1 done - echo "Done!" + + docker exec -i $node mysql -umaxuser -pmaxpwd -e "select 1" >& /dev/null + + if [ $? -ne 0 ] + then + echo "failed to start $node, error is:" + docker exec -i $node mysql -umaxuser -pmaxpwd -e "select 1" + exit 1 + else + echo "Done!" + fi done # Go to the test directory diff --git a/test/start_double_maxscale.sh b/test/start_double_maxscale.sh index a122e2dac..d4fc35e51 100755 --- a/test/start_double_maxscale.sh +++ b/test/start_double_maxscale.sh @@ -35,21 +35,20 @@ then fi # Start MaxScale -$maxscaledir/bin/maxscale $user_opt -f $maxscaledir/maxscale.cnf &>> $maxscaledir/maxscale1.output - -# Wait for the first MaxScale to start -for ((i=0;i<150;i++)) -do - $maxscaledir/bin/maxctrl list servers >& /dev/null && break - sleep 0.1 -done +$maxscaledir/bin/maxscale $user_opt -f $maxscaledir/maxscale.cnf &>> $maxscaledir/maxscale1.output || exit 1 # Start a second maxscale -$maxscaledir/bin/maxscale $user_opt -f $maxscaledir/maxscale_secondary.cnf &>> $maxscaledir/maxscale2.output +$maxscaledir/bin/maxscale $user_opt -f $maxscaledir/maxscale_secondary.cnf &>> $maxscaledir/maxscale2.output || exit 1 + +# Wait for the MaxScales to start -# Wait for the second MaxScale to start for ((i=0;i<150;i++)) do - $maxscaledir/bin/maxctrl --hosts 127.0.0.1:8990 list servers >& /dev/null && break + $maxscaledir/bin/maxctrl list servers >& /dev/null && \ + $maxscaledir/bin/maxctrl --hosts 127.0.0.1:8990 list servers >& /dev/null && \ + exit 0 sleep 0.1 done + +# MaxScales failed to start, exit with an error +exit 1 diff --git a/test/start_maxscale.sh b/test/start_maxscale.sh index d13b6c453..b53d9bcfa 100755 --- a/test/start_maxscale.sh +++ b/test/start_maxscale.sh @@ -25,11 +25,14 @@ then fi # Start MaxScale -$maxscaledir/bin/maxscale $user_opt -f $maxscaledir/maxscale.cnf &>> $maxscaledir/maxscale.output +$maxscaledir/bin/maxscale $user_opt -f $maxscaledir/maxscale.cnf &>> $maxscaledir/maxscale.output || exit 1 # Wait for MaxScale to start for ((i=0;i<150;i++)) do - $maxscaledir/bin/maxctrl list servers >& /dev/null && break + $maxscaledir/bin/maxctrl list servers >& /dev/null && exit 0 sleep 0.1 done + +# MaxScale failed to start, exit with an error +exit 1