1# This simple script is used in order to estimate the average PFAIL->FAIL
2# state switch after a failure.
3
4set ::sleep_time 10     ; # How much to sleep to trigger PFAIL.
5set ::fail_port 30016   ; # Node to put in sleep.
6set ::other_port 30001  ; # Node to use to monitor the flag switch.
7
8proc avg vector {
9    set sum 0.0
10    foreach x $vector {
11        set sum [expr {$sum+$x}]
12    }
13    expr {$sum/[llength $vector]}
14}
15
16set samples {}
17while 1 {
18    exec redis-cli -p $::fail_port debug sleep $::sleep_time > /dev/null &
19
20    # Wait for fail? to appear.
21    while 1 {
22        set output [exec redis-cli -p $::other_port cluster nodes]
23        if {[string match {*fail\?*} $output]} break
24        after 100
25    }
26
27    puts "FAIL?"
28    set start [clock milliseconds]
29
30    # Wait for fail? to disappear.
31    while 1 {
32        set output [exec redis-cli -p $::other_port cluster nodes]
33        if {![string match {*fail\?*} $output]} break
34        after 100
35    }
36
37    puts "FAIL"
38    set now [clock milliseconds]
39    set elapsed [expr {$now-$start}]
40    puts $elapsed
41    lappend samples $elapsed
42
43    puts "AVG([llength $samples]): [avg $samples]"
44
45    # Wait for the instance to be available again.
46    exec redis-cli -p $::fail_port ping
47
48    # Wait for the fail flag to be cleared.
49    after 2000
50}
51