-
Notifications
You must be signed in to change notification settings - Fork 3.9k
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
Make unit tests that forcibly exercise async security policies codepaths. #10835
Conversation
The usage of Futures.immediateFuture makes the implementation take several shortcuts to process server authorization. This leads to PendingAuthListener being under-tested. This commit adds delays to the futures in the hope that they will be triggered by the new codepaths. Before: https://fusion2.corp.google.com/invocations/fafaa334-2ac1-4d12-814c-33755fa08ad6/coverage After: https://fusion2.corp.google.com/invocations/6e3b4b41-461b-418d-8e9f-d9043dc3e5c6/coverage Part of grpc#10566.
binder/src/androidTest/java/io/grpc/binder/BinderSecurityTest.java
Outdated
Show resolved
Hide resolved
binder/src/test/java/io/grpc/binder/BinderTransportSecurityTest.java
Outdated
Show resolved
Hide resolved
binder/src/test/java/io/grpc/binder/BinderTransportSecurityTest.java
Outdated
Show resolved
Hide resolved
binder/src/test/java/io/grpc/binder/BinderTransportSecurityTest.java
Outdated
Show resolved
Hide resolved
binder/src/test/java/io/grpc/binder/BinderTransportSecurityTest.java
Outdated
Show resolved
Hide resolved
} | ||
|
||
void setSecurityPolicyStatusWhenReady(Status status) { | ||
Uninterruptibles.takeUninterruptibly(statusesToSet).set(status); |
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 also appears to block the main thread, in the common case where the server hasn't seen the request yet.
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.
That was intentional. At this point, the test has nothing else to do but wait until the gRPC's executor has ran, invoked the AsyncSecurityPolicy
and placed a new SettableFuture<Status>
into the queue.
This is meant to work somewhat like a CyclicBarrier: I want to have the test thread and the gRPC thread synchronized at the same point: after this line. Thus, the test must wait until the queue has an entry as a signal that the implementation has generated the future.
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.
But how do you know that the gRPC executor hasn't enqueued something to run on the main thread and won't run the ServerCallHandler until that completes => Now you are deadlocked because your main thread won't service the event loop again until the ServerCallHandler runs.
It seems to me that you need to poll for this, not block, and idle() the single main looper between take() attempts.
binder/src/test/java/io/grpc/binder/RobolectricBinderSecurityTest.java
Outdated
Show resolved
Hide resolved
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. Can you do a --runs_per_test 1000 to make sure it isn't flaky?
|
binder/src/test/java/io/grpc/binder/RobolectricBinderSecurityTest.java
Outdated
Show resolved
Hide resolved
binder/src/test/java/io/grpc/binder/RobolectricBinderSecurityTest.java
Outdated
Show resolved
Hide resolved
Looks like this doesn't build at the moment ... |
I broke myself with #10836. Should be fixed now. |
The usage of Futures.immediateFuture makes the implementation take several shortcuts to process server authorization. This leads to PendingAuthListener being under-tested.
This commit adds delays to the futures in the hope that they will be triggered by the new codepaths.
Before: https://fusion2.corp.google.com/invocations/fafaa334-2ac1-4d12-814c-33755fa08ad6/coverage
After: https://fusion2.corp.google.com/invocations/6e3b4b41-461b-418d-8e9f-d9043dc3e5c6/coverage
Part of #10566.