latency-monitor.tcl 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. start_server {tags {"latency-monitor"}} {
  2. # Set a threshold high enough to avoid spurious latency events.
  3. r config set latency-monitor-threshold 200
  4. r latency reset
  5. test {Test latency events logging} {
  6. r debug sleep 0.3
  7. after 1100
  8. r debug sleep 0.4
  9. after 1100
  10. r debug sleep 0.5
  11. assert {[r latency history command] >= 3}
  12. }
  13. test {LATENCY HISTORY output is ok} {
  14. set min 250
  15. set max 450
  16. foreach event [r latency history command] {
  17. lassign $event time latency
  18. assert {$latency >= $min && $latency <= $max}
  19. incr min 100
  20. incr max 100
  21. set last_time $time ; # Used in the next test
  22. }
  23. }
  24. test {LATENCY LATEST output is ok} {
  25. foreach event [r latency latest] {
  26. lassign $event eventname time latency max
  27. assert {$eventname eq "command"}
  28. assert {$max >= 450 & $max <= 650}
  29. assert {$time == $last_time}
  30. break
  31. }
  32. }
  33. test {LATENCY HISTORY / RESET with wrong event name is fine} {
  34. assert {[llength [r latency history blabla]] == 0}
  35. assert {[r latency reset blabla] == 0}
  36. }
  37. test {LATENCY DOCTOR produces some output} {
  38. assert {[string length [r latency doctor]] > 0}
  39. }
  40. test {LATENCY RESET is able to reset events} {
  41. assert {[r latency reset] > 0}
  42. assert {[r latency latest] eq {}}
  43. }
  44. test {LATENCY of expire events are correctly collected} {
  45. r config set latency-monitor-threshold 20
  46. r flushdb
  47. if {$::valgrind} {set count 100000} else {set count 1000000}
  48. r eval {
  49. local i = 0
  50. while (i < tonumber(ARGV[1])) do
  51. redis.call('sadd',KEYS[1],i)
  52. i = i+1
  53. end
  54. } 1 mybigkey $count
  55. r pexpire mybigkey 50
  56. wait_for_condition 5 100 {
  57. [r dbsize] == 0
  58. } else {
  59. fail "key wasn't expired"
  60. }
  61. assert_match {*expire-cycle*} [r latency latest]
  62. }
  63. test {LATENCY HELP should not have unexpected options} {
  64. catch {r LATENCY help xxx} e
  65. assert_match "*Unknown subcommand or wrong number of arguments*" $e
  66. }
  67. }