Commit 2670eab
authored
test(spanner): make samples instance and backup cleanup robust against FailedPrecondition and quota exhaustion (googleapis#17141)
Thank you for opening a Pull Request! Before submitting your PR, there
are a few things you can do to make sure it goes smoothly:
- [ ] Make sure to open an issue as a
[bug/issue](https://github.com/googleapis/google-cloud-python/issues)
before writing your code! That way we can discuss the change, evaluate
designs, and agree on the general idea
- [ ] Ensure the tests and linter pass
- [ ] Code coverage does not decrease (if any source code was changed)
- [ ] Appropriate docs were updated (if necessary)
### Root Cause
During Kokoro continuous test runs for Cloud Spanner samples, tests
restore databases from backups. The restored databases hold active
backend references to the backups (`backup.referencing_databases`) while
optimizing in the background.
During module teardown, `conftest.py` calls `database.drop()` and
immediately iterates to `backup.delete()`. Because `database.drop()` is
asynchronous on the Spanner backend, `backup.delete()` frequently fails
with a `FailedPrecondition` error (backup in use). This unhandled
exception crashes the fixture teardown generator, skipping
`instance.delete()` and leaking instances and backups.
As these leaked resources accumulate across frequent Kokoro runs in the
shared test project, subsequent runs fail due to `ResourceExhausted`
(quota exceeded) errors.
### Solution
- Created a robust retry helper (`retry_cleanup`) that retries on both
`ResourceExhausted` and `FailedPrecondition`.
- Isolated individual database drops and backup deletions within
`try...except exceptions.GoogleAPICallError` blocks so that an error on
a single resource never aborts the scrubbing generator.
- Unified this robust scrubbing logic across `cleanup_old_instances`,
`sample_instance`, and `multi_region_instance` teardown fixtures.1 parent f93911c commit 2670eab
1 file changed
Lines changed: 18 additions & 17 deletions
Lines changed: 18 additions & 17 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
29 | 29 | | |
30 | 30 | | |
31 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
32 | 35 | | |
33 | 36 | | |
34 | 37 | | |
| |||
60 | 63 | | |
61 | 64 | | |
62 | 65 | | |
63 | | - | |
| 66 | + | |
64 | 67 | | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
65 | 74 | | |
66 | | - | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
67 | 80 | | |
68 | | - | |
| 81 | + | |
69 | 82 | | |
70 | 83 | | |
71 | 84 | | |
| |||
154 | 167 | | |
155 | 168 | | |
156 | 169 | | |
157 | | - | |
158 | | - | |
159 | | - | |
160 | | - | |
161 | | - | |
162 | | - | |
163 | | - | |
| 170 | + | |
164 | 171 | | |
165 | 172 | | |
166 | 173 | | |
| |||
189 | 196 | | |
190 | 197 | | |
191 | 198 | | |
192 | | - | |
193 | | - | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
198 | | - | |
| 199 | + | |
199 | 200 | | |
200 | 201 | | |
201 | 202 | | |
| |||
0 commit comments