Skip to content

Commit

Permalink
Merge pull request #965 from josephschorr/test-grpc-config
Browse files Browse the repository at this point in the history
Add shorter timeouts and better config to gRPC dialing in tests
  • Loading branch information
josephschorr authored Oct 31, 2022
2 parents f529619 + 1892435 commit 3f78da9
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 2 deletions.
16 changes: 15 additions & 1 deletion internal/services/integrationtesting/cert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
"testing"
"time"

"google.golang.org/grpc/backoff"

v1 "github.com/authzed/authzed-go/proto/authzed/api/v1"
"github.com/stretchr/testify/require"
"google.golang.org/grpc"
Expand Down Expand Up @@ -135,6 +137,7 @@ func TestCertRotation(t *testing.T) {
server.WithDispatchServer(util.GRPCServerConfig{Enabled: false}),
).Complete()
require.NoError(t, err)

srv.SetMiddleware([]grpc.UnaryServerInterceptor{
datastoremw.UnaryServerInterceptor(ds),
consistency.UnaryServerInterceptor(),
Expand All @@ -150,7 +153,18 @@ func TestCertRotation(t *testing.T) {
require.NoError(t, srv.Run(ctx))
}()

conn, err := srv.GRPCDialContext(ctx, grpc.WithReturnConnectionError())
conn, err := srv.GRPCDialContext(ctx,
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.Config{
BaseDelay: 1 * time.Second,
Multiplier: 2,
MaxDelay: 15 * time.Second,
},
}),
)

require.NoError(t, err)
t.Cleanup(func() {
if conn != nil {
Expand Down
14 changes: 13 additions & 1 deletion internal/testserver/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ import (
"strings"
"sync"
"testing"
"time"

"google.golang.org/grpc/backoff"

"github.com/cespare/xxhash/v2"
"github.com/stretchr/testify/require"
Expand Down Expand Up @@ -217,7 +220,16 @@ func TestClusterWithDispatchAndCacheConfig(t testing.TB, size uint, ds datastore
cancelFuncs = append(cancelFuncs, cancel)

dialers = append(dialers, srv.DispatchNetDialContext)
conn, err := srv.GRPCDialContext(ctx, grpc.WithBlock())
conn, err := srv.GRPCDialContext(ctx,
grpc.WithReturnConnectionError(),
grpc.WithBlock(),
grpc.WithConnectParams(grpc.ConnectParams{
Backoff: backoff.Config{
BaseDelay: 1 * time.Second,
Multiplier: 2,
MaxDelay: 15 * time.Second,
},
}))
require.NoError(t, err)
conns = append(conns, conn)
}
Expand Down

0 comments on commit 3f78da9

Please sign in to comment.