Skip to content
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

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

janardhanvissa
Copy link
Contributor

Addresses: #7686

RELEASE NOTES: None

Copy link

codecov bot commented Oct 22, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 81.94%. Comparing base (4bb0170) to head (cd4f22e).
Report is 34 commits behind head on master.

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     

see 70 files with indirect coverage changes

@arjan-bal
Copy link
Contributor

Please merge the latest master. There was a fix for the failing vet test added recently.

arjan-bal
arjan-bal previously approved these changes Oct 23, 2024
Copy link
Contributor

@arjan-bal arjan-bal left a 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,
Copy link
Member

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.

Copy link
Contributor Author

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.

test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
}
}()

// TODO: Change this assertion to testutils.AwaitState(shortCtx, t, cc,
Copy link
Member

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.

test/clientconn_state_transition_test.go Show resolved Hide resolved
@dfawley dfawley assigned janardhanvissa and unassigned dfawley Oct 25, 2024
@janardhanvissa
Copy link
Contributor Author

Addressed above mentioned comments by using t.Skip instead with a message and channel and goroutine

@purnesh42H purnesh42H assigned dfawley and unassigned janardhanvissa Oct 29, 2024

done := make(chan struct{})
go func() {
_, err := testgrpc.NewTestServiceClient(cc).EmptyCall(shortCtx, &testgrpc.Empty{})
Copy link
Member

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)

Copy link
Contributor Author

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

Copy link
Member

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.

test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
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})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's this about?

@dfawley dfawley assigned janardhanvissa and unassigned dfawley Oct 29, 2024
// 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() {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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)
Copy link
Member

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..

Copy link
Contributor Author

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()

Copy link
Member

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.

test/clientconn_state_transition_test.go Show resolved Hide resolved

done := make(chan struct{})
go func() {
_, err := testgrpc.NewTestServiceClient(cc).EmptyCall(shortCtx, &testgrpc.Empty{})
Copy link
Member

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.

@purnesh42H
Copy link
Contributor

@janardhanvissa let's re-review it in BLR once since there were many changes after first commit. Closing it for now

@purnesh42H purnesh42H closed this Oct 30, 2024
@arjan-bal arjan-bal assigned arjan-bal and unassigned janardhanvissa Nov 5, 2024
@arjan-bal arjan-bal reopened this Nov 5, 2024
test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
// 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() {
Copy link
Contributor

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.")

@arjan-bal arjan-bal dismissed their stale review November 5, 2024 06:07

Re-reviewing changes requested by the second reviewer.

@arjan-bal arjan-bal assigned janardhanvissa and unassigned arjan-bal Nov 5, 2024
Copy link
Contributor

@arjan-bal arjan-bal left a 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) {

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed blank line

test/clientconn_state_transition_test.go Show resolved Hide resolved
test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
test/clientconn_state_transition_test.go Show resolved Hide resolved
@janardhanvissa
Copy link
Contributor Author

Added a new test with RPC call instead of cc.Connect()

@arjan-bal arjan-bal assigned arjan-bal and unassigned janardhanvissa Nov 6, 2024
Copy link
Contributor

@arjan-bal arjan-bal left a 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()
Copy link
Contributor

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".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done with the change

test/clientconn_state_transition_test.go Outdated Show resolved Hide resolved
@arjan-bal arjan-bal assigned janardhanvissa and unassigned arjan-bal Nov 6, 2024
Copy link
Member

@dfawley dfawley left a 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.")
Copy link
Member

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

Copy link
Contributor Author

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.")
Copy link
Member

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

Copy link
Contributor Author

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)
Copy link
Member

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.

@dfawley dfawley assigned janardhanvissa and unassigned dfawley Nov 11, 2024
@janardhanvissa
Copy link
Contributor Author

Replaced the initial AwaitState() call with a direct GetState() check.

@arjan-bal arjan-bal assigned dfawley and unassigned janardhanvissa Nov 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants