ctdb-tests: Update preamble for INTEGRATION tests
[vlendec/samba-autobuild/.git] / ctdb / tests / INTEGRATION / simple / basics.011.statistics_reset.sh
1 #!/usr/bin/env bash
2
3 # Verify that 'ctdb statisticsreset' works as expected
4
5 # This is pretty superficial.  It just checks that a few particular
6 # items reduce.
7
8 . "${TEST_SCRIPTS_DIR}/integration.bash"
9
10 set -e
11
12 ctdb_test_init
13
14 try_command_on_node 0 "$CTDB listnodes | wc -l"
15 num_nodes="$out"
16
17 get_stat ()
18 {
19         local label="$1"
20
21         cat "$outfile" |
22         sed -rn -e "s@^[[:space:]]+${label}[[:space:]]+([[:digit:]])@\1@p" |
23         head -1
24 }
25
26 check_reduced ()
27 {
28     local label="$1"
29     local before="$2"
30     local after="$3"
31
32     if [ $after -lt $before ] ; then
33         echo "GOOD: ${label} reduced from ${before} to ${after}"
34     else
35         die "BAD: ${label} did not reduce from ${before} to ${after}"
36     fi
37 }
38
39 n=0
40 while [ $n -lt $num_nodes ] ; do
41     echo "Getting initial statistics for node ${n}..."
42
43     try_command_on_node -v $n $CTDB statistics
44
45     before_req_control=$(get_stat "req_control")
46     before_reply_control=$(get_stat "reply_control")
47     before_node_packets_recv=$(get_stat "node_packets_recv")
48
49     try_command_on_node $n $CTDB statisticsreset
50
51     try_command_on_node -v $n $CTDB statistics
52
53     after_req_control=$(get_stat "req_control")
54     after_reply_control=$(get_stat "reply_control")
55     after_node_packets_recv=$(get_stat "node_packets_recv")
56
57     check_reduced "req_control" "$before_req_control" "$after_req_control"
58     check_reduced "reply_control" "$before_reply_control" "$after_reply_control"
59     check_reduced "node_packets_recv" "$before_node_packets_recv" "$after_node_packets_recv"
60
61     n=$(($n + 1))
62 done