Skip to content

Commit 412338c

Browse files
committed
tests: harden old instance cleanup against NotFound
Toward #435, #436, #437.
1 parent 2487800 commit 412338c

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

samples/samples/conftest.py

+14-11
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,17 @@ def spanner_client():
4141
return client.Client()
4242

4343

44+
def scrub_instance_ignore_not_found(to_scrub):
45+
"""Helper for func:`cleanup_old_instances`"""
46+
try:
47+
for backup_pb in to_scrub.list_backups():
48+
backup.Backup.from_pb(backup_pb, to_scrub).delete()
49+
50+
to_scrub.delete()
51+
except exceptions.NotFound:
52+
pass
53+
54+
4455
@pytest.fixture(scope="session")
4556
def cleanup_old_instances(spanner_client):
4657
"""Delete instances, created by samples, that are older than an hour."""
@@ -54,11 +65,7 @@ def cleanup_old_instances(spanner_client):
5465
create_time = int(inst.labels["created"])
5566

5667
if create_time <= cutoff:
57-
58-
for backup_pb in inst.list_backups():
59-
backup.Backup.from_pb(backup_pb, inst).delete()
60-
61-
inst.delete()
68+
scrub_instance_ignore_not_found(inst)
6269

6370

6471
@pytest.fixture(scope="module")
@@ -76,19 +83,15 @@ def instance_config(spanner_client):
7683

7784
@pytest.fixture(scope="module")
7885
def sample_instance(
79-
spanner_client,
80-
cleanup_old_instances,
81-
instance_id,
82-
instance_config,
83-
sample_name,
86+
spanner_client, cleanup_old_instances, instance_id, instance_config, sample_name,
8487
):
8588
sample_instance = spanner_client.instance(
8689
instance_id,
8790
instance_config,
8891
labels={
8992
"cloud_spanner_samples": "true",
9093
"sample_name": sample_name,
91-
"created": str(int(time.time()))
94+
"created": str(int(time.time())),
9295
},
9396
)
9497
retry_429 = retry.RetryErrors(exceptions.ResourceExhausted, delay=15)

0 commit comments

Comments
 (0)