2
0

latency-monitor.tcl 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. start_server {tags {"latency-monitor needs:latency"}} {
  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. if {!$::no_latency} {
  19. assert {$latency >= $min && $latency <= $max}
  20. }
  21. incr min 100
  22. incr max 100
  23. set last_time $time ; # Used in the next test
  24. }
  25. }
  26. test {LATENCY LATEST output is ok} {
  27. foreach event [r latency latest] {
  28. lassign $event eventname time latency max
  29. assert {$eventname eq "command"}
  30. if {!$::no_latency} {
  31. assert {$max >= 450 & $max <= 650}
  32. assert {$time == $last_time}
  33. }
  34. break
  35. }
  36. }
  37. test {LATENCY HISTORY / RESET with wrong event name is fine} {
  38. assert {[llength [r latency history blabla]] == 0}
  39. assert {[r latency reset blabla] == 0}
  40. }
  41. test {LATENCY DOCTOR produces some output} {
  42. assert {[string length [r latency doctor]] > 0}
  43. }
  44. test {LATENCY RESET is able to reset events} {
  45. assert {[r latency reset] > 0}
  46. assert {[r latency latest] eq {}}
  47. }
  48. test {LATENCY of expire events are correctly collected} {
  49. r config set latency-monitor-threshold 20
  50. r flushdb
  51. if {$::valgrind} {set count 100000} else {set count 1000000}
  52. r eval {
  53. local i = 0
  54. while (i < tonumber(ARGV[1])) do
  55. redis.call('sadd',KEYS[1],i)
  56. i = i+1
  57. end
  58. } 1 mybigkey $count
  59. r pexpire mybigkey 50
  60. wait_for_condition 5 100 {
  61. [r dbsize] == 0
  62. } else {
  63. fail "key wasn't expired"
  64. }
  65. assert_match {*expire-cycle*} [r latency latest]
  66. }
  67. test {LATENCY HELP should not have unexpected options} {
  68. catch {r LATENCY help xxx} e
  69. assert_match "*wrong number of arguments*" $e
  70. }
  71. }