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

chore: Control each response for calls to the IAM Mock Server #1455

Merged
merged 12 commits into from
Aug 15, 2024

Conversation

lqiu96
Copy link
Contributor

@lqiu96 lqiu96 commented Aug 1, 2024

This is part 2 that follows up on: #1452

Once Part 1 is merged, I can rebase this PR to show the diffs (mostly testing related changes) to allow us to test for retrying the IAM Sign Blob RPC.

@product-auto-label product-auto-label bot added the size: l Pull request size is large. label Aug 1, 2024
"36680232662-vrd7ji19qe3nelgchd0ah2csanun6bnr@developer.gserviceaccount.com";

@Test
public void sign_noRetry() throws IOException {
Copy link

Choose a reason for hiding this comment

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

sign_success() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Update to include success. Thanks!

ImpersonatedCredentialsTest.MockIAMCredentialsServiceTransportFactory transportFactory =
new ImpersonatedCredentialsTest.MockIAMCredentialsServiceTransportFactory();
transportFactory.transport.addStatusCodeAndMessage(502, "Bad Gateway");
transportFactory.transport.addStatusCodeAndMessage(502, "Bad Gateway");
Copy link

Choose a reason for hiding this comment

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

Should this fail 3 times to test the boundary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I updated the description for the following test below sign_retryThreeTimes_exception. I believe that will test the retry boundary as it fails three times before giving up.

Copy link

Choose a reason for hiding this comment

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

The idea here was to test the other side of the boundary: does the code allow the "last retry" to be successful? This isn't tested now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Apologies if I'm misunderstanding your point. The retry is configured to retry three times before giving up and I believe the two sides of the boundaries you are talking about are:

  1. Retrying while it hasn't reached the number of attempts limit
  2. Stop retrying after it has reached the number of attempts limit

The first test case sign_retryTwoTimes_success will receive two 5xx errors and should test the first case above.

The second test case sign_retryThreeTimes_exception will receive a four 5xx errors and should test the second case above. It'll retry 3 times and the 4th response will be what is sent back to the user. If it's a 5xx error, it'll throw an exception back, otherwise it'll send the response.

does the code allow the "last retry" to be successful?

If I'm understanding this comment correctly, I'll add another test case where it'll have three 5xx errors before returning a successful response. This should return a success back to the user.

transportFactory.transport,
expectedSignature,
ImmutableMap.of()));
assertTrue(exception.getMessage().contains("Failed to sign the provided bytes"));
Copy link

Choose a reason for hiding this comment

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

Can you assert that the server error is not retried? Or is that implicit in the setup of the transport? -- if so please leave a comment about that.

Otherwise please assert a 2nd call didn't arrive, or have the transport returning a success on 2nd request.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sounds good. I added a method in the transport to track the number of requests being made. This tests should include an assertion assertEquals(4, transportFactory.transport.getNumRequests()); which should ensure that a specific number of retry attempts are made and that the final 5xx errors aren't being retried.

transportFactory.transport.addStatusCodeAndMessage(502, "Bad Gateway");
transportFactory.transport.addStatusCodeAndMessage(502, "Bad Gateway");
transportFactory.transport.addStatusCodeAndMessage(502, "Bad Gateway");
transportFactory.transport.addStatusCodeAndMessage(502, "Bad Gateway");
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe assign different error code each time, so this test is more explicit on reporting back the third failure?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, done! There are a few 5xx errors, so I just swapped them to be 500, 502 and 503. It just reports the last status code that came back once all the retries are exhausted. Hopefully this should be clearer.

@lqiu96 lqiu96 marked this pull request as ready for review August 6, 2024 17:32
@lqiu96 lqiu96 requested a review from a team as a code owner August 6, 2024 17:32
@lqiu96 lqiu96 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 6, 2024
@yoshi-kokoro yoshi-kokoro removed the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Aug 6, 2024
Copy link
Contributor

@zhumin8 zhumin8 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

@lqiu96 lqiu96 merged commit c79f707 into main Aug 15, 2024
21 checks passed
@lqiu96 lqiu96 deleted the signed_url_retries_part2 branch August 15, 2024 15:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size: l Pull request size is large.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants