From e49c2a52922f1c86eb94b42206cb9d50e1aeb431 Mon Sep 17 00:00:00 2001
From: Binbin <binloveplay1314@qq.com>
Date: Thu, 4 May 2023 18:02:08 +0800
Subject: [PATCH] Pause cron to prevent premature shrinking in querybuf test
 (#12126)

Tests occasionally fail since #12000:
```
*** [err]: query buffer resized correctly when not idle in tests/unit/querybuf.tcl
Expected 0 > 32768 (context: type eval line 11 cmd {assert {$orig_test_client_qbuf > 32768}} proc ::test)

*** [err]: query buffer resized correctly with fat argv in tests/unit/querybuf.tcl
query buffer should not be resized when client idle time smaller than 2s
```

The reason may be because we set hz to 100, querybuf shrinks before we count
client_query_buffer. We avoid this problem by setting pause-cron to 1.
---
 tests/unit/querybuf.tcl | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/tests/unit/querybuf.tcl b/tests/unit/querybuf.tcl
index c66f5c250..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*]
@@ -20,6 +20,7 @@ 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" {
@@ -40,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
@@ -51,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 {
@@ -64,7 +70,7 @@ 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]