2
0

bg_block_op.tcl 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. source tests/support/redis.tcl
  2. source tests/support/util.tcl
  3. # This function sometimes writes sometimes blocking-reads from lists/sorted
  4. # sets. There are multiple processes like this executing at the same time
  5. # so that we have some chance to trap some corner condition if there is
  6. # a regression. For this to happen it is important that we narrow the key
  7. # space to just a few elements, and balance the operations so that it is
  8. # unlikely that lists and zsets just get more data without ever causing
  9. # blocking.
  10. proc bg_block_op {host port db ops} {
  11. set r [redis $host $port]
  12. $r select $db
  13. for {set j 0} {$j < $ops} {incr j} {
  14. # List side
  15. set k list_[randomInt 10]
  16. set k2 list_[randomInt 10]
  17. set v [randomValue]
  18. randpath {
  19. randpath {
  20. $r rpush $k $v
  21. } {
  22. $r lpush $k $v
  23. }
  24. } {
  25. $r blpop $k 2
  26. } {
  27. $r blpop $k $k2 2
  28. }
  29. # Zset side
  30. set k zset_[randomInt 10]
  31. set k2 zset_[randomInt 10]
  32. set v1 [randomValue]
  33. set v2 [randomValue]
  34. randpath {
  35. $r zadd $k [randomInt 10000] $v
  36. } {
  37. $r zadd $k [randomInt 10000] $v [randomInt 10000] $v2
  38. } {
  39. $r bzpopmin $k 2
  40. } {
  41. $r bzpopmax $k 2
  42. }
  43. }
  44. }
  45. bg_block_op [lindex $argv 0] [lindex $argv 1] [lindex $argv 2] [lindex $argv 3]