From 12649ef49bc5ac71ece57c929b9466e94d05a15e Mon Sep 17 00:00:00 2001 From: root Date: Thu, 14 Jan 2016 20:20:39 +0800 Subject: [PATCH] test: add unitest test_pidfile.sh Fixes: #13422 Signed-off-by: shun song --- src/test/Makefile.am | 3 +- src/test/test_pidfile.sh | 76 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100755 src/test/test_pidfile.sh diff --git a/src/test/Makefile.am b/src/test/Makefile.am index a9d3dbdf5c1..02c6cae5ca8 100644 --- a/src/test/Makefile.am +++ b/src/test/Makefile.am @@ -89,7 +89,8 @@ check_SCRIPTS += \ test/osd/osd-markdown.sh \ test/mon/mon-handle-forward.sh \ test/libradosstriper/rados-striper.sh \ - test/test_objectstore_memstore.sh + test/test_objectstore_memstore.sh \ + test/test_pidfile.sh check_SCRIPTS += test/ceph-disk.sh diff --git a/src/test/test_pidfile.sh b/src/test/test_pidfile.sh new file mode 100755 index 00000000000..2a5cb27c654 --- /dev/null +++ b/src/test/test_pidfile.sh @@ -0,0 +1,76 @@ +#!/bin/bash + +# +# test pidfile here +# + +# Includes +source ../qa/workunits/ceph-helpers.sh + +function run() { + local dir=$1 + shift + + export CEPH_MON="127.0.0.1:17108" + export CEPH_ARGS + CEPH_ARGS+="--fsid=$(uuidgen) --auth-supported=none " + CEPH_ARGS+="--mon-host=$CEPH_MON " + + local funcs=${@:-$(set | sed -n -e 's/^\(TEST_[0-9a-z_]*\) .*/\1/p')} + for func in $funcs ; do + $func $dir || return 1 + done +} + +function TEST_without_pidfile() { + local dir=$1 + setup $dir + local RUNID=`uuidgen` + run_mon $dir a --pid-file= --daemonize=$RUNID || { teardown_unexist_pidfile $dir; return 1; } + run_osd $dir 0 --pid-file= --daemonize=$RUNID || { teardown_unexist_pidfile $dir; return 1; } + teardown_unexist_pidfile $dir $RUNID || return 1 +} + +function teardown_unexist_pidfile() { + local dir=$1 + shift + local RUNID=$1 + shift + local delays=${4:-0 0 1 1 1 2 3 5 5 5 10 10 20 60 60 60 120} + local pids=$(ps aux|awk "/cep[h].*$RUNID.*/ {print \$2}") + local status=0 + for i in $pids ; do + local kill_complete=false + for try in $delays ; do + if kill $i 2> /dev/null ; then + kill_complete=false + sleep $try + else + kill_complete=true + break + fi + done + if ! $kill_complete ; then + status=1 + fi + done + if [ $(stat -f -c '%T' .) == "btrfs" ]; then + __teardown_btrfs $dir + fi + rm -fr $dir + return $status +} + +function TEST_contend_pidfile() { + local dir=$1 + setup $dir + + run_mon $dir a + run_mon $dir a 2>&1 | grep "failed to lock pidfile" || return 1 + + run_osd $dir 0 + run_osd $dir 0 2>&1 | grep "failed to lock pidfile" || return 1 + teardown $dir || return 1 +} + +main pidfile -- 2.47.3