Skip to content

Commit 67d0561

Browse files
review fixes for #407
1 parent b408001 commit 67d0561

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

connection.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,8 @@ func (d defaultLogger) Report(event ConnLogKind, conn *Connection, v ...interfac
100100
conn.Addr(), err)
101101
case LogUnexpectedResultId:
102102
header := v[0].(Header)
103-
log.Printf("tarantool: connection %s got unexpected request ID (%d) in response (probably canceled request)",
104-
conn.Addr(), header.RequestId)
103+
log.Printf("tarantool: connection %s got unexpected request ID (%d) in response %s",
104+
conn.Addr(), header.RequestId, "(probably canceled request)")
105105
case LogWatchEventReadFailed:
106106
err := v[0].(error)
107107
log.Printf("tarantool: unable to parse watch event: %s", err)

example_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -163,10 +163,10 @@ func ExamplePingRequest_Context() {
163163
// Ping a Tarantool instance to check connection.
164164
data, err := conn.Do(req).Get()
165165
fmt.Println("Ping Resp data", data)
166-
fmt.Println("Ping Error", err)
166+
fmt.Println("Ping Error", contextDoneErrRegexp.Match([]byte(err.Error())))
167167
// Output:
168168
// Ping Resp data []
169-
// Ping Error context is done (requestId 3)
169+
// Ping Error true
170170
}
171171

172172
func ExampleSelectRequest() {

tarantool_test.go

+7-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"os/exec"
1212
"path/filepath"
1313
"reflect"
14+
"regexp"
1415
"runtime"
1516
"strings"
1617
"sync"
@@ -47,6 +48,8 @@ type Member struct {
4748
Val uint
4849
}
4950

51+
var contextDoneErrRegexp = regexp.MustCompile(`^context is done \(request ID [0-9]+\)$`)
52+
5053
func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error {
5154
if err := e.EncodeArrayLen(2); err != nil {
5255
return err
@@ -2731,7 +2734,8 @@ func TestClientRequestObjectsWithPassedCanceledContext(t *testing.T) {
27312734
req := NewPingRequest().Context(ctx)
27322735
cancel()
27332736
resp, err := conn.Do(req).Get()
2734-
if !strings.HasPrefix(err.Error(), "context is done") {
2737+
2738+
if !contextDoneErrRegexp.Match([]byte(err.Error())) {
27352739
t.Fatalf("Failed to catch an error from done context")
27362740
}
27372741
if resp != nil {
@@ -2802,7 +2806,7 @@ func TestClientRequestObjectsWithContext(t *testing.T) {
28022806
if err == nil {
28032807
t.Fatalf("caught nil error")
28042808
}
2805-
if !strings.HasPrefix(err.Error(), "context is done") {
2809+
if !contextDoneErrRegexp.Match([]byte(err.Error())) {
28062810
t.Fatalf("wrong error caught: %v", err)
28072811
}
28082812
}
@@ -3295,7 +3299,7 @@ func TestClientIdRequestObjectWithPassedCanceledContext(t *testing.T) {
32953299
resp, err := conn.Do(req).Get()
32963300
require.Nilf(t, resp, "Response is empty")
32973301
require.NotNilf(t, err, "Error is not empty")
3298-
require.ErrorContains(t, err, "context is done")
3302+
require.Regexp(t, contextDoneErrRegexp, err.Error())
32993303
}
33003304

33013305
func TestConnectionProtocolInfoUnsupported(t *testing.T) {

0 commit comments

Comments
 (0)