summaryrefslogtreecommitdiff
path: root/tests/unit/querybuf.tcl
diff options
context:
space:
mode:
authoryoav-steinberg <yoav@monfort.co.il>2021-08-06 20:50:34 +0300
committerGitHub <noreply@github.com>2021-08-06 20:50:34 +0300
commit0a9377535b6fd42ca6affa1c939fb859950d8043 (patch)
tree3c2e76ddda0c62c2775bf948dd968354e363a994 /tests/unit/querybuf.tcl
parent3f3f678a4741e6af18230ee1862d9ced7af79faf (diff)
downloadredis-0a9377535b6fd42ca6affa1c939fb859950d8043.tar.gz
Ignore resize threshold on idle qbuf resizing (#9322)
Also update qbuf tests to verify both idle and peak based resizing logic. And delete unused function: getClientsMaxBuffers
Diffstat (limited to 'tests/unit/querybuf.tcl')
-rw-r--r--tests/unit/querybuf.tcl44
1 files changed, 31 insertions, 13 deletions
diff --git a/tests/unit/querybuf.tcl b/tests/unit/querybuf.tcl
index 458f8e844..bbbea12f4 100644
--- a/tests/unit/querybuf.tcl
+++ b/tests/unit/querybuf.tcl
@@ -21,28 +21,46 @@ start_server {tags {"querybuf slow"}} {
# The test will run at least 2s to check if client query
# buffer will be resized when client idle 2s.
test "query buffer resized correctly" {
- # Memory will increase by more than 32k due to client query buffer.
- set rd [redis_deferring_client]
+ set rd [redis_client]
$rd client setname test_client
set orig_test_client_qbuf [client_query_buffer test_client]
+ # Make sure query buff has less than the peak resize threshold (PROTO_RESIZE_THRESHOLD) 32k
+ # but at least the basic IO reading buffer size (PROTO_IOBUF_LEN) 16k
assert {$orig_test_client_qbuf >= 16384 && $orig_test_client_qbuf < 32768}
- # Check that the initial query buffer is not resized if it is idle for more than 2s
+ # Check that the initial query buffer is resized after 2 sec
wait_for_condition 1000 10 {
- [client_idle_sec test_client] > 3 && [client_query_buffer test_client] == $orig_test_client_qbuf
+ [client_idle_sec test_client] >= 3 && [client_query_buffer test_client] == 0
} else {
- fail "query buffer was resized"
+ fail "query buffer was not resized"
}
+ $rd close
+ }
- # Fill query buffer to more than 32k
- $rd set bigstring v ;# create bigstring in advance to avoid adding extra memory
- $rd set bigstring [string repeat A 32768] nx
+ test "query buffer resized correctly when not idle" {
+ # Memory will increase by more than 32k due to client query buffer.
+ set rd [redis_client]
+ $rd client setname test_client
- # Wait for query buffer to be resized to 0.
- wait_for_condition 1000 10 {
- [client_query_buffer test_client] == 0
- } else {
- fail "querybuf expected to be resized"
+ # Create a large query buffer (more than PROTO_RESIZE_THRESHOLD - 32k)
+ $rd set x [string repeat A 400000]
+
+ # Make sure query buff is larger than the peak resize threshold (PROTO_RESIZE_THRESHOLD) 32k
+ set orig_test_client_qbuf [client_query_buffer test_client]
+ assert {$orig_test_client_qbuf > 32768}
+
+ # Wait for qbuf to shrink due to lower peak
+ set t [clock milliseconds]
+ while true {
+ # Write something smaller, so query buf peak can shrink
+ $rd set x [string repeat A 100]
+ set new_test_client_qbuf [client_query_buffer test_client]
+ if {$new_test_client_qbuf < $orig_test_client_qbuf} { break }
+ if {[expr [clock milliseconds] - $t] > 1000} { break }
+ after 10
}
+ # Validate qbuf shrunk but isn't 0 since we maintain room based on latest peak
+ assert {[client_query_buffer test_client] > 0 && [client_query_buffer test_client] < $orig_test_client_qbuf}
+ $rd close
}
}