Skip to content

Commit

Permalink
removed deprecated code from tests
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkowalczuk committed Sep 2, 2024
1 parent 4c9de90 commit 72e3b48
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
6 changes: 1 addition & 5 deletions v4/promgrpc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ func BenchmarkUnary_all(b *testing.B) {
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

con, err := grpc.DialContext(ctx, lis.Addr().String(),
grpc.WithInsecure(),
grpc.WithBlock(),
grpc.WithStatsHandler(csh),
)
con, err := grpc.NewClient(lis.Addr().String(), grpc.WithStatsHandler(csh))
if err != nil {
b.Fatal(err)
}
Expand Down
21 changes: 13 additions & 8 deletions v4/util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@ package promgrpc_test

import (
"context"
"errors"
"testing"
"time"

"github.com/piotrkowalczuk/promgrpc/v4"
"github.com/piotrkowalczuk/promgrpc/v4/pb/private/test"
"github.com/prometheus/client_golang/prometheus"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
)

func suite(t *testing.T) (test.TestServiceClient, *prometheus.Registry, func(*testing.T)) {
lis := listener(t)

ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
_, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()

ssh := promgrpc.ServerStatsHandler(
Expand All @@ -33,24 +35,27 @@ func suite(t *testing.T) (test.TestServiceClient, *prometheus.Registry, func(*te
registerCollector(t, reg, csh)

go func() {
if err := srv.Serve(lis); err != grpc.ErrServerStopped {
if err := srv.Serve(lis); !errors.Is(err, grpc.ErrServerStopped) {
if err != nil {
t.Error(err)
}
}
}()

con, err := grpc.DialContext(ctx, lis.Addr().String(),
grpc.WithInsecure(),
grpc.WithBlock(),
cli, err := grpc.NewClient(lis.Addr().String(),
grpc.WithTransportCredentials(insecure.NewCredentials()),
grpc.WithStatsHandler(csh),
grpc.WithUserAgent("test"),
)
grpc.WithUserAgent("test"))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() {
if err := cli.Close(); err != nil {
t.Error(err)
}
})

return test.NewTestServiceClient(con), reg, func(t *testing.T) {
return test.NewTestServiceClient(cli), reg, func(t *testing.T) {
srv.GracefulStop()
}
}

0 comments on commit 72e3b48

Please sign in to comment.