Skip to content

Commit

Permalink
feat: add TestBufPool
Browse files Browse the repository at this point in the history
  • Loading branch information
buraksezer committed Jul 10, 2021
1 parent 06ddb76 commit 9c76c67
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 39 additions & 0 deletions internal/bufpool/bufpool_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// Copyright 2018-2021 Burak Sezer
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package bufpool

import "testing"

func TestBufPool(t *testing.T) {
p := New()

count := 1000
mebibyte := 1 << 20
total := 10 * mebibyte

b := make([]byte, total/count)

for i := 0; i < count; i++ {
buf := p.Get()
nr, err := buf.Write(b)
if err != nil {
t.Fatalf("Expected nil. Got: %v", err)
}
if nr != total/count {
t.Fatalf("Expected 10. Got: %d", nr)
}
p.Put(buf)
}
}
2 changes: 1 addition & 1 deletion internal/transport/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (c *Client) conn(addr string) (net.Conn, error) {
}

// TODO: Make this configurable
ctx, cancel := context.WithTimeout(context.Background(), 5 * time.Second)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

conn, err := p.Get(ctx)
Expand Down

0 comments on commit 9c76c67

Please sign in to comment.