pause.tcl 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. start_server {tags {"pause network"}} {
  2. test "Test read commands are not blocked by client pause" {
  3. r client PAUSE 100000000 WRITE
  4. set rd [redis_deferring_client]
  5. $rd GET FOO
  6. $rd PING
  7. $rd INFO
  8. assert_equal [s 0 blocked_clients] 0
  9. r client unpause
  10. $rd close
  11. }
  12. test "Test write commands are paused by RO" {
  13. r client PAUSE 100000000 WRITE
  14. set rd [redis_deferring_client]
  15. $rd SET FOO BAR
  16. wait_for_blocked_clients_count 1 50 100
  17. r client unpause
  18. assert_match "OK" [$rd read]
  19. $rd close
  20. }
  21. test "Test special commands are paused by RO" {
  22. r PFADD pause-hll test
  23. r client PAUSE 100000000 WRITE
  24. # Test that pfcount, which can replicate, is also blocked
  25. set rd [redis_deferring_client]
  26. $rd PFCOUNT pause-hll
  27. wait_for_blocked_clients_count 1 50 100
  28. # Test that publish, which adds the message to the replication
  29. # stream is blocked.
  30. set rd2 [redis_deferring_client]
  31. $rd2 publish foo bar
  32. wait_for_blocked_clients_count 2 50 100
  33. # Test that SCRIPT LOAD, which is replicated.
  34. set rd3 [redis_deferring_client]
  35. $rd3 script load "return 1"
  36. wait_for_blocked_clients_count 3 50 100
  37. r client unpause
  38. assert_match "1" [$rd read]
  39. assert_match "0" [$rd2 read]
  40. assert_match "*" [$rd3 read]
  41. $rd close
  42. $rd2 close
  43. $rd3 close
  44. }
  45. test "Test read/admin mutli-execs are not blocked by pause RO" {
  46. r SET FOO BAR
  47. r client PAUSE 100000000 WRITE
  48. set rd [redis_deferring_client]
  49. $rd MULTI
  50. assert_equal [$rd read] "OK"
  51. $rd PING
  52. assert_equal [$rd read] "QUEUED"
  53. $rd GET FOO
  54. assert_equal [$rd read] "QUEUED"
  55. $rd EXEC
  56. assert_equal [s 0 blocked_clients] 0
  57. r client unpause
  58. assert_match "PONG BAR" [$rd read]
  59. $rd close
  60. }
  61. test "Test write mutli-execs are blocked by pause RO" {
  62. set rd [redis_deferring_client]
  63. $rd MULTI
  64. assert_equal [$rd read] "OK"
  65. $rd SET FOO BAR
  66. r client PAUSE 100000000 WRITE
  67. assert_equal [$rd read] "QUEUED"
  68. $rd EXEC
  69. wait_for_blocked_clients_count 1 50 100
  70. r client unpause
  71. assert_match "OK" [$rd read]
  72. $rd close
  73. }
  74. test "Test scripts are blocked by pause RO" {
  75. r client PAUSE 100000000 WRITE
  76. set rd [redis_deferring_client]
  77. $rd EVAL "return 1" 0
  78. wait_for_blocked_clients_count 1 50 100
  79. r client unpause
  80. assert_match "1" [$rd read]
  81. $rd close
  82. }
  83. test "Test multiple clients can be queued up and unblocked" {
  84. r client PAUSE 100000000 WRITE
  85. set clients [list [redis_deferring_client] [redis_deferring_client] [redis_deferring_client]]
  86. foreach client $clients {
  87. $client SET FOO BAR
  88. }
  89. wait_for_blocked_clients_count 3 50 100
  90. r client unpause
  91. foreach client $clients {
  92. assert_match "OK" [$client read]
  93. $client close
  94. }
  95. }
  96. test "Test clients with syntax errors will get responses immediately" {
  97. r client PAUSE 100000000 WRITE
  98. catch {r set FOO} err
  99. assert_match "ERR wrong number of arguments for *" $err
  100. r client unpause
  101. }
  102. test "Test both active and passive expires are skipped during client pause" {
  103. set expired_keys [s 0 expired_keys]
  104. r multi
  105. r set foo{t} bar{t} PX 10
  106. r set bar{t} foo{t} PX 10
  107. r client PAUSE 100000000 WRITE
  108. r exec
  109. wait_for_condition 10 100 {
  110. [r get foo{t}] == {} && [r get bar{t}] == {}
  111. } else {
  112. fail "Keys were never logically expired"
  113. }
  114. # No keys should actually have been expired
  115. assert_match $expired_keys [s 0 expired_keys]
  116. r client unpause
  117. # Force the keys to expire
  118. r get foo{t}
  119. r get bar{t}
  120. # Now that clients have been unpaused, expires should go through
  121. assert_match [expr $expired_keys + 2] [s 0 expired_keys]
  122. }
  123. test "Test that client pause starts at the end of a transaction" {
  124. r MULTI
  125. r SET FOO1{t} BAR
  126. r client PAUSE 100000000 WRITE
  127. r SET FOO2{t} BAR
  128. r exec
  129. set rd [redis_deferring_client]
  130. $rd SET FOO3{t} BAR
  131. wait_for_blocked_clients_count 1 50 100
  132. assert_match "BAR" [r GET FOO1{t}]
  133. assert_match "BAR" [r GET FOO2{t}]
  134. assert_match "" [r GET FOO3{t}]
  135. r client unpause
  136. assert_match "OK" [$rd read]
  137. $rd close
  138. }
  139. # Make sure we unpause at the end
  140. r client unpause
  141. }