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

xds: Properly assign picker. #9201

Merged
merged 2 commits into from May 25, 2022
Merged

Conversation

temawi
Copy link
Contributor

@temawi temawi commented May 24, 2022

Fixes a bug where the picker was not getting used in RpcBehaviorLoadBalancer.

@temawi temawi requested a review from ejona86 May 24, 2022 22:59
Copy link
Member

@ejona86 ejona86 left a comment

Choose a reason for hiding this comment

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

You need to change the RpcBehaviorLoadBalancer constructor to not wrap as well.

@temawi temawi force-pushed the rpc_behavior_lb_picker_fix branch from 1e2447a to a699057 Compare May 24, 2022 23:19
Fixes a bug where the picker was not getting used in RpcBehaviorLoadBalancer.
@temawi temawi force-pushed the rpc_behavior_lb_picker_fix branch from a699057 to 5ae580e Compare May 24, 2022 23:31
@@ -61,7 +60,7 @@ public class RpcBehaviorLoadBalancerProviderTest {
private LoadBalancer mockDelegateLb;

@Mock
private Helper mockHelper;
private RpcBehaviorHelper mockHelper;
Copy link
Member

Choose a reason for hiding this comment

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

This looks busted. I see the tests would mostly work, but this doesn't instill confidence. One place we wrap a RpcBehaviorHelper with a (mock that claims to be) RpcBehaviorHelper and in the other we pass the mock directly into the LB constructor. Seems this should be Helper (which is a pseudo-interface). If you mock a real object, you should pretty much always use delegatesTo(); but in this case the object being mocked is also under test, so that seems strange.

Note that you can easily have a non-mock RpcBehaviorHelper field if you use mock(Helper.class) instead of @Mock. Otherwise you'd need to construct it in each test (not a big problem because it is only used twice... although I think that shows the other tests aren't that great[1]) or use @Before.

  1. "Not getting into it now," but helperWrapsPicker() to me is a perfect example of what you get when you make "the unit" be "a single class" along with white box testing. That test should have failed, but didn't, because it didn't test that RpcBehaviorLoadBalancer actually used RpcBehaviorHelper. To me, it'd be best to combine it with pickerAddsRpcBehaviorMetadata() and confirm that RpcBehaviorLoadBalancer as a whole does the one job it is supposed to do. RpcBehaviorPicker would be a private class and not referenced in the test at all. Without combining it all together, the tests are brittle (as they mirror the implementation 1:1 as it is testing internal constraints and not external constraints) and don't actually test the code does what it should. I could delete the line in RpcBehaviorLoadBalancer that calls setRpcBehavior() and all the tests would pass.

@temawi
Copy link
Contributor Author

temawi commented May 25, 2022

Ok noted, we can look at the general testing approach here. For now I just updated mockHelper to use the Helper class.

@temawi temawi merged commit fc406e8 into grpc:master May 25, 2022
@temawi temawi deleted the rpc_behavior_lb_picker_fix branch May 25, 2022 19:40
@temawi temawi added the TODO:backport PR needs to be backported. Removed after backport complete label May 26, 2022
temawi added a commit to temawi/grpc-java that referenced this pull request May 27, 2022
* xds: Properly assign picker.

Fixes a bug where the picker was not getting used in RpcBehaviorLoadBalancer.
temawi added a commit that referenced this pull request May 27, 2022
* xds: Properly assign picker.

Fixes a bug where the picker was not getting used in RpcBehaviorLoadBalancer.
@temawi temawi removed the TODO:backport PR needs to be backported. Removed after backport complete label May 27, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 26, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants