Skip to content

Commit

Permalink
add tap test for flush logs
Browse files Browse the repository at this point in the history
  • Loading branch information
mirostauder committed Apr 19, 2024
1 parent c6c370d commit 43fd85a
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 0 deletions.
6 changes: 6 additions & 0 deletions test/tap/tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand All @@ -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

Expand Down Expand Up @@ -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 $@
Expand Down
90 changes: 90 additions & 0 deletions test/tap/tests/test_flush_logs-t.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 43fd85a

Please sign in to comment.