-
Notifications
You must be signed in to change notification settings - Fork 40
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
feat(auth): Add unit tests for auth failures in gax layer #1394
feat(auth): Add unit tests for auth failures in gax layer #1394
Conversation
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.
/gcbrun
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.
The tests look great! Thanks!
If you think it should be unified, please suggest an implementation approach.
I do think we need to unify the loops. Let's move the call to get the auth headers inside request_attempt()
. I think that should achieve what we want and avoid duplication.
async fn request_attempt<O: serde::de::DeserializeOwned>( |
Something like:
@@ -258,6 +242,14 @@ impl ReqwestClient {
{
builder = builder.timeout(timeout);
}
+ let auth_headers = self
+ .cred
+ .get_headers()
+ .await
+ .map_err(Error::authentication)?;
+ for header in auth_headers.into_iter() {
+ builder = builder.header(header.0, header.1);
+ }
let response = builder.send().await.map_err(Error::io)?;
if !response.status().is_success() {
return Self::to_http_error(response).await;
And we might want to run all of the tests for gax, to make sure we are not breaking existing retry loop tests:
cargo test -p google-cloud-gax
@@ -63,7 +63,7 @@ impl CredentialError { | |||
/// # Arguments | |||
/// * `is_retryable` - A boolean indicating whether the error is retryable. | |||
/// * `message` - The underlying error that caused the auth failure. | |||
pub(crate) fn from_str<T: Into<String>>(is_retryable: bool, message: T) -> Self { | |||
pub fn from_str<T: Into<String>>(is_retryable: bool, message: T) -> Self { |
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.
comment: As I suspected, this was a necessary change to use CredentialError
outside of the google-cloud-auth
crate. Thanks.
d9ea025
to
f08f72f
Compare
Thank you for the review! I also confirmed that the GAX tests pass by running:
|
/gcbrun |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1394 +/- ##
==========================================
+ Coverage 95.93% 96.00% +0.07%
==========================================
Files 37 37
Lines 1475 1477 +2
==========================================
+ Hits 1415 1418 +3
+ Misses 60 59 -1 ☔ View full report in Codecov by Sentry. |
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.
Looks great, thanks!
Description
Fixes: #1350
I implemented the following two unit tests for CredentialError:
auth_error_retryable() { ... }
auth_error_non_retryable() { ... }
I tried to extend the existing retry_loop to implement the authentication loop process, but I couldn't get it to work properly. So, I implemented auth_retry_loop instead.
If you think it should be unified, please suggest an implementation approach.
Test
cargo test -p google-cloud-gax --test auth