From 68b8b45cd5ad63076afb29554f1647e949c5505c Mon Sep 17 00:00:00 2001 From: Yossi Gottlieb Date: Sun, 1 Aug 2021 15:07:27 +0300 Subject: [PATCH] Tests: avoid short reads on redis-cli output. (#9301) In some cases large replies on slow systems may only be partially read by the test suite, resulting with parsing errors. This fix is still timing sensitive but should greatly reduce the chances of this happening. --- tests/integration/redis-cli.tcl | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/integration/redis-cli.tcl b/tests/integration/redis-cli.tcl index a973c1539..db525e405 100644 --- a/tests/integration/redis-cli.tcl +++ b/tests/integration/redis-cli.tcl @@ -31,13 +31,25 @@ start_server {tags {"cli"}} { } proc read_cli {fd} { - set buf [read $fd] - while {[string length $buf] == 0} { - # wait some time and try again + set ret [read $fd] + while {[string length $ret] == 0} { after 10 - set buf [read $fd] + set ret [read $fd] } - set _ $buf + + # We may have a short read, try to read some more. + set empty_reads 0 + while {$empty_reads < 5} { + set buf [read $fd] + if {[string length $buf] == 0} { + after 10 + incr empty_reads + } else { + append ret $buf + set empty_reads 0 + } + } + return $ret } proc write_cli {fd buf} {