Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module support, clean up deprecated functions #32

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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
14 changes: 14 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
module github.com/processout/grpc-go-pool

go 1.21.1

require google.golang.org/grpc v1.58.2

require (
github.com/golang/protobuf v1.5.3 // indirect
golang.org/x/net v0.12.0 // indirect
golang.org/x/sys v0.10.0 // indirect
golang.org/x/text v0.11.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 // indirect
google.golang.org/protobuf v1.31.0 // indirect
)
21 changes: 21 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk=
github.com/golang/protobuf v1.5.3 h1:KhyjKVUg7Usr/dYsdSqoFveMYd5ko72D+zANwlG1mmg=
github.com/golang/protobuf v1.5.3/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY=
github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
golang.org/x/net v0.12.0 h1:cfawfvKITfUsFCeJIHJrbSxpeu/E81khclypR0GVT50=
golang.org/x/net v0.12.0/go.mod h1:zEVYFnQC7m/vmpQFELhcD1EWkZlX69l4oqgmer6hfKA=
golang.org/x/sys v0.10.0 h1:SqMFp9UcQJZa+pmYuAKjd9xq1f0j5rLcDIk0mj4qAsA=
golang.org/x/sys v0.10.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/text v0.11.0 h1:LAntKIrcmeSKERyiOh0XMV39LXS8IE9UL2yP7+f5ij4=
golang.org/x/text v0.11.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98 h1:bVf09lpb+OJbByTj913DRJioFFAjf/ZGxEz7MajTp2U=
google.golang.org/genproto/googleapis/rpc v0.0.0-20230711160842-782d3b101e98/go.mod h1:TUfxEVdsvPg18p6AslUXFoLdpED4oBnGwyqk3dV1XzM=
google.golang.org/grpc v1.58.2 h1:SXUpjxeVF3FKrTYQI4f4KvbGD5u2xccdYdurwowix5I=
google.golang.org/grpc v1.58.2/go.mod h1:tgX3ZQDlNJGU96V6yHh1T/JeoBQ2TXdr43YbYSsCJk0=
google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw=
google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc=
google.golang.org/protobuf v1.31.0 h1:g0LDEJHgrBl9N9r17Ru3sqWhkIx2NB67okBHPwC7hs8=
google.golang.org/protobuf v1.31.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I=
28 changes: 15 additions & 13 deletions pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ import (

"google.golang.org/grpc"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/credentials/insecure"
)

func TestNew(t *testing.T) {
p, err := New(func() (*grpc.ClientConn, error) {
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}, 1, 3, 0)
if err != nil {
t.Errorf("The pool returned an error: %s", err.Error())
Expand Down Expand Up @@ -95,7 +96,7 @@ func TestNew(t *testing.T) {

func TestTimeout(t *testing.T) {
p, err := New(func() (*grpc.ClientConn, error) {
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}, 1, 1, 0)
if err != nil {
t.Errorf("The pool returned an error: %s", err.Error())
Expand All @@ -110,9 +111,10 @@ func TestTimeout(t *testing.T) {
}

// We want to fetch a second one, with a timeout. If the timeout was
// ommitted, the pool would wait indefinitely as it'd wait for another
// omitted, the pool would wait indefinitely as it'd wait for another
// client to get back into the queue
ctx, _ := context.WithDeadline(context.Background(), time.Now().Add(10*time.Millisecond))
ctx, cancel := context.WithDeadline(context.Background(), time.Now().Add(10*time.Millisecond))
defer cancel()
_, err2 := p.Get(ctx)
if err2 != ErrTimeout {
t.Errorf("Expected error \"%s\" but got \"%s\"", ErrTimeout, err2.Error())
Expand All @@ -121,7 +123,7 @@ func TestTimeout(t *testing.T) {

func TestMaxLifeDuration(t *testing.T) {
p, err := New(func() (*grpc.ClientConn, error) {
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}, 1, 1, 0, 1)
if err != nil {
t.Errorf("The pool returned an error: %s", err.Error())
Expand All @@ -145,7 +147,7 @@ func TestMaxLifeDuration(t *testing.T) {
count := 0
p, err = New(func() (*grpc.ClientConn, error) {
count++
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}, 1, 1, 0, time.Minute)
if err != nil {
t.Errorf("The pool returned an error: %s", err.Error())
Expand Down Expand Up @@ -176,7 +178,7 @@ func TestMaxLifeDuration(t *testing.T) {

func TestPoolClose(t *testing.T) {
p, err := New(func() (*grpc.ClientConn, error) {
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}, 1, 1, 0)
if err != nil {
t.Errorf("The pool returned an error: %s", err.Error())
Expand All @@ -200,7 +202,7 @@ func TestPoolClose(t *testing.T) {
}
}

func TestContextCancelation(t *testing.T) {
func TestContextCancellation(t *testing.T) {
ctx, cancel := context.WithCancel(context.Background())
cancel()

Expand All @@ -210,7 +212,7 @@ func TestContextCancelation(t *testing.T) {
return nil, ctx.Err()

default:
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}

}, 1, 1, 0)
Expand All @@ -230,7 +232,7 @@ func TestContextTimeout(t *testing.T) {

// wait for the deadline to pass
case <-time.After(time.Millisecond):
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}

}, 1, 1, 0)
Expand All @@ -242,7 +244,7 @@ func TestContextTimeout(t *testing.T) {

func TestGetContextTimeout(t *testing.T) {
p, err := New(func() (*grpc.ClientConn, error) {
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}, 1, 1, 0)

if err != nil {
Expand Down Expand Up @@ -271,7 +273,7 @@ func TestGetContextFactoryTimeout(t *testing.T) {

// wait for the deadline to pass
case <-time.After(time.Millisecond):
return grpc.Dial("example.com", grpc.WithInsecure())
return grpc.Dial("example.com", grpc.WithTransportCredentials(insecure.NewCredentials()))
}

}, 1, 1, 0)
Expand All @@ -280,7 +282,7 @@ func TestGetContextFactoryTimeout(t *testing.T) {
t.Errorf("The pool returned an error: %s", err.Error())
}

// mark as unhealty the available conn
// mark as unhealthy the available conn
c, err := p.Get(context.Background())
if err != nil {
t.Errorf("Get returned an error: %s", err.Error())
Expand Down