Skip to content

Commit

Permalink
review fixes for #407
Browse files Browse the repository at this point in the history
  • Loading branch information
nurzhan-saktaganov committed Sep 19, 2024
1 parent b408001 commit e76c795
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
conn.Addr(), err)
case LogUnexpectedResultId:
header := v[0].(Header)
log.Printf("tarantool: connection %s got unexpected request ID (%d) in response (probably canceled request)",
conn.Addr(), header.RequestId)
log.Printf("tarantool: connection %s got unexpected request ID (%d) in response %s",
conn.Addr(), header.RequestId, "(probably canceled request)")
case LogWatchEventReadFailed:
err := v[0].(error)
log.Printf("tarantool: unable to parse watch event: %s", err)
Expand Down
4 changes: 2 additions & 2 deletions example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,10 @@ func ExamplePingRequest_Context() {
// Ping a Tarantool instance to check connection.
data, err := conn.Do(req).Get()
fmt.Println("Ping Resp data", data)
fmt.Println("Ping Error", err)
fmt.Println("Ping Error", contextDoneErrRegexp.Match([]byte(err.Error())))
// Output:
// Ping Resp data []
// Ping Error context is done (requestId 3)
// Ping Error true
}

func ExampleSelectRequest() {
Expand Down
9 changes: 6 additions & 3 deletions tarantool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"os/exec"
"path/filepath"
"reflect"
"regexp"
"runtime"
"strings"
"sync"
Expand Down Expand Up @@ -47,6 +48,8 @@ type Member struct {
Val uint
}

var contextDoneErrRegexp = regexp.MustCompile(`^context is done \(request ID [0-9]+\)$`)

func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error {
if err := e.EncodeArrayLen(2); err != nil {
return err
Expand Down Expand Up @@ -2731,7 +2734,7 @@ func TestClientRequestObjectsWithPassedCanceledContext(t *testing.T) {
req := NewPingRequest().Context(ctx)
cancel()
resp, err := conn.Do(req).Get()
if !strings.HasPrefix(err.Error(), "context is done") {
if !contextDoneErrRegexp.Match([]byte(err.Error())) {
t.Fatalf("Failed to catch an error from done context")
}
if resp != nil {
Expand Down Expand Up @@ -2802,7 +2805,7 @@ func TestClientRequestObjectsWithContext(t *testing.T) {
if err == nil {
t.Fatalf("caught nil error")
}
if !strings.HasPrefix(err.Error(), "context is done") {
if !contextDoneErrRegexp.Match([]byte(err.Error())) {
t.Fatalf("wrong error caught: %v", err)
}
}
Expand Down Expand Up @@ -3295,7 +3298,7 @@ func TestClientIdRequestObjectWithPassedCanceledContext(t *testing.T) {
resp, err := conn.Do(req).Get()
require.Nilf(t, resp, "Response is empty")
require.NotNilf(t, err, "Error is not empty")
require.ErrorContains(t, err, "context is done")
require.Regexp(t, contextDoneErrRegexp, err.Error())
}

func TestConnectionProtocolInfoUnsupported(t *testing.T) {
Expand Down

0 comments on commit e76c795

Please sign in to comment.