slowlog.tcl 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. start_server {tags {"slowlog"} overrides {slowlog-log-slower-than 1000000}} {
  2. test {SLOWLOG - check that it starts with an empty log} {
  3. r slowlog len
  4. } {0}
  5. test {SLOWLOG - only logs commands taking more time than specified} {
  6. r config set slowlog-log-slower-than 100000
  7. r ping
  8. assert_equal [r slowlog len] 0
  9. r debug sleep 0.2
  10. assert_equal [r slowlog len] 1
  11. }
  12. test {SLOWLOG - max entries is correctly handled} {
  13. r config set slowlog-log-slower-than 0
  14. r config set slowlog-max-len 10
  15. for {set i 0} {$i < 100} {incr i} {
  16. r ping
  17. }
  18. r slowlog len
  19. } {10}
  20. test {SLOWLOG - GET optional argument to limit output len works} {
  21. llength [r slowlog get 5]
  22. } {5}
  23. test {SLOWLOG - RESET subcommand works} {
  24. r config set slowlog-log-slower-than 100000
  25. r slowlog reset
  26. r slowlog len
  27. } {0}
  28. test {SLOWLOG - logged entry sanity check} {
  29. r client setname foobar
  30. r debug sleep 0.2
  31. set e [lindex [r slowlog get] 0]
  32. assert_equal [llength $e] 6
  33. assert_equal [lindex $e 0] 105
  34. assert_equal [expr {[lindex $e 2] > 100000}] 1
  35. assert_equal [lindex $e 3] {debug sleep 0.2}
  36. assert_equal {foobar} [lindex $e 5]
  37. }
  38. test {SLOWLOG - commands with too many arguments are trimmed} {
  39. r config set slowlog-log-slower-than 0
  40. r slowlog reset
  41. r sadd set 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
  42. set e [lindex [r slowlog get] 0]
  43. lindex $e 3
  44. } {sadd set 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 {... (2 more arguments)}}
  45. test {SLOWLOG - too long arguments are trimmed} {
  46. r config set slowlog-log-slower-than 0
  47. r slowlog reset
  48. set arg [string repeat A 129]
  49. r sadd set foo $arg
  50. set e [lindex [r slowlog get] 0]
  51. lindex $e 3
  52. } {sadd set foo {AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA... (1 more bytes)}}
  53. test {SLOWLOG - EXEC is not logged, just executed commands} {
  54. r config set slowlog-log-slower-than 100000
  55. r slowlog reset
  56. assert_equal [r slowlog len] 0
  57. r multi
  58. r debug sleep 0.2
  59. r exec
  60. assert_equal [r slowlog len] 1
  61. set e [lindex [r slowlog get] 0]
  62. assert_equal [lindex $e 3] {debug sleep 0.2}
  63. }
  64. test {SLOWLOG - can clean older entires} {
  65. r client setname lastentry_client
  66. r config set slowlog-max-len 1
  67. r debug sleep 0.2
  68. assert {[llength [r slowlog get]] == 1}
  69. set e [lindex [r slowlog get] 0]
  70. assert_equal {lastentry_client} [lindex $e 5]
  71. }
  72. }