replication.tcl 3.2 KB
Newer Older
1 2 3 4 5 6 7 8
start_server {tags {"repl"}} {
    start_server {} {
        test {First server should have role slave after SLAVEOF} {
            r -1 slaveof [srv 0 host] [srv 0 port]
            after 1000
            s -1 role
        } {slave}

9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
        test {BRPOPLPUSH replication, when blocking against empty list} {
            set rd [redis_deferring_client]
            $rd brpoplpush a b 5
            r lpush a foo
            after 1000
            assert_equal [r debug digest] [r -1 debug digest]
        }

        test {BRPOPLPUSH replication, list exists} {
            set rd [redis_deferring_client]
            r lpush c 1
            r lpush c 2
            r lpush c 3
            $rd brpoplpush c d 5
            after 1000
            assert_equal [r debug digest] [r -1 debug digest]
        }

27 28
        test {MASTER and SLAVE dataset should be identical after complex ops} {
            createComplexDataset r 10000
29 30 31 32 33 34 35 36 37 38 39
            after 500
            if {[r debug digest] ne [r -1 debug digest]} {
                set csv1 [csvdump r]
                set csv2 [csvdump {r -1}]
                set fd [open /tmp/repldump1.txt w]
                puts -nonewline $fd $csv1
                close $fd
                set fd [open /tmp/repldump2.txt w]
                puts -nonewline $fd $csv2
                close $fd
                puts "Master - Slave inconsistency"
A
antirez 已提交
40 41 42 43 44 45 46 47
                puts "Run diff -u against /tmp/repldump*.txt for more info"
            }
            assert_equal [r debug digest] [r -1 debug digest]
        }

        test {MASTER and SLAVE consistency with expire} {
            createComplexDataset r 50000 useexpire
            after 4000 ;# Make sure everything expired before taking the digest
48
            r keys *   ;# Force DEL syntesizing to slave
A
antirez 已提交
49
            after 1000 ;# Wait another second. Now everything should be fine.
A
antirez 已提交
50 51 52 53 54 55 56 57 58 59
            if {[r debug digest] ne [r -1 debug digest]} {
                set csv1 [csvdump r]
                set csv2 [csvdump {r -1}]
                set fd [open /tmp/repldump1.txt w]
                puts -nonewline $fd $csv1
                close $fd
                set fd [open /tmp/repldump2.txt w]
                puts -nonewline $fd $csv2
                close $fd
                puts "Master - Slave inconsistency"
60 61
                puts "Run diff -u against /tmp/repldump*.txt for more info"
            }
62 63 64 65 66
            assert_equal [r debug digest] [r -1 debug digest]
        }
    }
}

P
Pieter Noordhuis 已提交
67
start_server {tags {"repl"}} {
68 69
    r set mykey foo
    
70
    start_server {} {
71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
        test {Second server should have role master at first} {
            s role
        } {master}
        
        test {SLAVEOF should start with link status "down"} {
            r slaveof [srv -1 host] [srv -1 port]
            s master_link_status
        } {down}
        
        test {The role should immediately be changed to "slave"} {
            s role
        } {slave}

        wait_for_sync r
        test {Sync should have transferred keys from master} {
            r get mykey
        } {foo}
        
        test {The link status should be up} {
            s master_link_status
        } {up}
        
        test {SET on the master should immediately propagate} {
            r -1 set mykey bar
            r  0 get mykey
        } {bar}
    }
}