Skip to content

Commit d57f3e7

Browse files
authored
cleanup(flake): add retry loop to mitigate flakiness (#9752)
1 parent 404d9a8 commit d57f3e7

File tree

1 file changed

+36
-2
lines changed

1 file changed

+36
-2
lines changed

google/cloud/bigquery/integration_tests/bigquery_read_integration_test.cc

Lines changed: 36 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,11 @@
1313
// limitations under the License.
1414

1515
#include "google/cloud/bigquery/bigquery_read_client.h"
16+
#include "google/cloud/bigquery/bigquery_read_connection_idempotency_policy.h"
1617
#include "google/cloud/bigquery/bigquery_read_options.h"
1718
#include "google/cloud/bigquery/internal/bigquery_read_stub_factory.h"
1819
#include "google/cloud/common_options.h"
20+
#include "google/cloud/idempotency.h"
1921
#include "google/cloud/internal/getenv.h"
2022
#include "google/cloud/log.h"
2123
#include "google/cloud/testing_util/integration_test.h"
@@ -35,6 +37,31 @@ using ::testing::HasSubstr;
3537
using ::testing::Not;
3638
using ::testing::NotNull;
3739

40+
/// In order to reduce flakiness, allow retries on CreateReadSession and
41+
/// SplitReadStream.
42+
class RelaxedTestIdempotencyPolicy
43+
: public BigQueryReadConnectionIdempotencyPolicy {
44+
public:
45+
~RelaxedTestIdempotencyPolicy() override = default;
46+
47+
std::unique_ptr<BigQueryReadConnectionIdempotencyPolicy> clone()
48+
const override {
49+
return absl::make_unique<RelaxedTestIdempotencyPolicy>();
50+
}
51+
52+
google::cloud::Idempotency CreateReadSession(
53+
google::cloud::bigquery::storage::v1::CreateReadSessionRequest const&)
54+
override {
55+
return google::cloud::Idempotency::kIdempotent;
56+
}
57+
58+
google::cloud::Idempotency SplitReadStream(
59+
google::cloud::bigquery::storage::v1::SplitReadStreamRequest const&)
60+
override {
61+
return google::cloud::Idempotency::kIdempotent;
62+
}
63+
};
64+
3865
class BigQueryReadIntegrationTest
3966
: public ::google::cloud::testing_util::IntegrationTest {
4067
protected:
@@ -131,8 +158,15 @@ TEST_F(BigQueryReadIntegrationTest, SplitReadStreamProtoFailure) {
131158
}
132159

133160
TEST_F(BigQueryReadIntegrationTest, CreateReadSessionSuccess) {
134-
auto client =
135-
BigQueryReadClient(MakeBigQueryReadConnection(TestSuccessOptions()));
161+
auto client = BigQueryReadClient(MakeBigQueryReadConnection(
162+
TestSuccessOptions()
163+
.set<bigquery::BigQueryReadRetryPolicyOption>(
164+
absl::make_unique<BigQueryReadLimitedErrorCountRetryPolicy>(4))
165+
.set<bigquery::BigQueryReadBackoffPolicyOption>(
166+
absl::make_unique<ExponentialBackoffPolicy>(
167+
std::chrono::seconds(15), std::chrono::seconds(60), 2.0))
168+
.set<bigquery::BigQueryReadConnectionIdempotencyPolicyOption>(
169+
absl::make_unique<RelaxedTestIdempotencyPolicy>())));
136170
::google::cloud::bigquery::storage::v1::ReadSession read_session;
137171
read_session.set_data_format(
138172
google::cloud::bigquery::storage::v1::DataFormat::AVRO);

0 commit comments

Comments
 (0)