@@ -41,6 +41,17 @@ def spanner_client():
41
41
return client .Client ()
42
42
43
43
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
+
44
55
@pytest .fixture (scope = "session" )
45
56
def cleanup_old_instances (spanner_client ):
46
57
"""Delete instances, created by samples, that are older than an hour."""
@@ -54,11 +65,7 @@ def cleanup_old_instances(spanner_client):
54
65
create_time = int (inst .labels ["created" ])
55
66
56
67
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 )
62
69
63
70
64
71
@pytest .fixture (scope = "module" )
@@ -76,19 +83,15 @@ def instance_config(spanner_client):
76
83
77
84
@pytest .fixture (scope = "module" )
78
85
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 ,
84
87
):
85
88
sample_instance = spanner_client .instance (
86
89
instance_id ,
87
90
instance_config ,
88
91
labels = {
89
92
"cloud_spanner_samples" : "true" ,
90
93
"sample_name" : sample_name ,
91
- "created" : str (int (time .time ()))
94
+ "created" : str (int (time .time ())),
92
95
},
93
96
)
94
97
retry_429 = retry .RetryErrors (exceptions .ResourceExhausted , delay = 15 )
0 commit comments