Test suite: better debug info when the cluster is unexpectedly unhealthy.
[tridge/ctdb.git] / tests / simple / 51_ctdb_bench.sh
1 #!/bin/bash
2
3 test_info()
4 {
5     cat <<EOF
6 Run the ctdb_bench test and sanity check the output.
7
8 This doesn't test for performance regressions or similarly anything
9 useful.  Only vague sanity checking of results is done.
10
11 Prerequisites:
12
13 * An active CTDB cluster with at least 2 active nodes.
14
15 Steps:
16
17 1. Verify that the status on all of the ctdb nodes is 'OK'.
18 2. Run ctdb_bench on all nodes with default options.
19 3. Ensure that the number of +ve and -ive messages are within 1% of
20    each other.
21 4. Ensure that the number of messages per second is greater than 10.
22
23 Expected results:
24
25 * ctdb_bench runs without error and prints reasonable results.
26 EOF
27 }
28
29 . ctdb_test_functions.bash
30
31 ctdb_test_init "$@"
32
33 set -e
34
35 cluster_is_healthy
36
37 try_command_on_node 0 "$CTDB listnodes"
38 num_nodes=$(echo "$out" | wc -l)
39
40 echo "Running ctdb_bench on all $num_nodes nodes."
41 try_command_on_node -v -pq all $CTDB_TEST_WRAPPER $VALGRIND ctdb_bench -n $num_nodes
42
43 # Get the last line of output.
44 while read line ; do
45     prev=$line
46 done <<<"$out"
47
48 pat='^(Ring: [[:digit:]]+(\.[[:digit:]]+)? msgs/sec \(\+ve=[[:digit:]]+ -ve=[[:digit:]]+\)[[:space:]]?|Waiting for cluster[[:space:]]?)+$'
49 sanity_check_output 1 "$pat" "$out"
50
51 # $prev should look like this:
52 #    Ring: 10670.93 msgs/sec (+ve=53391 -ve=53373)
53 stuff="${prev##*Ring: }"
54 mps="${stuff% msgs/sec*}"
55
56 if [ ${mps%.*} -ge 10 ] ; then
57     echo "OK: $mps msgs/sec >= 10 msgs/sec"
58 else
59     echo "BAD: $mps msgs/sec < 10 msgs/sec"
60     exit 1
61 fi
62
63 stuff="${stuff#*msgs/sec (+ve=}"
64 positive="${stuff%% *}"
65
66 if [ $positive -gt 0 ] ; then
67     echo "OK: +ive ($positive) > 0"
68 else
69     echo "BAD: +ive ($positive) = 0"
70     exit 1
71 fi
72
73 stuff="${stuff#*-ve=}"
74 negative="${stuff%)}"
75
76 if [ $negative -gt 0 ] ; then
77     echo "OK: -ive ($negative) > 0"
78 else
79     echo "BAD: -ive ($negative) = 0"
80     exit 1
81 fi
82
83 perc_diff=$(( ($positive - $negative) * 100 / $positive ))
84 perc_diff=${perc_diff#-}
85
86 check_percent=5
87 if [ $perc_diff -le $check_percent ] ; then
88     echo "OK: percentage difference between +ive and -ive ($perc_diff%) <= $check_percent%"
89 else
90     echo "BAD: percentage difference between +ive and -ive ($perc_diff%) > $check_percent%"
91     exit 1
92 fi