diff --git a/client_tools.go b/client_tools.go index ed76ea258..88f78bf08 100644 --- a/client_tools.go +++ b/client_tools.go @@ -10,6 +10,7 @@ type IntKey struct { I int } +//nolint: errcheck func (k IntKey) EncodeMsgpack(enc *msgpack.Encoder) error { enc.EncodeSliceLen(1) enc.EncodeInt(k.I) @@ -22,6 +23,7 @@ type UintKey struct { I uint } +//nolint: errcheck func (k UintKey) EncodeMsgpack(enc *msgpack.Encoder) error { enc.EncodeSliceLen(1) enc.EncodeUint(k.I) @@ -34,6 +36,7 @@ type StringKey struct { S string } +//nolint: errcheck func (k StringKey) EncodeMsgpack(enc *msgpack.Encoder) error { enc.EncodeSliceLen(1) enc.EncodeString(k.S) @@ -46,6 +49,7 @@ type IntIntKey struct { I1, I2 int } +//nolint: errcheck func (k IntIntKey) EncodeMsgpack(enc *msgpack.Encoder) error { enc.EncodeSliceLen(2) enc.EncodeInt(k.I1) @@ -60,6 +64,7 @@ type Op struct { Arg interface{} } +//nolint: errcheck func (o Op) EncodeMsgpack(enc *msgpack.Encoder) error { enc.EncodeSliceLen(3) enc.EncodeString(o.Op) @@ -75,6 +80,7 @@ type OpSplice struct { Replace string } +//nolint: errcheck func (o OpSplice) EncodeMsgpack(enc *msgpack.Encoder) error { enc.EncodeSliceLen(5) enc.EncodeString(o.Op) diff --git a/connection.go b/connection.go index 102b58d50..ba8bacbbc 100644 --- a/connection.go +++ b/connection.go @@ -145,7 +145,7 @@ type connShard struct { bufmut sync.Mutex buf smallWBuf enc *msgpack.Encoder - _pad [16]uint64 + _pad [16]uint64 //nolint: structcheck,unused } // Greeting is a message sent by tarantool on connect. @@ -227,6 +227,7 @@ type Opts struct { // // - If opts.Reconnect is non-zero, then error will be returned only if authorization// fails. But if Tarantool is not reachable, then it will attempt to reconnect later // and will not end attempts on authorization failures. +//nolint: errcheck func Connect(addr string, opts Opts) (conn *Connection, err error) { conn = &Connection{ addr: addr, @@ -494,7 +495,7 @@ func (conn *Connection) createConnection(reconnect bool) (err error) { conn.notify(ReconnectFailed) reconnects++ conn.mutex.Unlock() - time.Sleep(now.Add(conn.opts.Reconnect).Sub(time.Now())) + time.Sleep(time.Until(now.Add(conn.opts.Reconnect))) conn.mutex.Lock() } if conn.state == connClosed { @@ -537,6 +538,7 @@ func (conn *Connection) closeConnection(neterr error, forever bool) (err error) return } +//nolint: errcheck func (conn *Connection) reconnect(neterr error, c net.Conn) { conn.mutex.Lock() defer conn.mutex.Unlock() @@ -566,6 +568,7 @@ func (conn *Connection) unlockShards() { } } +//nolint: errcheck func (conn *Connection) pinger() { to := conn.opts.Timeout if to == 0 { @@ -687,7 +690,7 @@ func (conn *Connection) newFuture(requestCode int32) (fut *Future) { *pair.last = fut pair.last = &fut.next if conn.opts.Timeout > 0 { - fut.timeout = time.Now().Sub(epoch) + conn.opts.Timeout + fut.timeout = time.Until(epoch) + conn.opts.Timeout } shard.rmut.Unlock() if conn.rlimit != nil && conn.opts.RLimitAction == RLimitWait { @@ -795,9 +798,9 @@ func (conn *Connection) timeouts() { return case <-t.C: } - minNext := time.Now().Sub(epoch) + timeout + minNext := time.Until(epoch) + timeout for i := range conn.shard { - nowepoch = time.Now().Sub(epoch) + nowepoch = time.Until(epoch) shard := &conn.shard[i] for pos := range shard.requests { shard.rmut.Lock() @@ -824,7 +827,7 @@ func (conn *Connection) timeouts() { shard.rmut.Unlock() } } - nowepoch = time.Now().Sub(epoch) + nowepoch = time.Until(epoch) if nowepoch+time.Microsecond < minNext { t.Reset(minNext - nowepoch) } else { diff --git a/deadline_io.go b/deadline_io.go index 3bda73ac8..155fc6bd2 100644 --- a/deadline_io.go +++ b/deadline_io.go @@ -10,6 +10,7 @@ type DeadlineIO struct { c net.Conn } +//nolint: errcheck func (d *DeadlineIO) Write(b []byte) (n int, err error) { if d.to > 0 { d.c.SetWriteDeadline(time.Now().Add(d.to)) @@ -18,6 +19,7 @@ func (d *DeadlineIO) Write(b []byte) (n int, err error) { return } +//nolint: errcheck func (d *DeadlineIO) Read(b []byte) (n int, err error) { if d.to > 0 { d.c.SetReadDeadline(time.Now().Add(d.to)) diff --git a/example_test.go b/example_test.go index 7b81bc28e..a3361c9ba 100644 --- a/example_test.go +++ b/example_test.go @@ -10,7 +10,7 @@ import ( type Tuple struct { /* instruct msgpack to pack this struct as array, * so no custom packer is needed */ - _msgpack struct{} `msgpack:",asArray"` + _msgpack struct{} `msgpack:",asArray"` //nolint: structcheck,unused Id uint Msg string Name string @@ -85,6 +85,7 @@ func ExampleConnection_SelectTyped() { // response is [{{} 1111 hello world}] } +//nolint func Example() { spaceNo := uint32(512) indexNo := uint32(0) @@ -99,7 +100,7 @@ func Example() { } client, err := tarantool.Connect(server, opts) if err != nil { - fmt.Errorf("Failed to connect: %s", err.Error()) + fmt.Printf("Failed to connect: %s", err.Error()) return } diff --git a/queue/example_test.go b/queue/example_test.go index cf3150260..1dd56f5a2 100644 --- a/queue/example_test.go +++ b/queue/example_test.go @@ -8,6 +8,7 @@ import ( "github.com/tarantool/go-tarantool/queue" ) +//nolint func ExampleConnection_Queue() { cfg := queue.Cfg{ Temporary: false, diff --git a/queue/queue.go b/queue/queue.go index 69dcf8bcd..f7ccc1b32 100644 --- a/queue/queue.go +++ b/queue/queue.go @@ -323,6 +323,7 @@ type queueData struct { result interface{} } +//nolint func (qd *queueData) DecodeMsgpack(d *msgpack.Decoder) error { var err error var l int diff --git a/queue/queue_test.go b/queue/queue_test.go index db531eb4c..1569dc874 100644 --- a/queue/queue_test.go +++ b/queue/queue_test.go @@ -797,12 +797,14 @@ func TestUtube_Put(t *testing.T) { go func() { t1, err := q.TakeTimeout(2 * time.Second) if err != nil { - t.Fatalf("Failed to take task from utube: %s", err.Error()) + t.Errorf("Failed to take task from utube: %s", err.Error()) + return } time.Sleep(2 * time.Second) if err := t1.Ack(); err != nil { - t.Fatalf("Failed to ack task: %s", err.Error()) + t.Errorf("Failed to ack task: %s", err.Error()) + return } }() diff --git a/request.go b/request.go index ae42eb440..d250a9480 100644 --- a/request.go +++ b/request.go @@ -19,11 +19,13 @@ type Future struct { } // Ping sends empty request to Tarantool to check connection. +//nolint: errcheck func (conn *Connection) Ping() (resp *Response, err error) { future := conn.newFuture(PingRequest) return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(0); return nil }).Get() } +//nolint: errcheck func (req *Future) fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key interface{}) error { enc.EncodeUint64(KeySpaceNo) enc.EncodeUint64(uint64(spaceNo)) @@ -33,6 +35,7 @@ func (req *Future) fillSearch(enc *msgpack.Encoder, spaceNo, indexNo uint32, key return enc.Encode(key) } +//nolint: errcheck func (req *Future) fillIterator(enc *msgpack.Encoder, offset, limit, iterator uint32) { enc.EncodeUint64(KeyIterator) enc.EncodeUint64(uint64(iterator)) @@ -42,6 +45,7 @@ func (req *Future) fillIterator(enc *msgpack.Encoder, offset, limit, iterator ui enc.EncodeUint64(uint64(limit)) } +//nolint: errcheck func (req *Future) fillInsert(enc *msgpack.Encoder, spaceNo uint32, tuple interface{}) error { enc.EncodeUint64(KeySpaceNo) enc.EncodeUint64(uint64(spaceNo)) @@ -219,6 +223,7 @@ func (conn *Connection) SelectAsync(space, index interface{}, offset, limit, ite if err != nil { return future.fail(conn, err) } + //nolint: errcheck return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(6) future.fillIterator(enc, offset, limit, iterator) @@ -234,6 +239,7 @@ func (conn *Connection) InsertAsync(space interface{}, tuple interface{}) *Futur if err != nil { return future.fail(conn, err) } + //nolint: errcheck return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(2) return future.fillInsert(enc, spaceNo, tuple) @@ -248,6 +254,7 @@ func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Futu if err != nil { return future.fail(conn, err) } + //nolint: errcheck return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(2) return future.fillInsert(enc, spaceNo, tuple) @@ -256,6 +263,7 @@ func (conn *Connection) ReplaceAsync(space interface{}, tuple interface{}) *Futu // DeleteAsync sends deletion action to tarantool and returns Future. // Future's result will contain array with deleted tuple. +//nolint: errcheck func (conn *Connection) DeleteAsync(space, index interface{}, key interface{}) *Future { future := conn.newFuture(DeleteRequest) spaceNo, indexNo, err := conn.Schema.resolveSpaceIndex(space, index) @@ -276,6 +284,7 @@ func (conn *Connection) UpdateAsync(space, index interface{}, key, ops interface if err != nil { return future.fail(conn, err) } + //nolint: errcheck return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(4) if err := future.fillSearch(enc, spaceNo, indexNo, key); err != nil { @@ -294,6 +303,7 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in if err != nil { return future.fail(conn, err) } + //nolint: errcheck return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(3) enc.EncodeUint64(KeySpaceNo) @@ -309,6 +319,7 @@ func (conn *Connection) UpsertAsync(space interface{}, tuple interface{}, ops in // CallAsync sends a call to registered tarantool function and returns Future. // It uses request code for tarantool 1.6, so future's result is always array of arrays +//nolint: errcheck func (conn *Connection) CallAsync(functionName string, args interface{}) *Future { future := conn.newFuture(CallRequest) return future.send(conn, func(enc *msgpack.Encoder) error { @@ -325,6 +336,7 @@ func (conn *Connection) CallAsync(functionName string, args interface{}) *Future // (though, keep in mind, result is always array) func (conn *Connection) Call17Async(functionName string, args interface{}) *Future { future := conn.newFuture(Call17Request) + //nolint: errcheck return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(2) enc.EncodeUint64(KeyFunctionName) @@ -337,6 +349,7 @@ func (conn *Connection) Call17Async(functionName string, args interface{}) *Futu // EvalAsync sends a lua expression for evaluation and returns Future. func (conn *Connection) EvalAsync(expr string, args interface{}) *Future { future := conn.newFuture(EvalRequest) + //nolint: errcheck return future.send(conn, func(enc *msgpack.Encoder) error { enc.EncodeMapLen(2) enc.EncodeUint64(KeyExpression) @@ -350,6 +363,7 @@ func (conn *Connection) EvalAsync(expr string, args interface{}) *Future { // private // +//nolint: errcheck func (fut *Future) pack(h *smallWBuf, enc *msgpack.Encoder, body func(*msgpack.Encoder) error) (err error) { rid := fut.requestId hl := h.Len() diff --git a/response.go b/response.go index 6363a4fe4..42ce9d1d4 100644 --- a/response.go +++ b/response.go @@ -15,10 +15,12 @@ type Response struct { buf smallBuf } +//nolint: unused func (resp *Response) fill(b []byte) { resp.buf.b = b } +//nolint: errcheck func (resp *Response) smallInt(d *msgpack.Decoder) (i int, err error) { b, err := resp.buf.ReadByte() if err != nil { @@ -31,6 +33,7 @@ func (resp *Response) smallInt(d *msgpack.Decoder) (i int, err error) { return d.DecodeInt() } +//nolint: errcheck func (resp *Response) decodeHeader(d *msgpack.Decoder) (err error) { var l int d.Reset(&resp.buf) diff --git a/schema.go b/schema.go index 9b2dfae75..55b6cb768 100644 --- a/schema.go +++ b/schema.go @@ -49,6 +49,7 @@ type IndexField struct { Type string } +//nolint: varcheck,deadcode const ( maxSchemas = 10000 spaceSpId = 280 diff --git a/tarantool_test.go b/tarantool_test.go index 41bdfe830..8a769114b 100644 --- a/tarantool_test.go +++ b/tarantool_test.go @@ -26,6 +26,7 @@ type Tuple2 struct { Members []Member } +//nolint: errcheck func (m *Member) EncodeMsgpack(e *msgpack.Encoder) error { e.EncodeSliceLen(2) e.EncodeString(m.Name) @@ -51,6 +52,7 @@ func (m *Member) DecodeMsgpack(d *msgpack.Decoder) error { return nil } +//nolint: errcheck func (c *Tuple2) EncodeMsgpack(e *msgpack.Encoder) error { e.EncodeSliceLen(3) e.EncodeUint(c.Cid) @@ -79,7 +81,7 @@ func (c *Tuple2) DecodeMsgpack(d *msgpack.Decoder) error { } c.Members = make([]Member, l) for i := 0; i < l; i++ { - d.Decode(&c.Members[i]) + _ = d.Decode(&c.Members[i]) } return nil } @@ -418,7 +420,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Insert: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Insert") + t.Fatalf("Response is nil after Insert") } if len(resp.Data) != 1 { t.Errorf("Response Body len != 1") @@ -451,7 +453,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Delete: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Delete") + t.Fatalf("Response is nil after Delete") } if len(resp.Data) != 1 { t.Errorf("Response Body len != 1") @@ -474,7 +476,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Delete: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Delete") + t.Fatalf("Response is nil after Delete") } if len(resp.Data) != 0 { t.Errorf("Response Data len != 0") @@ -493,7 +495,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Replace (duplicate): %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Replace (duplicate)") + t.Fatalf("Response is nil after Replace (duplicate)") } if len(resp.Data) != 1 { t.Errorf("Response Data len != 1") @@ -518,7 +520,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Update: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Update") + t.Fatalf("Response is nil after Update") } if len(resp.Data) != 1 { t.Errorf("Response Data len != 1") @@ -561,13 +563,16 @@ func TestClient(t *testing.T) { if err != nil { t.Errorf("Failed to Replace: %s", err.Error()) } + if resp.Code != 0 { + t.Errorf("Failed to replace") + } } resp, err = conn.Select(spaceNo, indexNo, 0, 1, IterEq, []interface{}{uint(10)}) if err != nil { t.Errorf("Failed to Select: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Select") + t.Fatalf("Response is nil after Select") } if len(resp.Data) != 1 { t.Errorf("Response Data len != 1") @@ -589,7 +594,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Select: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Select") + t.Fatalf("Response is nil after Select") } if len(resp.Data) != 0 { t.Errorf("Response Data len != 0") @@ -659,7 +664,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Call: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Call") + t.Fatalf("Response is nil after Call") } if len(resp.Data) < 1 { t.Errorf("Response.Data is empty after Eval") @@ -667,11 +672,17 @@ func TestClient(t *testing.T) { // Call vs Call17 resp, err = conn.Call("simple_incr", []interface{}{1}) + if err != nil { + t.Errorf("Failed to use Call") + } if resp.Data[0].([]interface{})[0].(uint64) != 2 { t.Errorf("result is not {{1}} : %v", resp.Data) } resp, err = conn.Call17("simple_incr", []interface{}{1}) + if err != nil { + t.Errorf("Failed to use Call17") + } if resp.Data[0].(uint64) != 2 { t.Errorf("result is not {{1}} : %v", resp.Data) } @@ -682,7 +693,7 @@ func TestClient(t *testing.T) { t.Errorf("Failed to Eval: %s", err.Error()) } if resp == nil { - t.Errorf("Response is nil after Eval") + t.Fatalf("Response is nil after Eval") } if len(resp.Data) < 1 { t.Errorf("Response.Data is empty after Eval") @@ -693,6 +704,7 @@ func TestClient(t *testing.T) { } } +//nolint: ineffassign,staticcheck func TestSchema(t *testing.T) { var err error var conn *Connection @@ -840,7 +852,7 @@ func TestSchema(t *testing.T) { ifield1 := index3.Fields[0] ifield2 := index3.Fields[1] if ifield1 == nil || ifield2 == nil { - t.Errorf("index field is nil") + t.Fatalf("index field is nil") } if ifield1.Id != 1 || ifield2.Id != 2 { t.Errorf("index field has incorrect Id") @@ -897,6 +909,9 @@ func TestClientNamed(t *testing.T) { if err != nil { t.Errorf("Failed to Insert: %s", err.Error()) } + if resp.Code != 0 { + t.Errorf("Failed to Insert: wrong code returned %d", resp.Code) + } // Delete resp, err = conn.Delete(spaceName, indexName, []interface{}{uint(1001)}) @@ -949,6 +964,9 @@ func TestClientNamed(t *testing.T) { if err != nil { t.Errorf("Failed to Replace: %s", err.Error()) } + if resp.Code != 0 { + t.Errorf("Failed to Replace: wrong code returned %d", resp.Code) + } } resp, err = conn.Select(spaceName, indexName, 0, 1, IterEq, []interface{}{uint(1010)}) if err != nil { diff --git a/test_helpers/main.go b/test_helpers/main.go index e5c73bfe5..8b107847f 100644 --- a/test_helpers/main.go +++ b/test_helpers/main.go @@ -134,8 +134,6 @@ func IsTarantoolVersionLess(majorMin uint64, minorMin uint64, patchMin uint64) ( } else { return patch < patchMin, nil } - - return false, nil } // StartTarantool starts a tarantool instance for tests diff --git a/uuid/uuid_test.go b/uuid/uuid_test.go index b8987b0bc..5921a4de7 100644 --- a/uuid/uuid_test.go +++ b/uuid/uuid_test.go @@ -96,7 +96,7 @@ func TestSelect(t *testing.T) { t.Errorf("UUID select failed: %s", errSel.Error()) } if resp == nil { - t.Errorf("Response is nil after Select") + t.Fatalf("Response is nil after Select") } tupleValueIsId(t, resp.Data, id) @@ -131,7 +131,7 @@ func TestReplace(t *testing.T) { t.Errorf("UUID replace failed: %s", errRep) } if respRep == nil { - t.Errorf("Response is nil after Replace") + t.Fatalf("Response is nil after Replace") } tupleValueIsId(t, respRep.Data, id) @@ -140,7 +140,7 @@ func TestReplace(t *testing.T) { t.Errorf("UUID select failed: %s", errSel) } if respSel == nil { - t.Errorf("Response is nil after Select") + t.Fatalf("Response is nil after Select") } tupleValueIsId(t, respSel.Data, id) }