-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
balancer: fix tests not properly updating subconn states #6501
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -128,13 +128,13 @@ func (s) TestDropByCategory(t *testing.T) { | |
} | ||
|
||
sc1 := <-cc.NewSubConnCh | ||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
// This should get the connecting picker. | ||
if err := cc.WaitForPickerWithErr(ctx, balancer.ErrNoSubConnAvailable); err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
// Test pick with one backend. | ||
|
||
const rpcCount = 20 | ||
|
@@ -283,13 +283,13 @@ func (s) TestDropCircuitBreaking(t *testing.T) { | |
} | ||
|
||
sc1 := <-cc.NewSubConnCh | ||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
// This should get the connecting picker. | ||
if err := cc.WaitForPickerWithErr(ctx, balancer.ErrNoSubConnAvailable); err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
// Test pick with one backend. | ||
const rpcCount = 100 | ||
if err := cc.WaitForPicker(ctx, func(p balancer.Picker) error { | ||
|
@@ -375,7 +375,11 @@ func (s) TestPickerUpdateAfterClose(t *testing.T) { | |
UpdateClientConnState: func(bd *stub.BalancerData, ccs balancer.ClientConnState) error { | ||
// Create a subConn which will be used later on to test the race | ||
// between UpdateSubConnState() and Close(). | ||
bd.ClientConn.NewSubConn(ccs.ResolverState.Addresses, balancer.NewSubConnOptions{}) | ||
sc, err := bd.ClientConn.NewSubConn(ccs.ResolverState.Addresses, balancer.NewSubConnOptions{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here, with the |
||
if err != nil { | ||
return err | ||
} | ||
sc.Connect() | ||
return nil | ||
}, | ||
UpdateSubConnState: func(bd *stub.BalancerData, _ balancer.SubConn, _ balancer.SubConnState) { | ||
|
@@ -410,7 +414,7 @@ func (s) TestPickerUpdateAfterClose(t *testing.T) { | |
// that we use as the child policy will not send a picker update until the | ||
// parent policy is closed. | ||
sc1 := <-cc.NewSubConnCh | ||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
b.Close() | ||
close(closeCh) | ||
|
||
|
@@ -449,7 +453,7 @@ func (s) TestClusterNameInAddressAttributes(t *testing.T) { | |
} | ||
|
||
sc1 := <-cc.NewSubConnCh | ||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
// This should get the connecting picker. | ||
if err := cc.WaitForPickerWithErr(ctx, balancer.ErrNoSubConnAvailable); err != nil { | ||
t.Fatal(err.Error()) | ||
|
@@ -464,7 +468,7 @@ func (s) TestClusterNameInAddressAttributes(t *testing.T) { | |
t.Fatalf("sc is created with addr with cluster name %v, %v, want cluster name %v", cn, ok, testClusterName) | ||
} | ||
|
||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
// Test pick with one backend. | ||
if err := cc.WaitForRoundRobinPicker(ctx, sc1); err != nil { | ||
t.Fatal(err.Error()) | ||
|
@@ -524,13 +528,13 @@ func (s) TestReResolution(t *testing.T) { | |
} | ||
|
||
sc1 := <-cc.NewSubConnCh | ||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
// This should get the connecting picker. | ||
if err := cc.WaitForPickerWithErr(ctx, balancer.ErrNoSubConnAvailable); err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.TransientFailure}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.TransientFailure}) | ||
// This should get the transient failure picker. | ||
if err := cc.WaitForErrPicker(ctx); err != nil { | ||
t.Fatal(err.Error()) | ||
|
@@ -543,13 +547,13 @@ func (s) TestReResolution(t *testing.T) { | |
t.Fatalf("timeout waiting for ResolveNow()") | ||
} | ||
|
||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
// Test pick with one backend. | ||
if err := cc.WaitForRoundRobinPicker(ctx, sc1); err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.TransientFailure}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.TransientFailure}) | ||
// This should get the transient failure picker. | ||
if err := cc.WaitForErrPicker(ctx); err != nil { | ||
t.Fatal(err.Error()) | ||
|
@@ -608,13 +612,13 @@ func (s) TestLoadReporting(t *testing.T) { | |
} | ||
|
||
sc1 := <-cc.NewSubConnCh | ||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
// This should get the connecting picker. | ||
if err := cc.WaitForPickerWithErr(ctx, balancer.ErrNoSubConnAvailable); err != nil { | ||
t.Fatal(err.Error()) | ||
} | ||
|
||
b.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
// Test pick with one backend. | ||
const successCount = 5 | ||
const errorCount = 5 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -169,8 +169,8 @@ func TestClusterPicks(t *testing.T) { | |
// Clear the attributes before adding to map. | ||
addrs[0].BalancerAttributes = nil | ||
m1[addrs[0]] = sc | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
} | ||
|
||
p1 := <-cc.NewPickerCh | ||
|
@@ -247,8 +247,8 @@ func TestConfigUpdateAddCluster(t *testing.T) { | |
// Clear the attributes before adding to map. | ||
addrs[0].BalancerAttributes = nil | ||
m1[addrs[0]] = sc | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
} | ||
|
||
p1 := <-cc.NewPickerCh | ||
|
@@ -313,8 +313,8 @@ func TestConfigUpdateAddCluster(t *testing.T) { | |
// Clear the attributes before adding to map. | ||
addrs[0].BalancerAttributes = nil | ||
m1[addrs[0]] = sc | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
|
||
// Should have no more newSubConn. | ||
select { | ||
|
@@ -404,8 +404,8 @@ func TestRoutingConfigUpdateDeleteAll(t *testing.T) { | |
// Clear the attributes before adding to map. | ||
addrs[0].BalancerAttributes = nil | ||
m1[addrs[0]] = sc | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
} | ||
|
||
p1 := <-cc.NewPickerCh | ||
|
@@ -488,8 +488,8 @@ func TestRoutingConfigUpdateDeleteAll(t *testing.T) { | |
// Clear the attributes before adding to map. | ||
addrs[0].BalancerAttributes = nil | ||
m2[addrs[0]] = sc | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
} | ||
|
||
p3 := <-cc.NewPickerCh | ||
|
@@ -582,7 +582,11 @@ var errTestInitIdle = fmt.Errorf("init Idle balancer error 0") | |
func init() { | ||
stub.Register(initIdleBalancerName, stub.BalancerFuncs{ | ||
UpdateClientConnState: func(bd *stub.BalancerData, opts balancer.ClientConnState) error { | ||
bd.ClientConn.NewSubConn(opts.ResolverState.Addresses, balancer.NewSubConnOptions{}) | ||
sc, err := bd.ClientConn.NewSubConn(opts.ResolverState.Addresses, balancer.NewSubConnOptions{}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And here? |
||
if err != nil { | ||
return err | ||
} | ||
sc.Connect() | ||
return nil | ||
}, | ||
UpdateSubConnState: func(bd *stub.BalancerData, sc balancer.SubConn, state balancer.SubConnState) { | ||
|
@@ -632,7 +636,7 @@ func TestInitialIdle(t *testing.T) { | |
// in the address is cleared. | ||
for range wantAddrs { | ||
sc := <-cc.NewSubConnCh | ||
rtb.UpdateSubConnState(sc, balancer.SubConnState{ConnectivityState: connectivity.Idle}) | ||
sc.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Idle}) | ||
} | ||
|
||
if state1 := <-cc.NewStateCh; state1 != connectivity.Idle { | ||
|
@@ -673,8 +677,8 @@ func TestClusterGracefulSwitch(t *testing.T) { | |
} | ||
|
||
sc1 := <-cc.NewSubConnCh | ||
rtb.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
rtb.UpdateSubConnState(sc1, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc1.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
p1 := <-cc.NewPickerCh | ||
pi := balancer.PickInfo{ | ||
Ctx: SetPickedCluster(context.Background(), "csp:cluster"), | ||
|
@@ -703,7 +707,7 @@ func TestClusterGracefulSwitch(t *testing.T) { | |
// Update the pick first balancers SubConn as CONNECTING. This will cause | ||
// the pick first balancer to UpdateState() with CONNECTING, which shouldn't send | ||
// a Picker update back, as the Graceful Switch process is not complete. | ||
rtb.UpdateSubConnState(sc2, balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
sc2.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Connecting}) | ||
ctx, cancel := context.WithTimeout(context.Background(), defaultTestShortTimeout) | ||
defer cancel() | ||
select { | ||
|
@@ -716,7 +720,7 @@ func TestClusterGracefulSwitch(t *testing.T) { | |
// the pick first balancer to UpdateState() with READY, which should send a | ||
// Picker update back, as the Graceful Switch process is complete. This | ||
// Picker should always pick the pick first's created SubConn. | ||
rtb.UpdateSubConnState(sc2, balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
sc2.UpdateState(balancer.SubConnState{ConnectivityState: connectivity.Ready}) | ||
p2 := <-cc.NewPickerCh | ||
testPick(t, p2, pi, sc2, nil) | ||
// The Graceful Switch process completing for the child should cause the | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't we need to set the
StateListener
here?