Skip to content

Commit

Permalink
Modified tests to use tlogger. (#3343)
Browse files Browse the repository at this point in the history
* Modified tests to use tlogger.

* Fail on errors, with error expectations.

* Added expects and MixedCapsed grpclb_config tests

* Moved tlogger to grpctest, moved leakcheck tester to grpctest.go

* Added ExpectErrorN()

* Removed redundant leak checks

* Fixed new test

* Made tlogger globals into tlogger methods

* ErrorsLeft -> EndTest

* Removed some redundant lines

* Fixed error in test and empty map in EndTest
  • Loading branch information
GarrettGutierrez1 committed Feb 6, 2020
1 parent cb03b9f commit 132187f
Show file tree
Hide file tree
Showing 77 changed files with 1,036 additions and 614 deletions.
4 changes: 2 additions & 2 deletions balancer/grpclb/grpclb_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
"google.golang.org/grpc/serviceconfig"
)

func Test_Parse(t *testing.T) {
func (s) TestParse(t *testing.T) {
tests := []struct {
name string
s string
Expand Down Expand Up @@ -71,7 +71,7 @@ func Test_Parse(t *testing.T) {
}
}

func Test_childIsPickFirst(t *testing.T) {
func (s) TestChildIsPickFirst(t *testing.T) {
tests := []struct {
name string
s string
Expand Down
63 changes: 24 additions & 39 deletions balancer/grpclb/grpclb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/credentials"
_ "google.golang.org/grpc/grpclog/glogger"
"google.golang.org/grpc/internal/leakcheck"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/metadata"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/resolver"
Expand All @@ -59,6 +59,14 @@ var (
fakeName = "fake.Name"
)

type s struct {
grpctest.Tester
}

func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

type serverNameCheckCreds struct {
mu sync.Mutex
sn string
Expand Down Expand Up @@ -383,9 +391,7 @@ func newLoadBalancer(numberOfBackends int, statsChan chan *lbpb.ClientStats) (ts
return
}

func TestGRPCLB(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestGRPCLB(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -429,9 +435,7 @@ func TestGRPCLB(t *testing.T) {
}

// The remote balancer sends response with duplicates to grpclb client.
func TestGRPCLBWeighted(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestGRPCLBWeighted(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -497,9 +501,7 @@ func TestGRPCLBWeighted(t *testing.T) {
}
}

func TestDropRequest(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestDropRequest(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -650,9 +652,7 @@ func TestDropRequest(t *testing.T) {
}

// When the balancer in use disconnects, grpclb should connect to the next address from resolved balancer address list.
func TestBalancerDisconnects(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestBalancerDisconnects(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -727,12 +727,10 @@ func TestBalancerDisconnects(t *testing.T) {
t.Fatalf("No RPC sent to second backend after 1 second")
}

func TestFallback(t *testing.T) {
func (s) TestFallback(t *testing.T) {
balancer.Register(newLBBuilderWithFallbackTimeout(100 * time.Millisecond))
defer balancer.Register(newLBBuilder())

defer leakcheck.Check(t)

r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -860,9 +858,7 @@ func TestFallback(t *testing.T) {
}
}

func TestExplicitFallback(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestExplicitFallback(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -965,9 +961,7 @@ func TestExplicitFallback(t *testing.T) {
}
}

func TestFallBackWithNoServerAddress(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestFallBackWithNoServerAddress(t *testing.T) {
resolveNowCh := make(chan struct{}, 1)
r, cleanup := manual.GenerateAndRegisterManualResolver()
r.ResolveNowCallback = func(resolver.ResolveNowOptions) {
Expand Down Expand Up @@ -1087,9 +1081,7 @@ func TestFallBackWithNoServerAddress(t *testing.T) {
}
}

func TestGRPCLBPickFirst(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestGRPCLBPickFirst(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -1301,8 +1293,7 @@ const (
failtosendURI = "failtosend"
)

func TestGRPCLBStatsUnarySuccess(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestGRPCLBStatsUnarySuccess(t *testing.T) {
if err := runAndCheckStats(t, false, nil, func(cc *grpc.ClientConn) {
testC := testpb.NewTestServiceClient(cc)
// The first non-failfast RPC succeeds, all connections are up.
Expand All @@ -1321,8 +1312,7 @@ func TestGRPCLBStatsUnarySuccess(t *testing.T) {
}
}

func TestGRPCLBStatsUnaryDrop(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestGRPCLBStatsUnaryDrop(t *testing.T) {
if err := runAndCheckStats(t, true, nil, func(cc *grpc.ClientConn) {
testC := testpb.NewTestServiceClient(cc)
// The first non-failfast RPC succeeds, all connections are up.
Expand All @@ -1342,8 +1332,7 @@ func TestGRPCLBStatsUnaryDrop(t *testing.T) {
}
}

func TestGRPCLBStatsUnaryFailedToSend(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestGRPCLBStatsUnaryFailedToSend(t *testing.T) {
if err := runAndCheckStats(t, false, nil, func(cc *grpc.ClientConn) {
testC := testpb.NewTestServiceClient(cc)
// The first non-failfast RPC succeeds, all connections are up.
Expand All @@ -1363,8 +1352,7 @@ func TestGRPCLBStatsUnaryFailedToSend(t *testing.T) {
}
}

func TestGRPCLBStatsStreamingSuccess(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestGRPCLBStatsStreamingSuccess(t *testing.T) {
if err := runAndCheckStats(t, false, nil, func(cc *grpc.ClientConn) {
testC := testpb.NewTestServiceClient(cc)
// The first non-failfast RPC succeeds, all connections are up.
Expand Down Expand Up @@ -1397,8 +1385,7 @@ func TestGRPCLBStatsStreamingSuccess(t *testing.T) {
}
}

func TestGRPCLBStatsStreamingDrop(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestGRPCLBStatsStreamingDrop(t *testing.T) {
if err := runAndCheckStats(t, true, nil, func(cc *grpc.ClientConn) {
testC := testpb.NewTestServiceClient(cc)
// The first non-failfast RPC succeeds, all connections are up.
Expand Down Expand Up @@ -1432,8 +1419,7 @@ func TestGRPCLBStatsStreamingDrop(t *testing.T) {
}
}

func TestGRPCLBStatsStreamingFailedToSend(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestGRPCLBStatsStreamingFailedToSend(t *testing.T) {
if err := runAndCheckStats(t, false, nil, func(cc *grpc.ClientConn) {
testC := testpb.NewTestServiceClient(cc)
// The first non-failfast RPC succeeds, all connections are up.
Expand All @@ -1459,8 +1445,7 @@ func TestGRPCLBStatsStreamingFailedToSend(t *testing.T) {
}
}

func TestGRPCLBStatsQuashEmpty(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestGRPCLBStatsQuashEmpty(t *testing.T) {
ch := make(chan *lbpb.ClientStats)
defer close(ch)
if err := runAndCheckStats(t, false, ch, func(cc *grpc.ClientConn) {
Expand Down
6 changes: 3 additions & 3 deletions balancer/grpclb/grpclb_util_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func checkCacheCC(ccc *lbCacheClientConn, sccLen, sctaLen int) error {
}

// Test that SubConn won't be immediately removed.
func TestLBCacheClientConnExpire(t *testing.T) {
func (s) TestLBCacheClientConnExpire(t *testing.T) {
mcc := newMockClientConn()
if err := checkMockCC(mcc, 0); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestLBCacheClientConnExpire(t *testing.T) {

// Test that NewSubConn with the same address of a SubConn being removed will
// reuse the SubConn and cancel the removing.
func TestLBCacheClientConnReuse(t *testing.T) {
func (s) TestLBCacheClientConnReuse(t *testing.T) {
mcc := newMockClientConn()
if err := checkMockCC(mcc, 0); err != nil {
t.Fatal(err)
Expand Down Expand Up @@ -220,7 +220,7 @@ func TestLBCacheClientConnReuse(t *testing.T) {

// Test that if the timer to remove a SubConn fires at the same time NewSubConn
// cancels the timer, it doesn't cause deadlock.
func TestLBCache_RemoveTimer_New_Race(t *testing.T) {
func (s) TestLBCache_RemoveTimer_New_Race(t *testing.T) {
mcc := newMockClientConn()
if err := checkMockCC(mcc, 0); err != nil {
t.Fatal(err)
Expand Down
31 changes: 16 additions & 15 deletions balancer/roundrobin/roundrobin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,22 @@ import (
"google.golang.org/grpc/codes"
"google.golang.org/grpc/connectivity"
_ "google.golang.org/grpc/grpclog/glogger"
"google.golang.org/grpc/internal/leakcheck"
"google.golang.org/grpc/internal/grpctest"
"google.golang.org/grpc/peer"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver/manual"
"google.golang.org/grpc/status"
testpb "google.golang.org/grpc/test/grpc_testing"
)

type s struct {
grpctest.Tester
}

func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

type testServer struct {
testpb.UnimplementedTestServiceServer
}
Expand Down Expand Up @@ -90,8 +98,7 @@ func startTestServers(count int) (_ *test, err error) {
return t, nil
}

func TestOneBackend(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestOneBackend(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -121,8 +128,7 @@ func TestOneBackend(t *testing.T) {
}
}

func TestBackendsRoundRobin(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestBackendsRoundRobin(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -181,8 +187,7 @@ func TestBackendsRoundRobin(t *testing.T) {
}
}

func TestAddressesRemoved(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestAddressesRemoved(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -239,8 +244,7 @@ func TestAddressesRemoved(t *testing.T) {

}

func TestCloseWithPendingRPC(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestCloseWithPendingRPC(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -273,8 +277,7 @@ func TestCloseWithPendingRPC(t *testing.T) {
wg.Wait()
}

func TestNewAddressWhileBlocking(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestNewAddressWhileBlocking(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -321,8 +324,7 @@ func TestNewAddressWhileBlocking(t *testing.T) {
wg.Wait()
}

func TestOneServerDown(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestOneServerDown(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down Expand Up @@ -419,8 +421,7 @@ func TestOneServerDown(t *testing.T) {
}
}

func TestAllServersDown(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestAllServersDown(t *testing.T) {
r, cleanup := manual.GenerateAndRegisterManualResolver()
defer cleanup()

Expand Down
18 changes: 14 additions & 4 deletions benchmark/flags/flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,19 @@ import (
"reflect"
"testing"
"time"

"google.golang.org/grpc/internal/grpctest"
)

func TestStringWithAllowedValues(t *testing.T) {
type s struct {
grpctest.Tester
}

func Test(t *testing.T) {
grpctest.RunSubTests(t, s{})
}

func (s) TestStringWithAllowedValues(t *testing.T) {
const defaultVal = "default"
tests := []struct {
args string
Expand Down Expand Up @@ -54,7 +64,7 @@ func TestStringWithAllowedValues(t *testing.T) {
}
}

func TestDurationSlice(t *testing.T) {
func (s) TestDurationSlice(t *testing.T) {
defaultVal := []time.Duration{time.Second, time.Nanosecond}
tests := []struct {
args string
Expand Down Expand Up @@ -83,7 +93,7 @@ func TestDurationSlice(t *testing.T) {
}
}

func TestIntSlice(t *testing.T) {
func (s) TestIntSlice(t *testing.T) {
defaultVal := []int{1, 1024}
tests := []struct {
args string
Expand Down Expand Up @@ -112,7 +122,7 @@ func TestIntSlice(t *testing.T) {
}
}

func TestStringSlice(t *testing.T) {
func (s) TestStringSlice(t *testing.T) {
defaultVal := []string{"bar", "baz"}
tests := []struct {
args string
Expand Down
Loading

0 comments on commit 132187f

Please sign in to comment.