corethreads.tcl 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. start_server {tags {"corethreads"}} {
  2. test {Write operations are blocked on locked keys} {
  3. set rd [redis_deferring_client]
  4. set now [clock milliseconds]
  5. $rd DEBUG LOCK 1000 read mykey
  6. r incr mykey
  7. set elapsed [expr {[clock milliseconds]-$now}]
  8. assert {$elapsed > 500}
  9. $rd read
  10. $rd close
  11. } 0
  12. test {Disconnecting a client with an active thread does not crash Redis} {
  13. set rd [redis_deferring_client]
  14. $rd CLIENT ID
  15. set id [$rd read]
  16. $rd DEBUG LOCK 5000 read mykey
  17. assert {[r client kill id $id] == 1}
  18. $rd close
  19. }
  20. test {Disconnecting a client blocked on a key does not crash Redis} {
  21. set rd1 [redis_deferring_client]
  22. set rd2 [redis_deferring_client]
  23. $rd1 CLIENT ID
  24. set id [$rd1 read]
  25. $rd2 DEBUG LOCK 5000 read mykey
  26. $rd1 INCR mykey ; # Now this $rd1 is blocked on mykey
  27. assert {[r client kill id $id] == 1}
  28. $rd1 close
  29. $rd2 close
  30. }
  31. test {Client is resumed only after last key gets unlocked} {
  32. set rd1 [redis_deferring_client]
  33. set rd2 [redis_deferring_client]
  34. set now [clock milliseconds]
  35. $rd1 DEBUG LOCK 500 read mykey1
  36. $rd2 DEBUG LOCK 2000 read mykey2
  37. r mset mykey1 a mykey2 b
  38. set elapsed [expr {[clock milliseconds]-$now}]
  39. assert {$elapsed > 1500}
  40. $rd1 close
  41. $rd2 close
  42. } 0
  43. test {Build large data structures for the next tests} {
  44. for {set j 0} {$j < 10000} {incr j} {
  45. lappend set1 $j
  46. lappend set2 [expr {$j*2}]
  47. }
  48. r sadd set1 {*}$set1
  49. r sadd set2 {*}$set2
  50. r rpush list1 {*}$set1
  51. assert {[r scard set1] == $j}
  52. assert {[r scard set2] == $j}
  53. assert {[r llen list1] == $j}
  54. }
  55. test {Lua can execute threaded commands synchronously} {
  56. set items [r EVAL {return redis.call('smembers','set1')} 0]
  57. llength $items
  58. } 10000
  59. test {Lua report an error if we try to access a locked key} {
  60. set rd [redis_deferring_client]
  61. $rd DEBUG LOCK 5000 read set1
  62. catch {
  63. r EVAL {return redis.call('sadd','set1','foo')} 0
  64. } err
  65. $rd close
  66. set err
  67. } {*LOCKED*}
  68. test {MULTI can execute threaded commands synchronously} {
  69. r MULTI
  70. r SMEMBERS set1
  71. set items [r EXEC]
  72. set items [lindex $items 0]
  73. llength $items
  74. } 10000
  75. test {MULTI can block on locked keys} {
  76. set rd [redis_deferring_client]
  77. set now [clock milliseconds]
  78. $rd DEBUG LOCK 1000 read mykey3
  79. r multi
  80. r incr mykey3
  81. r exec
  82. set elapsed [expr {[clock milliseconds]-$now}]
  83. assert {$elapsed > 500}
  84. $rd read
  85. $rd close
  86. }
  87. test {Threaded SUNION works} {
  88. set res [r SUNION set1 set2]
  89. llength $res
  90. } {15000}
  91. test {Threaded SDIFF works} {
  92. set res [r SDIFF set1 set2]
  93. llength $res
  94. } {5000}
  95. test {Threaded SINTER works} {
  96. set res [r SINTER set1 set2]
  97. llength $res
  98. } {5000}
  99. test {Threaded SMEMBERS works} {
  100. set res [r SMEMBERS set1]
  101. llength $res
  102. } {10000}
  103. test {Threaded LRANGE works} {
  104. set res [r LRANGE list1 0 -1]
  105. llength $res
  106. } {10000}
  107. }