Skip to content

Commit

Permalink
Fix timing issue in replica migration test (#968)
Browse files Browse the repository at this point in the history
The reason is the server 3 still have the server 7 as its replica
due to a short wait, the wait is not enough, we should wait for
server loss its replica.
```
*** [err]: valkey-cli make source node ignores NOREPLICAS error when doing the last CLUSTER SETSLOT
Expected '{127.0.0.1 21497 267}' to be equal to '' (context: type eval line 34 cmd {assert_equal [lindex [R 3 role] 2] {}} proc ::test)
```

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin authored Aug 30, 2024
1 parent 743f5ac commit fea49bc
Showing 1 changed file with 6 additions and 21 deletions.
27 changes: 6 additions & 21 deletions tests/unit/cluster/replica-migration.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -339,11 +339,6 @@ start_cluster 4 4 {tags {external:skip cluster} overrides {cluster-node-timeout
R 3 config set cluster-allow-replica-migration no
R 7 config set cluster-allow-replica-migration yes

# Record the current primary node, server 7 will be migrated later.
set old_role_response [R 7 role]
set old_primary_ip [lindex [R 7 role] 1]
set old_primary_port [lindex [R 7 role] 2]

# Move slot 0 from primary 3 to primary 0.
set addr "[srv 0 host]:[srv 0 port]"
set myid [R 3 CLUSTER MYID]
Expand All @@ -354,26 +349,16 @@ start_cluster 4 4 {tags {external:skip cluster} overrides {cluster-node-timeout
fail "valkey-cli --cluster rebalance returns non-zero exit code, output below:\n$result"
}

# Wait for server 7 role response to change.
# Make sure server 3 lost its replica (server 7) and server 7 becomes a replica of primary 0.
wait_for_condition 1000 50 {
[R 7 role] ne $old_role_response
[s -3 role] eq {master} &&
[s -3 connected_slaves] eq 0 &&
[s -7 role] eq {slave} &&
[get_my_primary_peer 7] eq $addr
} else {
puts "R 3 role: [R 3 role]"
puts "R 7 role: [R 7 role]"
fail "Server 7 role response has not changed"
fail "Server 3 and 7 role response has not changed"
}

wait_for_cluster_propagation
wait_for_cluster_state "ok"

# Make sure server 3 is still a primary and has no replicas.
assert_equal [s -3 role] {master}
assert_equal [lindex [R 3 role] 2] {}

# And server 7 becomes a replica of another primary.
set new_primary_ip [lindex [R 7 role] 1]
set new_primary_port [lindex [R 7 role] 2]
assert_equal [s -7 role] {slave}
assert_not_equal "$old_primary_ip:$old_primary_port" "new_primary_ip:new_primary_port"
}
} my_slot_allocation cluster_allocate_replicas ;# start_cluster

0 comments on commit fea49bc

Please sign in to comment.