Skip to content

Commit 8104c5d

Browse files
authored
fix(storage): add backoff to retry flaky test (GoogleCloudPlatform#7582)
* fix(storage): add backoff to retry flaky test * fix lint
1 parent ec6155d commit 8104c5d

1 file changed

Lines changed: 19 additions & 11 deletions

File tree

storagetransfer/check_latest_transfer_operation_test.py

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,7 @@
2525

2626

2727
@pytest.fixture()
28-
def transfer_job(
29-
project_id: str, source_bucket: Bucket, destination_bucket: Bucket):
30-
# Create job
28+
def transfer_job(project_id: str, source_bucket: Bucket, destination_bucket: Bucket):
3129
client = storage_transfer.StorageTransferServiceClient()
3230
transfer_job = {
3331
"description": "Sample job",
@@ -53,18 +51,28 @@ def transfer_job(
5351
"delete_objects_from_source_after_transfer": True},
5452
},
5553
}
56-
result = client.create_transfer_job({"transfer_job": transfer_job})
54+
55+
# Create job
56+
@backoff.on_exception(backoff.expo, HttpError, max_time=60)
57+
def create_job():
58+
return client.create_transfer_job({"transfer_job": transfer_job})
59+
60+
result = create_job()
5761

5862
yield result.name
5963

6064
# Remove job
61-
client.update_transfer_job({
62-
"job_name": result.name,
63-
"project_id": project_id,
64-
"transfer_job": {
65-
"status": storage_transfer.TransferJob.Status.DELETED
66-
}
67-
})
65+
@backoff.on_exception(backoff.expo, HttpError, max_time=60)
66+
def remove_job():
67+
client.update_transfer_job(
68+
{
69+
"job_name": result.name,
70+
"project_id": project_id,
71+
"transfer_job": {"status": storage_transfer.TransferJob.Status.DELETED},
72+
}
73+
)
74+
75+
remove_job()
6876

6977

7078
@backoff.on_exception(backoff.expo, (RetryError,), max_time=60)

0 commit comments

Comments
 (0)