"Fossies" - the Fresh Open Source Software Archive

Member "redis-7.0.5/tests/cluster/tests/16-transactions-on-replica.tcl" (21 Sep 2022, 2001 Bytes) of package /linux/misc/redis-7.0.5.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Tcl/Tk source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "16-transactions-on-replica.tcl": 7.0.4_vs_7.0.5.

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