blockonkeys.tcl 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. set testmodule [file normalize tests/modules/blockonkeys.so]
  2. start_server {tags {"modules"}} {
  3. r module load $testmodule
  4. test {Module client blocked on keys (no metadata): No block} {
  5. r del k
  6. r fsl.push k 33
  7. r fsl.push k 34
  8. r fsl.bpop2 k 0
  9. } {34 33}
  10. test {Module client blocked on keys (no metadata): Timeout} {
  11. r del k
  12. set rd [redis_deferring_client]
  13. r fsl.push k 33
  14. $rd fsl.bpop2 k 1
  15. assert_equal {Request timedout} [$rd read]
  16. }
  17. test {Module client blocked on keys (no metadata): Blocked, case 1} {
  18. r del k
  19. set rd [redis_deferring_client]
  20. r fsl.push k 33
  21. $rd fsl.bpop2 k 0
  22. r fsl.push k 34
  23. assert_equal {34 33} [$rd read]
  24. }
  25. test {Module client blocked on keys (no metadata): Blocked, case 2} {
  26. r del k
  27. set rd [redis_deferring_client]
  28. r fsl.push k 33
  29. r fsl.push k 34
  30. $rd fsl.bpop2 k 0
  31. assert_equal {34 33} [$rd read]
  32. }
  33. test {Module client blocked on keys (with metadata): No block} {
  34. r del k
  35. r fsl.push k 34
  36. r fsl.bpopgt k 30 0
  37. } {34}
  38. test {Module client blocked on keys (with metadata): Timeout} {
  39. r del k
  40. set rd [redis_deferring_client]
  41. r fsl.push k 33
  42. $rd fsl.bpopgt k 35 1
  43. assert_equal {Request timedout} [$rd read]
  44. }
  45. test {Module client blocked on keys (with metadata): Blocked, case 1} {
  46. r del k
  47. set rd [redis_deferring_client]
  48. r fsl.push k 33
  49. $rd fsl.bpopgt k 33 0
  50. r fsl.push k 34
  51. assert_equal {34} [$rd read]
  52. }
  53. test {Module client blocked on keys (with metadata): Blocked, case 2} {
  54. r del k
  55. set rd [redis_deferring_client]
  56. $rd fsl.bpopgt k 35 0
  57. r fsl.push k 33
  58. r fsl.push k 34
  59. r fsl.push k 35
  60. r fsl.push k 36
  61. assert_equal {36} [$rd read]
  62. }
  63. test {Module client blocked on keys does not wake up on wrong type} {
  64. r del k
  65. set rd [redis_deferring_client]
  66. $rd fsl.bpop2 k 0
  67. r lpush k 12
  68. r lpush k 13
  69. r lpush k 14
  70. r del k
  71. r fsl.push k 33
  72. r fsl.push k 34
  73. assert_equal {34 33} [$rd read]
  74. }
  75. }