diff options
Diffstat (limited to 'tests/unit/querybuf.tcl')
-rw-r--r-- | tests/unit/querybuf.tcl | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/unit/querybuf.tcl b/tests/unit/querybuf.tcl index bbbea12f4..f4859dd27 100644 --- a/tests/unit/querybuf.tcl +++ b/tests/unit/querybuf.tcl @@ -5,7 +5,7 @@ proc client_idle_sec {name} { return $idle } -# Calculate query buffer memory of slave +# Calculate query buffer memory of client proc client_query_buffer {name} { set clients [split [r client list] "\r\n"] set c [lsearch -inline $clients *name=$name*] @@ -18,6 +18,9 @@ proc client_query_buffer {name} { } start_server {tags {"querybuf slow"}} { + # increase the execution frequency of clientsCron + r config set hz 100 + # 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" { @@ -38,6 +41,9 @@ start_server {tags {"querybuf slow"}} { } test "query buffer resized correctly when not idle" { + # Pause cron to prevent premature shrinking (timing issue). + r debug pause-cron 1 + # Memory will increase by more than 32k due to client query buffer. set rd [redis_client] $rd client setname test_client @@ -49,6 +55,8 @@ start_server {tags {"querybuf slow"}} { set orig_test_client_qbuf [client_query_buffer test_client] assert {$orig_test_client_qbuf > 32768} + r debug pause-cron 0 + # Wait for qbuf to shrink due to lower peak set t [clock milliseconds] while true { @@ -62,5 +70,27 @@ start_server {tags {"querybuf slow"}} { # 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 + } {0} {needs:debug} + + test "query buffer resized correctly with fat argv" { + set rd [redis_client] + $rd client setname test_client + $rd write "*3\r\n\$3\r\nset\r\n\$1\r\na\r\n\$1000000\r\n" + $rd flush + + after 20 + if {[client_query_buffer test_client] < 1000000} { + fail "query buffer should not be resized when client idle time smaller than 2s" + } + + # Check that the query buffer is resized after 2 sec + wait_for_condition 1000 10 { + [client_idle_sec test_client] >= 3 && [client_query_buffer test_client] < 1000000 + } else { + fail "query buffer should be resized when client idle time bigger than 2s" + } + + $rd close } + } |