From bf447e89d4d0a9060dbebda2dd1b4a5047f3b915 Mon Sep 17 00:00:00 2001 From: Cathy Ouyang Date: Thu, 10 Mar 2022 15:09:04 -0800 Subject: [PATCH 1/2] fix(storage): add backoff to retry flaky test --- .../check_latest_transfer_operation_test.py | 29 ++++++++++++------- 1 file changed, 19 insertions(+), 10 deletions(-) diff --git a/storagetransfer/check_latest_transfer_operation_test.py b/storagetransfer/check_latest_transfer_operation_test.py index c294e07fc9c..b6bd95a5642 100644 --- a/storagetransfer/check_latest_transfer_operation_test.py +++ b/storagetransfer/check_latest_transfer_operation_test.py @@ -26,8 +26,7 @@ @pytest.fixture() def transfer_job( - project_id: str, source_bucket: Bucket, destination_bucket: Bucket): - # Create job + project_id: str, source_bucket: Bucket, destination_bucket: Bucket): client = storage_transfer.StorageTransferServiceClient() transfer_job = { "description": "Sample job", @@ -53,18 +52,28 @@ def transfer_job( "delete_objects_from_source_after_transfer": True}, }, } - result = client.create_transfer_job({"transfer_job": transfer_job}) + + # Create job + @backoff.on_exception(backoff.expo, HttpError, max_time=60) + def create_job(): + return client.create_transfer_job({"transfer_job": transfer_job}) + + result = create_job() yield result.name # Remove job - client.update_transfer_job({ - "job_name": result.name, - "project_id": project_id, - "transfer_job": { - "status": storage_transfer.TransferJob.Status.DELETED - } - }) + @backoff.on_exception(backoff.expo, HttpError, max_time=60) + def remove_job(): + client.update_transfer_job({ + "job_name": result.name, + "project_id": project_id, + "transfer_job": { + "status": storage_transfer.TransferJob.Status.DELETED + } + }) + + remove_job() @backoff.on_exception(backoff.expo, (RetryError,), max_time=60) From dc427391d75b08a2457828752302b256fc361e5d Mon Sep 17 00:00:00 2001 From: Cathy Ouyang Date: Thu, 10 Mar 2022 16:13:20 -0800 Subject: [PATCH 2/2] fix lint --- .../check_latest_transfer_operation_test.py | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/storagetransfer/check_latest_transfer_operation_test.py b/storagetransfer/check_latest_transfer_operation_test.py index b6bd95a5642..74780ee4070 100644 --- a/storagetransfer/check_latest_transfer_operation_test.py +++ b/storagetransfer/check_latest_transfer_operation_test.py @@ -25,8 +25,7 @@ @pytest.fixture() -def transfer_job( - project_id: str, source_bucket: Bucket, destination_bucket: Bucket): +def transfer_job(project_id: str, source_bucket: Bucket, destination_bucket: Bucket): client = storage_transfer.StorageTransferServiceClient() transfer_job = { "description": "Sample job", @@ -65,13 +64,13 @@ def create_job(): # Remove job @backoff.on_exception(backoff.expo, HttpError, max_time=60) def remove_job(): - client.update_transfer_job({ - "job_name": result.name, - "project_id": project_id, - "transfer_job": { - "status": storage_transfer.TransferJob.Status.DELETED + client.update_transfer_job( + { + "job_name": result.name, + "project_id": project_id, + "transfer_job": {"status": storage_transfer.TransferJob.Status.DELETED}, } - }) + ) remove_job()