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

Make unit tests that forcibly exercise async security policies codepaths. #10835

Merged
merged 11 commits into from
Jan 30, 2024

Conversation

mateusazis
Copy link
Contributor

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.

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.
@mateusazis mateusazis changed the title Force BinderSecurityTest to exercise async security policies codepaths. Make unit tests that forcibly exercise async security policies codepaths. Jan 19, 2024
}

void setSecurityPolicyStatusWhenReady(Status status) {
Uninterruptibles.takeUninterruptibly(statusesToSet).set(status);
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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.

Copy link
Member

@jdcormie jdcormie left a 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?

@mateusazis
Copy link
Contributor Author

LGTM. Can you do a --runs_per_test 1000 to make sure it isn't flaky?

@markb74 markb74 added the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jan 22, 2024
@grpc-kokoro grpc-kokoro removed the kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run label Jan 22, 2024
@jdcormie jdcormie added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Jan 23, 2024
@grpc-kokoro grpc-kokoro removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Jan 23, 2024
@jdcormie
Copy link
Member

Looks like this doesn't build at the moment ...

@mateusazis
Copy link
Contributor Author

Looks like this doesn't build at the moment ...

I broke myself with #10836. Should be fixed now.

@jdcormie jdcormie added the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Jan 29, 2024
@grpc-kokoro grpc-kokoro removed the kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary label Jan 29, 2024
@jdcormie jdcormie added kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary labels Jan 30, 2024
@grpc-kokoro grpc-kokoro removed kokoro:run Add this label to a PR to tell Kokoro the code is safe and tests can be run kokoro:force-run Add this label to a PR to tell Kokoro to re-run all tests. Not generally necessary labels Jan 30, 2024
@jdcormie jdcormie merged commit c2a3792 into grpc:master Jan 30, 2024
14 checks passed
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 30, 2024
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.

4 participants