Skip to content

Commit 6d935d5

Browse files
test(spanner): fix backup restore TimeoutError and premature instance cleanup (#17150)
1 parent 16ab4c2 commit 6d935d5

2 files changed

Lines changed: 7 additions & 7 deletions

File tree

packages/google-cloud-spanner/samples/samples/backup_sample_test.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ def test_copy_backup_with_multiple_kms_keys(
135135

136136

137137
@pytest.mark.dependency(depends=["create_backup"])
138-
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
138+
@RetryErrors(exception=(DeadlineExceeded, TimeoutError), max_tries=2)
139139
def test_restore_database(capsys, instance_id, sample_database):
140140
backup_sample.restore_database(instance_id, RESTORE_DB_ID, BACKUP_ID)
141141
out, _ = capsys.readouterr()
@@ -145,7 +145,7 @@ def test_restore_database(capsys, instance_id, sample_database):
145145

146146

147147
@pytest.mark.dependency(depends=["create_backup_with_encryption_key"])
148-
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
148+
@RetryErrors(exception=(DeadlineExceeded, TimeoutError), max_tries=2)
149149
def test_restore_database_with_encryption_key(
150150
capsys,
151151
instance_id,
@@ -164,7 +164,7 @@ def test_restore_database_with_encryption_key(
164164

165165
@pytest.mark.skip(reason="skipped since the KMS keys are not added on test project")
166166
@pytest.mark.dependency(depends=["create_backup_with_multiple_kms_keys"])
167-
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
167+
@RetryErrors(exception=(DeadlineExceeded, TimeoutError), max_tries=2)
168168
def test_restore_database_with_multiple_kms_keys(
169169
capsys,
170170
multi_region_instance_id,
@@ -243,7 +243,7 @@ def test_cancel_backup(capsys, instance_id, sample_database):
243243
assert cancel_success or cancel_failure
244244

245245

246-
@RetryErrors(exception=DeadlineExceeded, max_tries=2)
246+
@RetryErrors(exception=(DeadlineExceeded, TimeoutError), max_tries=2)
247247
def test_create_database_with_retention_period(capsys, sample_instance):
248248
backup_sample.create_database_with_version_retention_period(
249249
sample_instance.instance_id,

packages/google-cloud-spanner/samples/samples/conftest.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,14 +79,14 @@ def scrub_instance_ignore_not_found(to_scrub):
7979
pass
8080

8181
retry_cleanup(to_scrub.delete)()
82-
except exceptions.NotFound:
82+
except exceptions.GoogleAPICallError:
8383
pass
8484

8585

8686
@pytest.fixture(scope="session")
8787
def cleanup_old_instances(spanner_client):
88-
"""Delete instances, created by samples, that are older than an hour."""
89-
cutoff = int(time.time()) - 1 * 60 * 60
88+
"""Delete instances, created by samples, that are older than 4 hours."""
89+
cutoff = int(time.time()) - 4 * 60 * 60
9090
instance_filter = "labels.cloud_spanner_samples:true"
9191

9292
for instance_pb in spanner_client.list_instances(filter_=instance_filter):

0 commit comments

Comments
 (0)