-
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
test: Add unit test for channel state waiting for first resolver update #7768
base: master
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## master #7768 +/- ##
==========================================
+ Coverage 80.25% 81.94% +1.69%
==========================================
Files 367 373 +6
Lines 36622 37880 +1258
==========================================
+ Hits 29391 31042 +1651
+ Misses 6043 5545 -498
- Partials 1188 1293 +105 |
Please merge the latest master. There was a fix for the failing vet test added recently. |
1edec56
to
6ad9713
Compare
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.
LGTM, adding a second reviewer.
|
||
cc.Connect() | ||
|
||
// TODO: Change this assertion to testutils.AwaitState(shortCtx, t, cc, |
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.
Please instead assert the proper behavior and use t.Skip
instead with a message that refers to the issue.
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.
Used t.Skip
with a message.
} | ||
}() | ||
|
||
// TODO: Change this assertion to testutils.AwaitState(shortCtx, t, cc, |
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.
I'm not sure what this part is attempting to test. It should already be CONNECTING per the above assertion.
Addressed above mentioned comments by using t.Skip instead with a message and channel and goroutine |
|
||
done := make(chan struct{}) | ||
go func() { | ||
_, err := testgrpc.NewTestServiceClient(cc).EmptyCall(shortCtx, &testgrpc.Empty{}) |
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.
This shouldn't use the shortCtx
- we only use that for operations we expect to not happen. We want this one to succeed.
Actually...literally everywhere you use shortCtx
is wrong. Use ctx
instead.
But, we should use shortCtx
in one check: before we produce the proper address from the resolver, and after we've asserted that we entered CONNECTING, we should do testutils.AwaitNoStateChange(shortCtx, t, cc, connectivity.Connecting)
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.
used ctx instead of shortCtx
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.
I don't see the AwaitNoStateChange.
testutils.AwaitState(shortCtx, t, cc, connectivity.Ready) | ||
t.Skipf("After entering READY state: current state = %v\n", cc.GetState()) | ||
|
||
mr.UpdateState(resolver.State{Addresses: nil}) |
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.
What's this about?
// TestChannelStateWaitingForFirstResolverUpdate verifies the initial | ||
// state of the channel when a manual name resolver doesn't provide any updates. | ||
func (s) TestChannelStateWaitingForFirstResolverUpdate(t *testing.T) { | ||
if testing.Short() { |
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.
What is this and why?
I think we have a bug, which this test doesn't actually appear to be testing, but which is described in the issue that asked for this test. IF there is a bug, we need to always skip the test.
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.
Yes, we have a bug that's why we added this test to skip.
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.
@janardhanvissa you can skip the test unconditionally, i.e. remote the if testing.Short()
. Also add more details in the skip message.
t.Skip("The channel remains in IDLE until the LB policy updates the state to CONNECTING. This is a bug and the channel should transition to CONNECTING as soon as Connect() is called.")
|
||
cc.Connect() | ||
|
||
testutils.AwaitState(ctx, t, cc, connectivity.Idle) |
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.
This has to be before Connect or else it will race..
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.
connectivity.Idle
moved up before cc.Connect()
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.
This should go above the context creation and just be an assertion that State() == IDLE
. No need to Await
since it should always be in this state upon creation.
|
||
done := make(chan struct{}) | ||
go func() { | ||
_, err := testgrpc.NewTestServiceClient(cc).EmptyCall(shortCtx, &testgrpc.Empty{}) |
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.
I don't see the AwaitNoStateChange.
@janardhanvissa let's re-review it in BLR once since there were many changes after first commit. Closing it for now |
// TestChannelStateWaitingForFirstResolverUpdate verifies the initial | ||
// state of the channel when a manual name resolver doesn't provide any updates. | ||
func (s) TestChannelStateWaitingForFirstResolverUpdate(t *testing.T) { | ||
if testing.Short() { |
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.
@janardhanvissa you can skip the test unconditionally, i.e. remote the if testing.Short()
. Also add more details in the skip message.
t.Skip("The channel remains in IDLE until the LB policy updates the state to CONNECTING. This is a bug and the channel should transition to CONNECTING as soon as Connect() is called.")
Re-reviewing changes requested by the second reviewer.
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.
Can you add another test case similar to the existing one, but that makes an RPC instead of calling cc.Connect()
?
// TestChannelStateWaitingForFirstResolverUpdate verifies the initial | ||
// state of the channel when a manual name resolver doesn't provide any updates. | ||
func (s) TestChannelStateWaitingForFirstResolverUpdate(t *testing.T) { | ||
|
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.
nit: Please remove blank line at the beginning of the method.
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.
removed blank line
Added a new test with RPC call instead of cc.Connect() |
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.
Couple of minor comments, otherwise LGTM!
} | ||
}() | ||
|
||
// The channel should transition to CONNECTING automatically when Connect() |
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.
nit: This comment needs to say "when an RPC is made" instead of "when Connect() is called".
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.
done with the change
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.
Thanks! Looks better, just a couple minor things.
// TestChannelStateWaitingForFirstResolverUpdate verifies the initial | ||
// state of the channel when a manual name resolver doesn't provide any updates. | ||
func (s) TestChannelStateWaitingForFirstResolverUpdate(t *testing.T) { | ||
t.Skip("The channel remains in IDLE until the LB policy updates the state to CONNECTING. This is a bug and the channel should transition to CONNECTING as soon as Connect() is called soon as Connect() is called. See issue #7686.") |
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.
as soon as Connect() is called soon as Connect() is called
-> as soon as Connect() is called
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.
Updated the comment.
} | ||
|
||
func (s) TestChannelStateTransitionWithRPC(t *testing.T) { | ||
t.Skip("The channel remains in IDLE until the LB policy updates the state to CONNECTING. This is a bug and the channel should transition to CONNECTING as soon as an RPC call is made soon as Connect() is called. See issue #7686.") |
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.
Copy/paste issues here too
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.
Updated the comment here as well.
|
||
cc.Connect() | ||
|
||
testutils.AwaitState(ctx, t, cc, connectivity.Idle) |
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.
This should go above the context creation and just be an assertion that State() == IDLE
. No need to Await
since it should always be in this state upon creation.
Replaced the initial AwaitState() call with a direct GetState() check. |
Addresses: #7686
RELEASE NOTES: None