Skip to content
Merged
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
22 changes: 7 additions & 15 deletions balancer_switching_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"google.golang.org/grpc/connectivity"
_ "google.golang.org/grpc/grpclog/glogger"
"google.golang.org/grpc/internal"
"google.golang.org/grpc/internal/leakcheck"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver/manual"
)
Expand Down Expand Up @@ -129,8 +128,7 @@ func checkRoundRobin(cc *ClientConn, servers []*server) error {
return nil
}

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

Expand Down Expand Up @@ -161,8 +159,7 @@ func TestSwitchBalancer(t *testing.T) {
}

// Test that balancer specified by dial option will not be overridden.
func TestBalancerDialOption(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestBalancerDialOption(t *testing.T) {
r, rcleanup := manual.GenerateAndRegisterManualResolver()
defer rcleanup()

Expand All @@ -189,8 +186,7 @@ func TestBalancerDialOption(t *testing.T) {
}

// First addr update contains grpclb.
func TestSwitchBalancerGRPCLBFirst(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestSwitchBalancerGRPCLBFirst(t *testing.T) {
r, rcleanup := manual.GenerateAndRegisterManualResolver()
defer rcleanup()

Expand Down Expand Up @@ -251,8 +247,7 @@ func TestSwitchBalancerGRPCLBFirst(t *testing.T) {
}

// First addr update does not contain grpclb.
func TestSwitchBalancerGRPCLBSecond(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestSwitchBalancerGRPCLBSecond(t *testing.T) {
r, rcleanup := manual.GenerateAndRegisterManualResolver()
defer rcleanup()

Expand Down Expand Up @@ -329,8 +324,7 @@ func TestSwitchBalancerGRPCLBSecond(t *testing.T) {
// Test that if the current balancer is roundrobin, after switching to grpclb,
// when the resolved address doesn't contain grpclb addresses, balancer will be
// switched back to roundrobin.
func TestSwitchBalancerGRPCLBRoundRobin(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestSwitchBalancerGRPCLBRoundRobin(t *testing.T) {
r, rcleanup := manual.GenerateAndRegisterManualResolver()
defer rcleanup()

Expand Down Expand Up @@ -393,8 +387,7 @@ func TestSwitchBalancerGRPCLBRoundRobin(t *testing.T) {
// Test that if resolved address list contains grpclb, the balancer option in
// service config won't take effect. But when there's no grpclb address in a new
// resolved address list, balancer will be switched to the new one.
func TestSwitchBalancerGRPCLBServiceConfig(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestSwitchBalancerGRPCLBServiceConfig(t *testing.T) {
r, rcleanup := manual.GenerateAndRegisterManualResolver()
defer rcleanup()

Expand Down Expand Up @@ -476,11 +469,10 @@ func TestSwitchBalancerGRPCLBServiceConfig(t *testing.T) {
// The tests sends 3 server addresses (all backends) as resolved addresses, but
// claim the first one is grpclb server. The all RPCs should all be send to the
// other addresses, not the first one.
func TestSwitchBalancerGRPCLBWithGRPCLBNotRegistered(t *testing.T) {
func (s) TestSwitchBalancerGRPCLBWithGRPCLBNotRegistered(t *testing.T) {
internal.BalancerUnregister("grpclb")
defer balancer.Register(&magicalLB{})

defer leakcheck.Check(t)
r, rcleanup := manual.GenerateAndRegisterManualResolver()
defer rcleanup()

Expand Down
37 changes: 12 additions & 25 deletions balancer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (

"google.golang.org/grpc/codes"
_ "google.golang.org/grpc/grpclog/glogger"
"google.golang.org/grpc/internal/leakcheck"
"google.golang.org/grpc/naming"
"google.golang.org/grpc/status"

Expand Down Expand Up @@ -121,8 +120,7 @@ func startServers(t *testing.T, numServers int, maxStreams uint32) ([]*server, *
}
}

func TestNameDiscovery(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestNameDiscovery(t *testing.T) {
// Start 2 servers on 2 ports.
numServers := 2
servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
Expand Down Expand Up @@ -157,8 +155,7 @@ func TestNameDiscovery(t *testing.T) {
}
}

func TestEmptyAddrs(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestEmptyAddrs(t *testing.T) {
servers, r, cleanup := startServers(t, 1, math.MaxUint32)
defer cleanup()
cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
Expand Down Expand Up @@ -189,8 +186,7 @@ func TestEmptyAddrs(t *testing.T) {
}
}

func TestRoundRobin(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestRoundRobin(t *testing.T) {
// Start 3 servers on 3 ports.
numServers := 3
servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
Expand Down Expand Up @@ -236,8 +232,7 @@ func TestRoundRobin(t *testing.T) {
}
}

func TestCloseWithPendingRPC(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestCloseWithPendingRPC(t *testing.T) {
servers, r, cleanup := startServers(t, 1, math.MaxUint32)
defer cleanup()
cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
Expand Down Expand Up @@ -288,8 +283,7 @@ func TestCloseWithPendingRPC(t *testing.T) {
wg.Wait()
}

func TestGetOnWaitChannel(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestGetOnWaitChannel(t *testing.T) {
servers, r, cleanup := startServers(t, 1, math.MaxUint32)
defer cleanup()
cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(RoundRobin(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
Expand Down Expand Up @@ -332,8 +326,7 @@ func TestGetOnWaitChannel(t *testing.T) {
wg.Wait()
}

func TestOneServerDown(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestOneServerDown(t *testing.T) {
// Start 2 servers.
numServers := 2
servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
Expand Down Expand Up @@ -385,8 +378,7 @@ func TestOneServerDown(t *testing.T) {
wg.Wait()
}

func TestOneAddressRemoval(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestOneAddressRemoval(t *testing.T) {
// Start 2 servers.
numServers := 2
servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
Expand Down Expand Up @@ -463,8 +455,7 @@ func checkServerUp(t *testing.T, currentServer *server) {
}
}

func TestPickFirstEmptyAddrs(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestPickFirstEmptyAddrs(t *testing.T) {
servers, r, cleanup := startServers(t, 1, math.MaxUint32)
defer cleanup()
cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(pickFirstBalancerV1(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
Expand Down Expand Up @@ -495,8 +486,7 @@ func TestPickFirstEmptyAddrs(t *testing.T) {
}
}

func TestPickFirstCloseWithPendingRPC(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestPickFirstCloseWithPendingRPC(t *testing.T) {
servers, r, cleanup := startServers(t, 1, math.MaxUint32)
defer cleanup()
cc, err := Dial("passthrough:///foo.bar.com", WithBalancer(pickFirstBalancerV1(r)), WithBlock(), WithInsecure(), WithCodec(testCodec{}))
Expand Down Expand Up @@ -547,8 +537,7 @@ func TestPickFirstCloseWithPendingRPC(t *testing.T) {
wg.Wait()
}

func TestPickFirstOrderAllServerUp(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestPickFirstOrderAllServerUp(t *testing.T) {
// Start 3 servers on 3 ports.
numServers := 3
servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
Expand Down Expand Up @@ -660,8 +649,7 @@ func TestPickFirstOrderAllServerUp(t *testing.T) {
}
}

func TestPickFirstOrderOneServerDown(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestPickFirstOrderOneServerDown(t *testing.T) {
// Start 3 servers on 3 ports.
numServers := 3
servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
Expand Down Expand Up @@ -751,8 +739,7 @@ func TestPickFirstOrderOneServerDown(t *testing.T) {
}
}

func TestPickFirstOneAddressRemoval(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestPickFirstOneAddressRemoval(t *testing.T) {
// Start 2 servers.
numServers := 2
servers, r, cleanup := startServers(t, numServers, math.MaxUint32)
Expand Down
16 changes: 5 additions & 11 deletions call_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ import (
"time"

"google.golang.org/grpc/codes"
"google.golang.org/grpc/internal/leakcheck"
"google.golang.org/grpc/internal/transport"
"google.golang.org/grpc/status"
)
Expand Down Expand Up @@ -214,8 +213,7 @@ func setUp(t *testing.T, port int, maxStreams uint32) (*server, *ClientConn) {
return server, cc
}

func TestInvoke(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestInvoke(t *testing.T) {
server, cc := setUp(t, 0, math.MaxUint32)
var reply string
if err := cc.Invoke(context.Background(), "/foo/bar", &expectedRequest, &reply); err != nil || reply != expectedResponse {
Expand All @@ -225,8 +223,7 @@ func TestInvoke(t *testing.T) {
server.stop()
}

func TestInvokeLargeErr(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestInvokeLargeErr(t *testing.T) {
server, cc := setUp(t, 0, math.MaxUint32)
var reply string
req := "hello"
Expand All @@ -242,8 +239,7 @@ func TestInvokeLargeErr(t *testing.T) {
}

// TestInvokeErrorSpecialChars checks that error messages don't get mangled.
func TestInvokeErrorSpecialChars(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestInvokeErrorSpecialChars(t *testing.T) {
server, cc := setUp(t, 0, math.MaxUint32)
var reply string
req := "weird error"
Expand All @@ -259,8 +255,7 @@ func TestInvokeErrorSpecialChars(t *testing.T) {
}

// TestInvokeCancel checks that an Invoke with a canceled context is not sent.
func TestInvokeCancel(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestInvokeCancel(t *testing.T) {
server, cc := setUp(t, 0, math.MaxUint32)
var reply string
req := "canceled"
Expand All @@ -278,8 +273,7 @@ func TestInvokeCancel(t *testing.T) {

// TestInvokeCancelClosedNonFail checks that a canceled non-failfast RPC
// on a closed client will terminate.
func TestInvokeCancelClosedNonFailFast(t *testing.T) {
defer leakcheck.Check(t)
func (s) TestInvokeCancelClosedNonFailFast(t *testing.T) {
server, cc := setUp(t, 0, math.MaxUint32)
var reply string
cc.Close()
Expand Down
19 changes: 4 additions & 15 deletions clientconn_state_transition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ import (
"golang.org/x/net/http2"
"google.golang.org/grpc/balancer"
"google.golang.org/grpc/connectivity"
"google.golang.org/grpc/internal/leakcheck"
"google.golang.org/grpc/internal/testutils"
"google.golang.org/grpc/resolver"
"google.golang.org/grpc/resolver/manual"
Expand All @@ -46,9 +45,7 @@ func init() {
// These tests use a pipeListener. This listener is similar to net.Listener
// except that it is unbuffered, so each read and write will wait for the other
// side's corresponding write or read.
func TestStateTransitions_SingleAddress(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestStateTransitions_SingleAddress(t *testing.T) {
mctBkp := getMinConnectTimeout()
defer func() {
atomic.StoreInt64((*int64)(&mutableMinConnectTimeout), int64(mctBkp))
Expand Down Expand Up @@ -151,8 +148,6 @@ client enters TRANSIENT FAILURE.`,
}

func testStateTransitionSingleAddress(t *testing.T, want []connectivity.State, server func(net.Listener) net.Conn) {
defer leakcheck.Check(t)

stateNotifications := make(chan connectivity.State, len(want))
testBalancer.ResetNotifier(stateNotifications)

Expand Down Expand Up @@ -202,9 +197,7 @@ func testStateTransitionSingleAddress(t *testing.T, want []connectivity.State, s
}

// When a READY connection is closed, the client enters TRANSIENT FAILURE before CONNECTING.
func TestStateTransitions_ReadyToTransientFailure(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestStateTransitions_ReadyToTransientFailure(t *testing.T) {
want := []connectivity.State{
connectivity.Connecting,
connectivity.Ready,
Expand Down Expand Up @@ -273,9 +266,7 @@ func TestStateTransitions_ReadyToTransientFailure(t *testing.T) {

// When the first connection is closed, the client enters stays in CONNECTING
// until it tries the second address (which succeeds, and then it enters READY).
func TestStateTransitions_TriesAllAddrsBeforeTransientFailure(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestStateTransitions_TriesAllAddrsBeforeTransientFailure(t *testing.T) {
want := []connectivity.State{
connectivity.Connecting,
connectivity.Ready,
Expand Down Expand Up @@ -370,9 +361,7 @@ func TestStateTransitions_TriesAllAddrsBeforeTransientFailure(t *testing.T) {
// When there are multiple addresses, and we enter READY on one of them, a
// later closure should cause the client to enter TRANSIENT FAILURE before it
// re-enters CONNECTING.
func TestStateTransitions_MultipleAddrsEntersReady(t *testing.T) {
defer leakcheck.Check(t)

func (s) TestStateTransitions_MultipleAddrsEntersReady(t *testing.T) {
want := []connectivity.State{
connectivity.Connecting,
connectivity.Ready,
Expand Down
Loading