summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorBinbin <binloveplay1314@qq.com>2023-03-15 17:07:04 +0800
committerGitHub <noreply@github.com>2023-03-15 11:07:04 +0200
commit70b2c4f5fd4dc5ca592aad2128d0fd43e1e8f82c (patch)
tree0419189f6fbe6338f695dbea144486fadf5a4edb /tests
parent5360350e4aeaa2c7498be4af29aee449f0ee49ad (diff)
downloadredis-70b2c4f5fd4dc5ca592aad2128d0fd43e1e8f82c.tar.gz
Fix WAITAOF reply when using last_offset and last_numreplicas (#11917)
WAITAOF wad added in #11713, its return is an array. But forget to handle WAITAOF in last_offset and last_numreplicas, causing WAITAOF to return a WAIT like reply. Tests was added to validate that case (both WAIT and WAITAOF). This PR also refactored processClientsWaitingReplicas a bit for better maintainability and readability.
Diffstat (limited to 'tests')
-rw-r--r--tests/support/util.tcl4
-rw-r--r--tests/unit/wait.tcl74
2 files changed, 69 insertions, 9 deletions
diff --git a/tests/support/util.tcl b/tests/support/util.tcl
index 062f33a14..236fad314 100644
--- a/tests/support/util.tcl
+++ b/tests/support/util.tcl
@@ -886,9 +886,9 @@ proc wait_for_blocked_client {{idx 0}} {
}
}
-proc wait_for_blocked_clients_count {count {maxtries 100} {delay 10}} {
+proc wait_for_blocked_clients_count {count {maxtries 100} {delay 10} {idx 0}} {
wait_for_condition $maxtries $delay {
- [s blocked_clients] == $count
+ [s $idx blocked_clients] == $count
} else {
fail "Timeout waiting for blocked clients"
}
diff --git a/tests/unit/wait.tcl b/tests/unit/wait.tcl
index 7e040fbc0..8990965d5 100644
--- a/tests/unit/wait.tcl
+++ b/tests/unit/wait.tcl
@@ -18,20 +18,20 @@ start_server {} {
fail "Replication not started."
}
}
-
+
test {WAIT out of range timeout (milliseconds)} {
# Timeout is parsed as milliseconds by getLongLongFromObjectOrReply().
# Verify we get out of range message if value is behind LLONG_MAX
# (decimal value equals to 0x8000000000000000)
assert_error "*or out of range*" {$master wait 2 9223372036854775808}
-
+
# expected to fail by later overflow condition after addition
# of mstime(). (decimal value equals to 0x7FFFFFFFFFFFFFFF)
assert_error "*timeout is out of range*" {$master wait 2 9223372036854775807}
-
- assert_error "*timeout is negative*" {$master wait 2 -1}
+
+ assert_error "*timeout is negative*" {$master wait 2 -1}
}
-
+
test {WAIT should acknowledge 1 additional copy of the data} {
$master set foo 0
$master incr foo
@@ -68,6 +68,36 @@ start_server {} {
exec kill -SIGCONT $slave_pid
assert {[$master wait 1 1000] == 1}
}
+
+ test {WAIT replica multiple clients unblock - reuse last result} {
+ set rd [redis_deferring_client -1]
+ set rd2 [redis_deferring_client -1]
+
+ exec kill -SIGSTOP $slave_pid
+
+ $rd incr foo
+ $rd read
+
+ $rd2 incr foo
+ $rd2 read
+
+ $rd wait 1 0
+ $rd2 wait 1 0
+ wait_for_blocked_clients_count 2 100 10 -1
+
+ exec kill -SIGCONT $slave_pid
+
+ assert_equal [$rd read] {1}
+ assert_equal [$rd2 read] {1}
+
+ $rd ping
+ assert_equal [$rd read] {PONG}
+ $rd2 ping
+ assert_equal [$rd2 read] {PONG}
+
+ $rd close
+ $rd2 close
+ }
}}
@@ -101,13 +131,13 @@ tags {"wait aof network external:skip"} {
$rd waitaof 1 0 0
wait_for_blocked_client
r config set appendonly no ;# this should release the blocked client as an error
- assert_error {ERR WAITAOF cannot be used when appendonly is disabled} {$rd read}
+ assert_error {ERR WAITAOF cannot be used when numlocal is set but appendonly is disabled.} {$rd read}
$rd close
}
test {WAITAOF local on server with aof disabled} {
$master incr foo
- assert_error {ERR WAITAOF cannot be used when appendonly is disabled} {$master waitaof 1 0 0}
+ assert_error {ERR WAITAOF cannot be used when numlocal is set but appendonly is disabled.} {$master waitaof 1 0 0}
}
$master config set appendonly yes
@@ -164,6 +194,36 @@ tags {"wait aof network external:skip"} {
assert_equal [$master waitaof 0 1 0] {1 1}
}
+ test {WAITAOF replica multiple clients unblock - reuse last result} {
+ set rd [redis_deferring_client -1]
+ set rd2 [redis_deferring_client -1]
+
+ exec kill -SIGSTOP $replica_pid
+
+ $rd incr foo
+ $rd read
+
+ $rd2 incr foo
+ $rd2 read
+
+ $rd waitaof 0 1 0
+ $rd2 waitaof 0 1 0
+ wait_for_blocked_clients_count 2 100 10 -1
+
+ exec kill -SIGCONT $replica_pid
+
+ assert_equal [$rd read] {1 1}
+ assert_equal [$rd2 read] {1 1}
+
+ $rd ping
+ assert_equal [$rd read] {PONG}
+ $rd2 ping
+ assert_equal [$rd2 read] {PONG}
+
+ $rd close
+ $rd2 close
+ }
+
test {WAITAOF on promoted replica} {
$replica replicaof no one
$replica incr foo