-
Notifications
You must be signed in to change notification settings - Fork 361
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
fix(storage): only backoff before resume attempts #14427
Merged
coryan
merged 2 commits into
googleapis:main
from
coryan:fix-storage-only-sleep-before-resume-attempts
Jul 3, 2024
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,7 @@ | |
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "google/cloud/storage/internal/retry_object_read_source.h" | ||
#include "google/cloud/storage/internal/connection_impl.h" | ||
#include "google/cloud/storage/retry_policy.h" | ||
#include "google/cloud/storage/testing/canonical_errors.h" | ||
|
@@ -32,6 +33,7 @@ using ::google::cloud::storage::testing::MockGenericStub; | |
using ::google::cloud::storage::testing::MockObjectReadSource; | ||
using ::google::cloud::storage::testing::canonical_errors::PermanentError; | ||
using ::google::cloud::storage::testing::canonical_errors::TransientError; | ||
using ::google::cloud::testing_util::StatusIs; | ||
using ::testing::_; | ||
using ::testing::Contains; | ||
using ::testing::HasSubstr; | ||
|
@@ -222,21 +224,22 @@ TEST(RetryObjectReadSourceTest, BackoffPolicyResetOnSuccess) { | |
|
||
// raw_source1 and raw_source2 fail, then a success | ||
ASSERT_STATUS_OK((*source)->Read(nullptr, 1024)); | ||
// Two retries, so the backoff policy was called twice. | ||
EXPECT_EQ(2, num_backoff_policy_called); | ||
// The backoff should have been cloned during the read. | ||
// Two retries, the first one does not get a backoff, so there should be one | ||
// call to OnCompletion. | ||
EXPECT_EQ(1, num_backoff_policy_called); | ||
// The backoff should have been cloned during the Read() call. | ||
EXPECT_EQ(initial_clone_count + 2, backoff_policy_mock.NumClones()); | ||
// The backoff policy was used twice in the first retry. | ||
EXPECT_EQ(2, backoff_policy_mock.NumCallsFromLastClone()); | ||
// The backoff policy was used once in the first retry. | ||
EXPECT_EQ(1, backoff_policy_mock.NumCallsFromLastClone()); | ||
|
||
// raw_source3 fails, then a success | ||
ASSERT_STATUS_OK((*source)->Read(nullptr, 1024)); | ||
// This read caused a third retry. | ||
EXPECT_EQ(3, num_backoff_policy_called); | ||
// This read caused another retry, but no call to backoff. | ||
EXPECT_EQ(1, num_backoff_policy_called); | ||
// The backoff should have been cloned during the read. | ||
EXPECT_EQ(initial_clone_count + 3, backoff_policy_mock.NumClones()); | ||
// The backoff policy was only once in the second retry. | ||
EXPECT_EQ(1, backoff_policy_mock.NumCallsFromLastClone()); | ||
// The backoff policy was cloned once, but never used in the second retry. | ||
EXPECT_EQ(0, backoff_policy_mock.NumCallsFromLastClone()); | ||
} | ||
|
||
/// @test Check that retry policy is shared between reads and resetting session | ||
|
@@ -269,6 +272,50 @@ TEST(RetryObjectReadSourceTest, RetryPolicyExhaustedOnResetSession) { | |
EXPECT_THAT(res.status().message(), HasSubstr("Retry policy exhausted")); | ||
} | ||
|
||
/// @test Check that retry policy is shared between reads and resetting session | ||
TEST(RetryObjectReadSourceTest, ResumePolicyOrder) { | ||
::testing::MockFunction<void(std::chrono::milliseconds)> backoff; | ||
::testing::MockFunction<StatusOr<std::unique_ptr<ObjectReadSource>>( | ||
ReadObjectRangeRequest const&, RetryPolicy&, BackoffPolicy&)> | ||
factory; | ||
|
||
auto make_partial = [] { | ||
auto source = std::make_unique<MockObjectReadSource>(); | ||
EXPECT_CALL(*source, Read).WillOnce(Return(TransientError())); | ||
return std::unique_ptr<ObjectReadSource>(std::move(source)); | ||
}; | ||
|
||
auto source = std::make_unique<MockObjectReadSource>(); | ||
{ | ||
::testing::InSequence sequence; | ||
EXPECT_CALL(*source, Read) | ||
.WillOnce(Return(ReadSourceResult{static_cast<std::size_t>(512 * 1024), | ||
HttpResponse{100, "", {}}})); | ||
EXPECT_CALL(*source, Read).WillOnce(Return(TransientError())); | ||
// No backoffs to resume after a (partially) successful request: | ||
// EXPECT_CALL(backoff, Call).Times(1); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. remove? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
EXPECT_CALL(factory, Call).WillOnce(make_partial); | ||
EXPECT_CALL(backoff, Call).Times(1); | ||
EXPECT_CALL(factory, Call).WillOnce(make_partial); | ||
EXPECT_CALL(backoff, Call).Times(1); | ||
EXPECT_CALL(factory, Call).WillOnce(make_partial); | ||
} | ||
|
||
auto options = BasicTestPolicies(); | ||
auto retry_policy = options.get<RetryPolicyOption>()->clone(); | ||
auto backoff_policy = options.get<BackoffPolicyOption>()->clone(); | ||
|
||
RetryObjectReadSource tested( | ||
factory.AsStdFunction(), | ||
google::cloud::internal::MakeImmutableOptions(std::move(options)), | ||
ReadObjectRangeRequest{}, std::move(source), std::move(retry_policy), | ||
std::move(backoff_policy), backoff.AsStdFunction()); | ||
|
||
ASSERT_STATUS_OK(tested.Read(nullptr, 1024)); | ||
auto response = tested.Read(nullptr, 1024); | ||
EXPECT_THAT(response, StatusIs(TransientError().code())); | ||
} | ||
|
||
/// @test `ReadLast` behaviour after a transient failure | ||
TEST(RetryObjectReadSourceTest, TransientFailureWithReadLastOption) { | ||
auto mock = std::make_unique<MockGenericStub>(); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
s/closed/cloned/ on L217
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.
Done.