diff --git a/bin/pt-stalk b/bin/pt-stalk index fd80baf5..93c79cc5 100755 --- a/bin/pt-stalk +++ b/bin/pt-stalk @@ -862,6 +862,16 @@ collect() { hostname > "$d/$p-hostname" + local slept=0 + while [ -n "$(jobs)" -a $slept -lt $OPT_RUN_TIME ]; do + sleep 1 + slept=$((slept + 1)) + done + + for pid in $(jobs -p); do + kill $pid >/dev/null 2>&1 + done + for file in "$d/$p-"*; do if [ -z "$(grep -v '^TS ' --max-count 1 "$file")" ]; then log "Removing empty file $file"; diff --git a/lib/bash/collect.sh b/lib/bash/collect.sh index 0b7013c8..87a614af 100644 --- a/lib/bash/collect.sh +++ b/lib/bash/collect.sh @@ -286,7 +286,19 @@ collect() { # Remove "empty" files, i.e. ones that are truly empty or # just contain timestamp lines. When a command above fails, - # it may leave an empty file. + # it may leave an empty file. But first wait another --run-time + # seconds for any slow process to finish: + # https://bugs.launchpad.net/percona-toolkit/+bug/1047701 + local slept=0 + while [ -n "$(jobs)" -a $slept -lt $OPT_RUN_TIME ]; do + sleep 1 + slept=$((slept + 1)) + done + + for pid in $(jobs -p); do + kill $pid >/dev/null 2>&1 + done + for file in "$d/$p-"*; do # If there's not at least 1 line that's not a TS, # then the file is empty. diff --git a/sandbox/jenkins-test b/sandbox/jenkins-test index 44266613..7c647749 100755 --- a/sandbox/jenkins-test +++ b/sandbox/jenkins-test @@ -59,6 +59,15 @@ export PERCONA_TOOLKIT_SANDBOX="$MYSQL_BASE_DIR" export PATH="$PATH:/usr/sbin:$MYSQL_BASE_DIR/bin" export LANG="en_US.UTF-8" +# ######################################### # +# Remove conf files that's shouldn't exist. # +# ######################################### # +rm -rf /tmp/pt-* || true +rm -rf /tmp/pt_* || true +rm -rf /tmp/percona* || true +rm ~/.pt-*conf* || true +rm ~/.my* || true + ############################# # Check and start test env. # ############################# diff --git a/t/pt-stalk/pt-stalk.t b/t/pt-stalk/pt-stalk.t index 4c3ead15..ed905eb0 100644 --- a/t/pt-stalk/pt-stalk.t +++ b/t/pt-stalk/pt-stalk.t @@ -149,9 +149,9 @@ like( # the samples may not be precisely 1 second apart. chomp($output = `cat $dest/*-df | grep -c '^TS'`); ok( - $output >= 1 && $output <= 2, + $output >= 1 && $output <= 3, "Collect ran for --run-time" -); +) or diag("Run time: $output"); ok( PerconaTest::not_running("pt-stalk --iterations 1"),