From 43fd85a99b4e05b24ea3de32bcda36a57f862755 Mon Sep 17 00:00:00 2001 From: Miro Stauder Date: Wed, 17 Apr 2024 10:03:02 +0000 Subject: [PATCH] add tap test for flush logs --- test/tap/tests/Makefile | 6 ++ test/tap/tests/test_flush_logs-t.sh | 90 +++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) create mode 100755 test/tap/tests/test_flush_logs-t.sh diff --git a/test/tap/tests/Makefile b/test/tap/tests/Makefile index f4f29da9c..fca9b3137 100644 --- a/test/tap/tests/Makefile +++ b/test/tap/tests/Makefile @@ -175,6 +175,7 @@ debug: tests tests: tests-cpp \ tests-php \ tests-py \ + tests-sh \ setparser_test \ reg_test_3504-change_user_libmariadb_helper \ reg_test_3504-change_user_libmysql_helper \ @@ -191,6 +192,7 @@ tests: tests-cpp \ tests-cpp: $(patsubst %.cpp,%,$(wildcard *-t.cpp)) tests-php: $(patsubst %,php-%,$(wildcard *-t.php)) tests-py: $(patsubst %,py-%,$(wildcard *-t.py)) +tests-sh: $(patsubst %,sh-%,$(wildcard *-t.sh)) testgalera: galera_1_timeout_count galera_2_timeout_no_count testaurora: aurora @@ -222,6 +224,10 @@ py-%: cp $(patsubst py-%,%,$@) $(patsubst py-%.py,%,$@) chmod +x $(patsubst py-%.py,%,$@) +sh-%: + cp $(patsubst sh-%,%,$@) $(patsubst sh-%.sh,%,$@) + chmod +x $(patsubst sh-%.sh,%,$@) + %-t: %-t.cpp $(TAP_LDIR)/libtap.so $(CXX) $< $(IDIRS) $(LDIRS) $(OPT) $(MYLIBS) $(STATIC_LIBS) -o $@ # $(CXX) $< $(IDIRS) $(LDIRS) $(OPT) $(MYLIBS) -lpthread -ldl $(STATIC_LIBS) $(TAP_LDIR)/libtap.so -o $@ diff --git a/test/tap/tests/test_flush_logs-t.sh b/test/tap/tests/test_flush_logs-t.sh new file mode 100755 index 000000000..4ec8f87a6 --- /dev/null +++ b/test/tap/tests/test_flush_logs-t.sh @@ -0,0 +1,90 @@ +#!/usr/bin/env bash +# +# test proxysql log flushing mechanisms +# - PROXYSQL FLUSH LOGS command +# - SIGUSR1 signal +# + +# change plan here, 0 means auto plan +PLAN=0 +DONE=0 +FAIL=0 + +trap fn_exit EXIT +trap fn_exit SIGINT + +PROXYSQL_PATH=$(while [ ! -f ./src/proxysql_global.cpp ]; do cd ..; done; pwd) +PROXYSQL_LOGS=${REGULAR_INFRA_DATADIR:-$PROXYSQL_PATH/src} + +fn_getenv () { + source .env 2>/dev/null + source $(basename $(dirname $0)).env 2>/dev/null + source $(basename $0 | sed 's/.sh//').env 2>/dev/null +} + +fn_plan () { + PLAN=${1:-$PLAN} + echo "msg: 1..${PLAN/#0/}" +} + +fn_exit () { + trap - EXIT + trap - SIGINT + if [[ $DONE -eq $PLAN ]] && [[ $FAIL -eq 0 ]]; then + echo "msg: Test took $SECONDS sec" + exit 0 + else + echo "msg: plan was $PLAN - done $DONE" + echo "msg: from $DONE done - $FAIL failed" + echo "msg: Test took $SECONDS sec" + exit 1 + fi +} + +fn_padmin () { + mysql -u${TAP_ADMINUSERNAME:-admin} -p${TAP_ADMINPASSWORD:-admin} -h${TAP_ADMINHOST:-127.0.0.1} -P${TAP_ADMINPORT:-6032} -e "${1}" 2>&1 | grep -vP "mysql: .?Warning" +} + +fn_signal () { + # send signal to all - watchdog and worker processes +# ps aux | grep -P 'proxysql ' | grep -v 'grep' | awk '{ print $2 }' | sudo xargs -n1 kill -s ${1} + # send signal only to worker processes +# ps aux | grep -P 'proxysql ' | grep -v 'grep' | awk '{ print $2 }' | sort -n | sed '1 !d' | sudo xargs -n1 kill -s ${1} + sudo netstat -ntpl | grep proxysql | tr '/' ' ' | awk '{ print $7 }' | sort | uniq | sudo xargs -r -n1 kill -s ${1} +} + +fn_get_rotations () { + sleep 1 + cat $PROXYSQL_LOGS/proxysql.log | grep '\[INFO\] ProxySQL version' | wc -l +} + +fn_check_res () { + DONE=$(( $DONE + 1 )) + PLAN=$([[ $PLAN -lt $DONE ]] && echo $DONE || echo $PLAN) + if [[ $RES -ne $(( $BASELINE + 1)) ]]; then + echo "msg: not ok $DONE - command '$1' - initial BASELINE: $BASELINE - expected BASELINE + 1 : got $RES" + FAIL=$(( $FAIL + 1 )) + else + echo "msg: ok $DONE - command '$1' - initial BASELINE: $BASELINE - expected BASELINE + 1 : got $RES" + fi +} + +# test init +fn_getenv +fn_plan + + +# test PROXYSQL FLUSH LOGS +BASELINE=$(fn_get_rotations) +fn_padmin "PROXYSQL FLUSH LOGS;" +RES=$(fn_get_rotations) +fn_check_res "PROXYSQL FLUSH LOGS;" + +# test SIGUSR1 signal +BASELINE=$(fn_get_rotations) +fn_signal "SIGUSR1" +RES=$(fn_get_rotations) +fn_check_res "kill -s SIGUSR1 \$PID" + + +# test done