1
0

blockonbackground.tcl 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. set testmodule [file normalize tests/modules/blockonbackground.so]
  2. source tests/support/util.tcl
  3. start_server {tags {"modules"}} {
  4. r module load $testmodule
  5. test { blocked clients time tracking - check blocked command that uses RedisModule_BlockedClientMeasureTimeStart() is tracking background time} {
  6. r slowlog reset
  7. r config set slowlog-log-slower-than 200000
  8. if {!$::no_latency} {
  9. assert_equal [r slowlog len] 0
  10. }
  11. r block.debug 0 10000
  12. if {!$::no_latency} {
  13. assert_equal [r slowlog len] 0
  14. }
  15. r config resetstat
  16. r block.debug 200 10000
  17. if {!$::no_latency} {
  18. assert_equal [r slowlog len] 1
  19. }
  20. set cmdstatline [cmdrstat block.debug r]
  21. regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call
  22. assert {$usec >= 100000}
  23. assert {$usec_per_call >= 100000}
  24. }
  25. test { blocked clients time tracking - check blocked command that uses RedisModule_BlockedClientMeasureTimeStart() is tracking background time even in timeout } {
  26. r slowlog reset
  27. r config set slowlog-log-slower-than 200000
  28. if {!$::no_latency} {
  29. assert_equal [r slowlog len] 0
  30. }
  31. r block.debug 0 20000
  32. if {!$::no_latency} {
  33. assert_equal [r slowlog len] 0
  34. }
  35. r config resetstat
  36. r block.debug 20000 500
  37. if {!$::no_latency} {
  38. assert_equal [r slowlog len] 1
  39. }
  40. set cmdstatline [cmdrstat block.debug r]
  41. regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call
  42. assert {$usec >= 250000}
  43. assert {$usec_per_call >= 250000}
  44. }
  45. test { blocked clients time tracking - check blocked command with multiple calls RedisModule_BlockedClientMeasureTimeStart() is tracking the total background time } {
  46. r slowlog reset
  47. r config set slowlog-log-slower-than 200000
  48. if {!$::no_latency} {
  49. assert_equal [r slowlog len] 0
  50. }
  51. r block.double_debug 0
  52. if {!$::no_latency} {
  53. assert_equal [r slowlog len] 0
  54. }
  55. r config resetstat
  56. r block.double_debug 100
  57. if {!$::no_latency} {
  58. assert_equal [r slowlog len] 1
  59. }
  60. set cmdstatline [cmdrstat block.double_debug r]
  61. regexp "calls=1,usec=(.*?),usec_per_call=(.*?),rejected_calls=0,failed_calls=0" $cmdstatline usec usec_per_call
  62. assert {$usec >= 60000}
  63. assert {$usec_per_call >= 60000}
  64. }
  65. test { blocked clients time tracking - check blocked command without calling RedisModule_BlockedClientMeasureTimeStart() is not reporting background time } {
  66. r slowlog reset
  67. r config set slowlog-log-slower-than 200000
  68. if {!$::no_latency} {
  69. assert_equal [r slowlog len] 0
  70. }
  71. r block.debug_no_track 200 1000
  72. # ensure slowlog is still empty
  73. if {!$::no_latency} {
  74. assert_equal [r slowlog len] 0
  75. }
  76. }
  77. test "client unblock works only for modules with timeout support" {
  78. set rd [redis_deferring_client]
  79. $rd client id
  80. set id [$rd read]
  81. # Block with a timeout function - may unblock
  82. $rd block.block 20000
  83. wait_for_condition 50 100 {
  84. [r block.is_blocked] == 1
  85. } else {
  86. fail "Module did not block"
  87. }
  88. assert_equal 1 [r client unblock $id]
  89. assert_match {*Timed out*} [$rd read]
  90. # Block without a timeout function - cannot unblock
  91. $rd block.block 0
  92. wait_for_condition 50 100 {
  93. [r block.is_blocked] == 1
  94. } else {
  95. fail "Module did not block"
  96. }
  97. assert_equal 0 [r client unblock $id]
  98. assert_equal "OK" [r block.release foobar]
  99. assert_equal "foobar" [$rd read]
  100. }
  101. }