Files
percona-toolkit/t/lib/bash/collect.sh
Sveta Smirnova 9755074cd8 PT-2156 Fix tests for lib, part2 (#650)
* PT-2156 - Fix tests for lib

Fixed tests, broken by putting fix for PT-1554 into the library code, mostly by updating checksums.
Added AutoCommit option for test lib/QueryReview.t
Reset SQL mode to empty to allow TableChunker to work with invalid and zero dates

* PT-2156 - Fix tests for lib

Adjusted t/lib/SchemaIterator.t to work with version 8.0

* PT-2156 - Fix tests for lib

Adjusted b/t/lib/Processlist.t, so it reflects fix for PT-981

* PT-2156 - Fix tests for lib

Adjusted t/lib/HTTP/Micro.t, so it works with different order of parameters, returned at v.percona.com/
Adjusted test for empty files in t/lib/bash/collect.t
Disabled mysqladmin debug test in t/lib/bash/collect.t, because of PT-2242

* PT-2156 - Fix tests for lib

Added LC_NUMERRIC=POSIX into t/lib/bash/report_system_info.sh, so reports in tests are not environment-dependent
Updated expected results in t/lib/bash/report_system_info.sh, so they reflect new information, collected by pt-summary

* PT-2156 - Fix tests for lib

- Improved fix for PT-76, so it handles inline comments
- Added test case for PT-76
- Improved fix for PT-1720, so it ignores unrecognizable option only if it comes from the toolkit-wide files and still errors out if wrong option was passed via command line or the tool-specific option file.

* PT-2156 - Fix tests for lib

- Improved fix for PT-2102, so it finds running instance configuration file using PID and also does not break t/lib/bash/report_mysql_info.t test
- Removed unnecessary copy-paste from t/pt-mysql-summary/pt-2102.t test
- Adjusted number of collected files in t/lib/bash/collect_mysql_info.sh

* PT-2156 - Fix tests for lib

- Fix for PT-1543 and MyRocks collection were originally put only into lib/bash/report_mysql_info.shthat broke the logic of collecting data first, then formatting report from this data. This, in its turn, broke test t/lib/bash/report_mysql_info.sh/t/lib/bash/report_mysql_info.t, because CMD_MYSQL is not defined in this library. I rewrote these fixes, so they follow original logic of the tool (pt-mysql-summary)
- Added tests for keyring plugin, encrypted tables, and MyRocks for t/lib/bash/report_mysql_info.sh and t/pt-mysql-summary/pt-mysql-summary_encryption.t

* PT-2156 - Fix tests for lib

- Added FLUSH TABLES to t/lib/bash/collect.sh, so it does not fail opentables tests if run when more than 1000 tables open in the sandbox environment
- Changed number of expected sample files to reflect keyring colletion file

* PT-2156 - Fix tests for lib

- Added skip to some tests in lib that file when run with PXC, because not supported to work with PXC
- Adjusted configuration files for PXC, so they allow LOAD DATA/SELECT INTO OUTFILE commands
- Adjusted data samples, so they do not depend on auto increment values
- Fixed lib tests, failing with PXC

* PT-2156 - Fix tests for lib

Updated tests for pt-online-schema-change, so they work with PXC and skipped if designed for semi-synchronous replication setup

* PT-2156 - Fix tests for lib

- Added cluster-specific samples for t/lib/SchemaIterator.t
- Removed extra debugging print from t/pt-table-checksum/pt-1728.t

* PT-2156 - Fix tests for lib

Evgeniy's review on July 20

* Update t/lib/TableSyncer.t

Removed comment left after debugging

* Update t/pt-mysql-summary/pt-mysql-summary_encryption.t

Removed extra debug output

* PT-2156 - Fix tests for lib

Tabs to spaces
2023-08-02 14:50:21 +03:00

214 lines
5.5 KiB
Bash

#!/usr/bin/env bash
plan 22
TMPFILE="$TEST_PT_TMPDIR/parse-opts-output"
PT_TMPDIR="$TEST_PT_TMPDIR"
PATH="$PATH:$PERCONA_TOOLKIT_SANDBOX/bin"
TOOL="pt-stalk"
mkdir "$PT_TMPDIR/collect" 2>/dev/null
source "$LIB_DIR/log_warn_die.sh"
source "$LIB_DIR/subshell.sh"
source "$LIB_DIR/parse_options.sh"
source "$LIB_DIR/safeguards.sh"
source "$LIB_DIR/alt_cmds.sh"
source "$LIB_DIR/collect.sh"
# We need flush tables, otherwise we won't have stable results for opentables tests
CMD_MYSQL="$(_which mysql)"
$CMD_MYSQL --defaults-file=/tmp/12345/my.sandbox.cnf -ss -e 'FLUSH TABLES'
parse_options "$BIN_DIR/pt-stalk" --run-time 1 -- --defaults-file=/tmp/12345/my.sandbox.cnf
# Prefix (with path) for the collect files.
p="$PT_TMPDIR/collect/2011_12_05"
# Default collect, no extras like gdb, tcpdump, etc.
collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1
wait_for_files "$p-hostname" "$p-opentables2" "$p-variables" "$p-df" "$p-innodbstatus2"
# Even if this system doesn't have all the cmds, collect should still
# have created some files for cmds that (hopefully) all systems have.
ls -1 $PT_TMPDIR/collect | sort > $PT_TMPDIR/collect-files
# If this system has /proc, then some files should be collected.
# Else, those files should not exist.
if [ -f /proc/diskstats ]; then
cmd_ok \
"grep -q '[0-9]' $PT_TMPDIR/collect/2011_12_05-diskstats" \
"/proc/diskstats"
else
test -f $PT_TMPDIR/collect/2011_12_05-diskstats
is "$?" "1" "No /proc/diskstats"
fi
cmd_ok \
"grep -q '\-hostname\$' $PT_TMPDIR/collect-files" \
"Collected hostname"
cmd_ok \
"grep -q 'Avail' $p-df" \
"df"
# hostname is the last thing collected, so if it's ok,
# then the sub reached its end.
is \
"`cat $p-hostname`" \
"`hostname`" \
"hostname"
cmd_ok \
"grep -q -i 'buffer pool' $p-innodbstatus1" \
"innodbstatus1"
cmd_ok \
"grep -q -i 'buffer pool' $p-innodbstatus2" \
"innodbstatus2"
cmd_ok \
"grep -q 'error log seems to be .*/mysqld.log' $p-output" \
"Finds MySQL error log"
if [ "$(which lsof 2>/dev/null)" ]; then
cmd_ok \
"grep -q 'COMMAND[ ]\+PID[ ]\+USER' $p-lsof" \
"lsof"
else
is "1" "1" "SKIP lsof not in PATH"
fi
cmd_ok \
"grep -q -e OS_waits -e Type $p-mutex-status1" \
"mutex-status1"
cmd_ok \
"grep -q -e OS_waits -e Type $p-mutex-status2" \
"mutex-status2"
cmd_ok \
"grep -q '^| Uptime' $p-mysqladmin" \
"mysqladmin ext"
cmd_ok \
"grep -qP 'Database\tTable\tIn_use' $p-opentables1" \
"opentables1"
cmd_ok \
"grep -qP 'Database\tTable\t\In_use' $p-opentables2" \
"opentables2"
cmd_ok \
"grep -q '1. row' $p-processlist" \
"processlist"
cmd_ok \
"grep -q 'mysqld' $p-ps" \
"ps"
cmd_ok \
"grep -qP '^wait_timeout\t\d' $p-variables" \
"variables"
iters=$(cat $p-df | grep -c '^TS ')
is "$iters" "1" "1 iteration/1s run time"
empty_files=0
for file in $p-*; do
if ! [ -s $file ]; then
empty_files=1
break
fi
# We need additional check here in case if first match
# is empty string.
if [ 0 -eq "$(grep -vc '^TS ' --max-count 1 $file)" ] ||
[ 0 -eq "$(grep -vc '^$' --max-count 1 $file)" ]; then
empty_files=1
break
fi
done
is "$empty_files" "0" "No empty files"
# ###########################################################################
# Debug option for mysqladmin is not default now, we will test it separately.
# ###########################################################################
#Skipping until PT-2242 is fixed
if false; then
parse_options "$BIN_DIR/pt-stalk" --run-time 2 -- --defaults-file=/tmp/12345/my.sandbox.cnf
rm $PT_TMPDIR/collect/*
# Prefix (with path) for the collect files.
p="$PT_TMPDIR/collect/2011_12_05"
CMD_MYSQLADMIN="mysqladmin debug"
# Default collect, no extras like gdb, tcpdump, etc.
collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1
wait_for_files "$p-hostname" "$p-opentables2" "$p-variables" "$p-df" "$p-innodbstatus2"
if [[ "$SANDBOX_VERSION" > "5.0" ]]; then
wait_for_files "$p-log_error"
cmd_ok \
"grep -qE 'Memory status|Open streams|Begin safemalloc' $p-log_error" \
"debug"
else
is "1" "1" "SKIP Can't determine MySQL 5.0 error log"
fi
else
is "1" "1" "SKIP until PT-2242 is fixed"
fi
# ###########################################################################
# Try longer run time.
# ###########################################################################
parse_options "$BIN_DIR/pt-stalk" --run-time 2 -- --defaults-file=/tmp/12345/my.sandbox.cnf
rm $PT_TMPDIR/collect/*
fake_opcontrol="$PT_TMPDIR/collect/fake_opcontrol"
fake_out="$PT_TMPDIR/collect/pt-faked-opcontrol-out"
cat <<FAKE_EXEC > "$fake_opcontrol"
#!/bin/sh
echo "Faked opcontrol: \$@" > "$fake_out"
exit 1
FAKE_EXEC
chmod +x "$fake_opcontrol"
CMD_OPCONTROL="$fake_opcontrol"
OPT_COLLECT_OPROFILE=1
collect "$PT_TMPDIR/collect" "2011_12_05" > $p-output 2>&1
CMD_OPCONTROL=""
OPT_COLLECT_OPROFILE=""
iters=$(cat $p-df | grep -c '^TS ')
is "$iters" "2" "2 iteration/2s run time"
is \
"$(cat "$fake_out")" \
"Faked opcontrol: --init" \
"Bug 986847: Can manually set which commands pt-stalk uses"
if [ -f "$p-vmstat" ]; then
n=$(awk '/[ ]*[0-9]/ { n += 1 } END { print n }' "$p-vmstat")
is \
"$n" \
"2" \
"vmstat runs for --run-time seconds (bug 955860)"
else
is "1" "1" "SKIP vmstat not installed"
fi
# ############################################################################
# Done
# ############################################################################