This is an automated email from the ASF dual-hosted git repository.
hulk pushed a commit to branch unstable
in repository https://gitbox.apache.org/repos/asf/incubator-kvrocks.git
The following commit(s) were added to refs/heads/unstable by this push:
new 9daa6b3a Fix redis cli test will fail if cannot read response at once
(#1129)
9daa6b3a is described below
commit 9daa6b3aaeb58621bdbf051ac6b22e80712e27d4
Author: hulk <[email protected]>
AuthorDate: Sun Nov 20 20:52:46 2022 +0800
Fix redis cli test will fail if cannot read response at once (#1129)
For the current read implementation, it will return the string after
reading the response, so it may only read parts of the response.
We simply fix it by checking whether the response string has the
newline('\r\n') or not.
---
tests/gocase/integration/cli/cli_test.go | 15 ++++++++++++++-
1 file changed, 14 insertions(+), 1 deletion(-)
diff --git a/tests/gocase/integration/cli/cli_test.go
b/tests/gocase/integration/cli/cli_test.go
index ad6d4776..e16e0e15 100644
--- a/tests/gocase/integration/cli/cli_test.go
+++ b/tests/gocase/integration/cli/cli_test.go
@@ -23,6 +23,7 @@ import (
"bufio"
"bytes"
"context"
+ "errors"
"fmt"
"io"
"math"
@@ -67,13 +68,25 @@ func (c *interactiveCli) Close() error {
}
func (c *interactiveCli) Read() (string, error) {
+ pos := 0
b := make([]byte, defaultByteBufLen)
for {
- n, err := c.r.Read(b)
+ if pos >= defaultByteBufLen {
+ return "", errors.New("exceed read buffer size")
+ }
+ n, err := c.r.Read(b[pos:])
if err != nil {
return "", err
}
+ pos += n
if n > 0 {
+ // For the big response size scenario, it may need
multiple times
+ // to read all bytes, but it's no a good way to wait
for the entire
+ // response except parsing the Redis protocol. To make
this simple,
+ // we can just check whether the response has the
newline or not.
+ if pos < 2 || b[pos-1] != '\n' {
+ continue
+ }
r := string(bytes.Trim(b, "\x00"))
r = strings.ReplaceAll(r, "\r", "")
r = strings.TrimSuffix(r, "\n")