Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions bytes/buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ func (b *Buffer) WriteNextEnd(n int) (int, error) {
bufLen := len(b.buf)
l := bufLen + n
if l > peekBufLen {
return 0, fmt.Errorf("U have not invoked @WriteNextBegin")
return 0, fmt.Errorf("you have not invoked @WriteNextBegin")
}

b.lastRead = opInvalid
Expand Down Expand Up @@ -331,7 +331,8 @@ func (b *Buffer) WriteByte(c byte) error {
func (b *Buffer) WriteRune(r rune) (n int, err error) {
// Compare as uint32 to correctly handle negative runes.
if uint32(r) < utf8.RuneSelf {
b.WriteByte(byte(r))
// WriteByte returns nil for bytes.Buffer
_ = b.WriteByte(byte(r))
return 1, nil
}
b.lastRead = opInvalid
Expand Down
3 changes: 2 additions & 1 deletion bytes/buffer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (

func TestBufferWithPeek(t *testing.T) {
var b Buffer
b.WriteString("hello")
_, err := b.WriteString("hello")
assert.Nil(t, err)

b1 := b
b1.WriteNextBegin(100)
Expand Down
2 changes: 1 addition & 1 deletion bytes/bytes_pool.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func (bp *BytesPool) findIndex(size int) int {
func (bp *BytesPool) AcquireBytes(size int) *[]byte {
idx := bp.findIndex(size)
if idx >= bp.length {
buf := make([]byte, size, size)
buf := make([]byte, size)
return &buf
}

Expand Down
14 changes: 4 additions & 10 deletions container/chan/unbounded_chan_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func TestUnboundedChan(t *testing.T) {
}

for i := 1; i < 60; i++ {
v, _ := <-ch.Out()
v := <-ch.Out()
count += v.(int)
}

Expand Down Expand Up @@ -222,9 +222,7 @@ func BenchmarkUnboundedChan_Fixed(b *testing.B) {

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
select {
case ch.In() <- 1:
}
ch.In() <- 1

<-ch.Out()
}
Expand All @@ -238,9 +236,7 @@ func BenchmarkUnboundedChan_Extension(b *testing.B) {

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
select {
case ch.In() <- 1:
}
ch.In() <- 1

<-ch.Out()
}
Expand All @@ -254,9 +250,7 @@ func BenchmarkUnboundedChan_ExtensionUnlimited(b *testing.B) {

b.RunParallel(func(pb *testing.PB) {
for pb.Next() {
select {
case ch.In() <- 1:
}
ch.In() <- 1

<-ch.Out()
}
Expand Down
93 changes: 62 additions & 31 deletions container/queue/queue_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ import (
func TestPut(t *testing.T) {
q := New(10)

q.Put(`test`)
err := q.Put(`test`)
assert.Nil(t, err)
assert.Equal(t, int64(1), q.Len())

results, err := q.Get(1)
Expand All @@ -41,7 +42,8 @@ func TestPut(t *testing.T) {
assert.Equal(t, `test`, result)
assert.True(t, q.Empty())

q.Put(`test2`)
err = q.Put(`test2`)
assert.Nil(t, err)
assert.Equal(t, int64(1), q.Len())

results, err = q.Get(1)
Expand All @@ -55,7 +57,8 @@ func TestPut(t *testing.T) {
func TestGet(t *testing.T) {
q := New(10)

q.Put(`test`)
err := q.Put(`test`)
assert.Nil(t, err)
result, err := q.Get(2)
if !assert.Nil(t, err) {
return
Expand All @@ -65,8 +68,10 @@ func TestGet(t *testing.T) {
assert.Equal(t, `test`, result[0])
assert.Equal(t, int64(0), q.Len())

q.Put(`1`)
q.Put(`2`)
err = q.Put(`1`)
assert.Nil(t, err)
err = q.Put(`2`)
assert.Nil(t, err)

result, err = q.Get(1)
if !assert.Nil(t, err) {
Expand All @@ -89,9 +94,11 @@ func TestPoll(t *testing.T) {
q := New(10)

// should be able to Poll() before anything is present, without breaking future Puts
q.Poll(1, time.Millisecond)
// testing timeout behavior on empty queue
_, _ = q.Poll(1, time.Millisecond)

q.Put(`test`)
err := q.Put(`test`)
assert.Nil(t, err)
result, err := q.Poll(2, 0)
if !assert.Nil(t, err) {
return
Expand All @@ -101,8 +108,10 @@ func TestPoll(t *testing.T) {
assert.Equal(t, `test`, result[0])
assert.Equal(t, int64(0), q.Len())

q.Put(`1`)
q.Put(`2`)
err = q.Put(`1`)
assert.Nil(t, err)
err = q.Put(`2`)
assert.Nil(t, err)

result, err = q.Poll(1, time.Millisecond)
if !assert.Nil(t, err) {
Expand Down Expand Up @@ -135,15 +144,17 @@ func TestPollNoMemoryLeak(t *testing.T) {

for i := 0; i < 10; i++ {
// Poll() should cleanup waiters after timeout
q.Poll(1, time.Nanosecond)
// testing waiter cleanup mechanism
_, _ = q.Poll(1, time.Nanosecond)
assert.Len(t, q.waiters, 0)
}
}

func TestAddEmptyPut(t *testing.T) {
q := New(10)

q.Put()
// testing empty parameters behavior
_ = q.Put()

if q.Len() != 0 {
t.Errorf(`Expected len: %d, received: %d`, 0, q.Len())
Expand All @@ -153,7 +164,8 @@ func TestAddEmptyPut(t *testing.T) {
func TestGetNonPositiveNumber(t *testing.T) {
q := New(10)

q.Put(`test`)
err := q.Put(`test`)
assert.Nil(t, err)
result, err := q.Get(0)
if !assert.Nil(t, err) {
return
Expand All @@ -171,7 +183,8 @@ func TestEmpty(t *testing.T) {
t.Errorf(`Expected empty queue.`)
}

q.Put(`test`)
err := q.Put(`test`)
assert.Nil(t, err)
if q.Empty() {
t.Errorf(`Expected non-empty queue.`)
}
Expand All @@ -182,7 +195,8 @@ func TestGetEmpty(t *testing.T) {

go func() {
time.Sleep(time.Second)
q.Put(`a`)
// test setup, not test target
_ = q.Put(`a`)
}()

result, err := q.Get(2)
Expand Down Expand Up @@ -219,7 +233,8 @@ func TestMultipleGetEmpty(t *testing.T) {
wg.Wait()
wg.Add(2)

q.Put(`a`, `b`, `c`)
err := q.Put(`a`, `b`, `c`)
assert.Nil(t, err)
wg.Wait()

if assert.Len(t, results[0], 1) && assert.Len(t, results[1], 1) {
Expand All @@ -238,7 +253,8 @@ func TestDispose(t *testing.T) {

// when the queue is not empty
q = New(10)
q.Put(`1`)
err := q.Put(`1`)
assert.Nil(t, err)
itemsDisposed = q.Dispose()

expected := []interface{}{`1`}
Expand Down Expand Up @@ -305,7 +321,8 @@ func BenchmarkQueue(b *testing.B) {

go func() {
for {
q.Get(1)
// benchmark focuses on throughput
_, _ = q.Get(1)
i++
if i == b.N {
wg.Done()
Expand All @@ -315,7 +332,8 @@ func BenchmarkQueue(b *testing.B) {
}()

for i := 0; i < b.N; i++ {
q.Put(`a`)
// benchmark focuses on throughput
_ = q.Put(`a`)
}

wg.Wait()
Expand Down Expand Up @@ -347,9 +365,12 @@ func BenchmarkChannel(b *testing.B) {

func TestPeek(t *testing.T) {
q := New(10)
q.Put(`a`)
q.Put(`b`)
q.Put(`c`)
err := q.Put(`a`)
assert.Nil(t, err)
err = q.Put(`b`)
assert.Nil(t, err)
err = q.Put(`c`)
assert.Nil(t, err)
peekResult, err := q.Peek()
peekExpected := `a`
assert.Nil(t, err)
Expand All @@ -373,7 +394,8 @@ func TestPeekOnDisposedQueue(t *testing.T) {

func TestGetUntil(t *testing.T) {
q := New(10)
q.Put(`a`, `b`, `c`)
err := q.Put(`a`, `b`, `c`)
assert.Nil(t, err)
result, err := q.GetUntil(func(item interface{}) bool {
return item != `c`
})
Expand Down Expand Up @@ -402,7 +424,8 @@ func TestGetUntilEmptyQueue(t *testing.T) {

func TestGetUntilThenGet(t *testing.T) {
q := New(10)
q.Put(`a`, `b`, `c`)
err := q.Put(`a`, `b`, `c`)
assert.Nil(t, err)
takeItems, _ := q.GetUntil(func(item interface{}) bool {
return item != `c`
})
Expand All @@ -414,7 +437,8 @@ func TestGetUntilThenGet(t *testing.T) {

func TestGetUntilNoMatches(t *testing.T) {
q := New(10)
q.Put(`a`, `b`, `c`)
err := q.Put(`a`, `b`, `c`)
assert.Nil(t, err)
takeItems, _ := q.GetUntil(func(item interface{}) bool {
return item != `a`
})
Expand Down Expand Up @@ -500,7 +524,8 @@ func TestWaiters(t *testing.T) {
func TestExecuteInParallel(t *testing.T) {
q := New(10)
for i := 0; i < 10; i++ {
q.Put(i)
err := q.Put(i)
assert.Nil(t, err)
}

numCalls := uint64(0)
Expand Down Expand Up @@ -537,7 +562,8 @@ func BenchmarkQueuePut(b *testing.B) {
for i := 0; i < b.N; i++ {
q := qs[i]
for j := int64(0); j < numItems; j++ {
q.Put(j)
// benchmark focuses on throughput
_ = q.Put(j)
}
}
}
Expand All @@ -550,7 +576,8 @@ func BenchmarkQueueGet(b *testing.B) {
for i := 0; i < b.N; i++ {
q := New(numItems)
for j := int64(0); j < numItems; j++ {
q.Put(j)
// benchmark setup
_ = q.Put(j)
}
qs = append(qs, q)
}
Expand All @@ -560,7 +587,8 @@ func BenchmarkQueueGet(b *testing.B) {
for i := 0; i < b.N; i++ {
q := qs[i]
for j := int64(0); j < numItems; j++ {
q.Get(1)
// benchmark focuses on throughput
_, _ = q.Get(1)
}
}
}
Expand All @@ -573,7 +601,8 @@ func BenchmarkQueuePoll(b *testing.B) {
for i := 0; i < b.N; i++ {
q := New(numItems)
for j := int64(0); j < numItems; j++ {
q.Put(j)
// benchmark setup
_ = q.Put(j)
}
qs = append(qs, q)
}
Expand All @@ -582,7 +611,8 @@ func BenchmarkQueuePoll(b *testing.B) {

for _, q := range qs {
for j := int64(0); j < numItems; j++ {
q.Poll(1, time.Millisecond)
// benchmark focuses on throughput
_, _ = q.Poll(1, time.Millisecond)
}
}
}
Expand All @@ -595,7 +625,8 @@ func BenchmarkExecuteInParallel(b *testing.B) {
for i := 0; i < b.N; i++ {
q := New(numItems)
for j := int64(0); j < numItems; j++ {
q.Put(j)
// benchmark setup
_ = q.Put(j)
}
qs = append(qs, q)
}
Expand Down
6 changes: 4 additions & 2 deletions database/kv/etcd/v3/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,8 @@ func NewClientWithOptions(ctx context.Context, opts *Options) (*Client, error) {
// NOTICE: need to get the lock before calling this method
func (c *Client) clean() {
// close raw client
c.rawClient.Close()
// cleanup prioritizes resource release
_ = c.rawClient.Close()

// cancel ctx for raw client
c.cancel()
Expand Down Expand Up @@ -456,7 +457,8 @@ func (c *Client) keepAliveKV(k string, v string) error {

keepAlive, err := rawClient.KeepAlive(c.ctx, lease.ID)
if err != nil || keepAlive == nil {
rawClient.Revoke(c.ctx, lease.ID)
// prioritize returning keepalive failure
_, _ = rawClient.Revoke(c.ctx, lease.ID)
if err != nil {
return perrors.WithMessage(err, "keep alive lease")
}
Expand Down
6 changes: 3 additions & 3 deletions database/kv/etcd/v3/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ func (suite *ClientTestSuite) SetupSuite() {
}

suite.etcd = e
return
}

// stop etcd server
Expand All @@ -136,9 +135,10 @@ func (suite *ClientTestSuite) setUpClient() *Client {
// set up a client for suite
func (suite *ClientTestSuite) SetupTest() {
c := suite.setUpClient()
c.CleanKV()
if err := c.CleanKV(); err != nil {
suite.T().Fatal("CleanKV failed:", err)
}
suite.client = c
return
}

func (suite *ClientTestSuite) TestClientClose() {
Expand Down
Loading
Loading