Commit 002d650
authored
tests: cleanup stale databases in spanner system tests (#17668)
### Problem
Spanner system tests can sometimes leave behind test databases if a run
is interrupted or fails to clean up properly. Over time, these stale
databases can accumulate, potentially hitting quota limits or cluttering
the test environment.
### Solution
Introduced a proactive cleanup mechanism to remove stale databases
during test setup.
* **Added `cleanup_stale_databases` helper**: A new function in
`_helpers.py` that lists databases in a given instance and drops any
that are older than a specified cutoff (defaulting to 10 minutes/600
seconds).
* **Drop Protection Handling**: The helper explicitly disables
`enable_drop_protection` if it's set, ensuring that even protected test
databases can be cleaned up automatically.
* **Fixture Integration**: Integrated this cleanup call into the
`shared_instance` fixture in `conftest.py`, ensuring that every test
session starts by cleaning up residue from previous runs.
### Impact
* Reduces the risk of test failures due to database quota exhaustion.
* Keeps the Spanner instance used for testing clean.
* Resilient against partial failures by handling `NotFound` and other
API errors during cleanup.1 parent 00b9040 commit 002d650
2 files changed
Lines changed: 28 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
| 20 | + | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| |||
159 | 159 | | |
160 | 160 | | |
161 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
162 | 186 | | |
163 | 187 | | |
164 | 188 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
20 | | - | |
21 | 20 | | |
22 | 21 | | |
23 | 22 | | |
| |||
218 | 217 | | |
219 | 218 | | |
220 | 219 | | |
| 220 | + | |
| 221 | + | |
221 | 222 | | |
222 | 223 | | |
223 | 224 | | |
| |||
0 commit comments