blockedclient.tcl 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. # source tests/support/util.tcl
  2. set testmodule [file normalize tests/modules/blockedclient.so]
  3. start_server {tags {"modules"}} {
  4. r module load $testmodule
  5. test {Locked GIL acquisition} {
  6. assert_match "OK" [r acquire_gil]
  7. }
  8. test {Locked GIL acquisition during multi} {
  9. r multi
  10. r acquire_gil
  11. assert_equal {{Blocked client is not supported inside multi}} [r exec]
  12. }
  13. test {Locked GIL acquisition from RM_Call} {
  14. assert_equal {Blocked client is not allowed} [r do_rm_call acquire_gil]
  15. }
  16. test {Blocking command are not block the client on RM_Call} {
  17. r lpush l test
  18. assert_equal [r do_rm_call blpop l 0] {l test}
  19. r lpush l test
  20. assert_equal [r do_rm_call brpop l 0] {l test}
  21. r lpush l1 test
  22. assert_equal [r do_rm_call brpoplpush l1 l2 0] {test}
  23. assert_equal [r do_rm_call brpop l2 0] {l2 test}
  24. r lpush l1 test
  25. assert_equal [r do_rm_call blmove l1 l2 LEFT LEFT 0] {test}
  26. assert_equal [r do_rm_call brpop l2 0] {l2 test}
  27. r ZADD zset1 0 a 1 b 2 c
  28. assert_equal [r do_rm_call bzpopmin zset1 0] {zset1 a 0}
  29. assert_equal [r do_rm_call bzpopmax zset1 0] {zset1 c 2}
  30. r xgroup create s g $ MKSTREAM
  31. r xadd s * foo bar
  32. assert {[r do_rm_call xread BLOCK 0 STREAMS s 0-0] ne {}}
  33. assert {[r do_rm_call xreadgroup group g c BLOCK 0 STREAMS s >] ne {}}
  34. assert {[r do_rm_call blpop empty_list 0] eq {}}
  35. assert {[r do_rm_call brpop empty_list 0] eq {}}
  36. assert {[r do_rm_call brpoplpush empty_list1 empty_list2 0] eq {}}
  37. assert {[r do_rm_call blmove empty_list1 empty_list2 LEFT LEFT 0] eq {}}
  38. assert {[r do_rm_call bzpopmin empty_zset 0] eq {}}
  39. assert {[r do_rm_call bzpopmax empty_zset 0] eq {}}
  40. r xgroup create empty_stream g $ MKSTREAM
  41. assert {[r do_rm_call xread BLOCK 0 STREAMS empty_stream $] eq {}}
  42. assert {[r do_rm_call xreadgroup group g c BLOCK 0 STREAMS empty_stream >] eq {}}
  43. }
  44. test {Monitor disallow inside RM_Call} {
  45. set e {}
  46. catch {
  47. r do_rm_call monitor
  48. } e
  49. set e
  50. } {*ERR*DENY BLOCKING*}
  51. test {subscribe disallow inside RM_Call} {
  52. set e {}
  53. catch {
  54. r do_rm_call subscribe x
  55. } e
  56. set e
  57. } {*ERR*DENY BLOCKING*}
  58. test {RM_Call from blocked client} {
  59. r hset hash foo bar
  60. r do_bg_rm_call hgetall hash
  61. } {foo bar}
  62. test {blocked client reaches client output buffer limit} {
  63. r hset hash big [string repeat x 50000]
  64. r hset hash bada [string repeat x 50000]
  65. r hset hash boom [string repeat x 50000]
  66. r config set client-output-buffer-limit {normal 100000 0 0}
  67. r client setname myclient
  68. catch {r do_bg_rm_call hgetall hash} e
  69. assert_match "*I/O error*" $e
  70. reconnect
  71. set clients [r client list]
  72. assert_no_match "*name=myclient*" $clients
  73. }
  74. }