diff --git a/connection.go b/connection.go index 6a5e5c8e2..52af2d9cf 100644 --- a/connection.go +++ b/connection.go @@ -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) diff --git a/example_test.go b/example_test.go index 763e5e4e5..a76d9b1b4 100644 --- a/example_test.go +++ b/example_test.go @@ -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() { diff --git a/tarantool_test.go b/tarantool_test.go index bf4e51cdd..eb95c61cb 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -11,6 +11,7 @@ import ( "os/exec" "path/filepath" "reflect" + "regexp" "runtime" "strings" "sync" @@ -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 @@ -2731,7 +2734,8 @@ 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 { @@ -2802,7 +2806,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) } } @@ -3295,7 +3299,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) {