1
0

16-transactions-on-replica.tcl 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. # Check basic transactions on a replica.
  2. source "../tests/includes/init-tests.tcl"
  3. test "Create a primary with a replica" {
  4. create_cluster 1 1
  5. }
  6. test "Cluster should start ok" {
  7. assert_cluster_state ok
  8. }
  9. set primary [Rn 0]
  10. set replica [Rn 1]
  11. test "Can't read from replica without READONLY" {
  12. $primary SET a 1
  13. wait_for_ofs_sync $primary $replica
  14. catch {$replica GET a} err
  15. assert {[string range $err 0 4] eq {MOVED}}
  16. }
  17. test "Can read from replica after READONLY" {
  18. $replica READONLY
  19. assert {[$replica GET a] eq {1}}
  20. }
  21. test "Can perform HSET primary and HGET from replica" {
  22. $primary HSET h a 1
  23. $primary HSET h b 2
  24. $primary HSET h c 3
  25. wait_for_ofs_sync $primary $replica
  26. assert {[$replica HGET h a] eq {1}}
  27. assert {[$replica HGET h b] eq {2}}
  28. assert {[$replica HGET h c] eq {3}}
  29. }
  30. test "Can MULTI-EXEC transaction of HGET operations from replica" {
  31. $replica MULTI
  32. assert {[$replica HGET h a] eq {QUEUED}}
  33. assert {[$replica HGET h b] eq {QUEUED}}
  34. assert {[$replica HGET h c] eq {QUEUED}}
  35. assert {[$replica EXEC] eq {1 2 3}}
  36. }
  37. test "MULTI-EXEC with write operations is MOVED" {
  38. $replica MULTI
  39. catch {$replica HSET h b 4} err
  40. assert {[string range $err 0 4] eq {MOVED}}
  41. catch {$replica exec} err
  42. assert {[string range $err 0 8] eq {EXECABORT}}
  43. }
  44. test "read-only blocking operations from replica" {
  45. set rd [redis_deferring_client redis 1]
  46. $rd readonly
  47. $rd read
  48. $rd XREAD BLOCK 0 STREAMS k 0
  49. wait_for_condition 1000 50 {
  50. [RI 1 blocked_clients] eq {1}
  51. } else {
  52. fail "client wasn't blocked"
  53. }
  54. $primary XADD k * foo bar
  55. set res [$rd read]
  56. set res [lindex [lindex [lindex [lindex $res 0] 1] 0] 1]
  57. assert {$res eq {foo bar}}
  58. $rd close
  59. }