| 127 | } |
| 128 | |
| 129 | const delay = async (test, cleanupFn = null) => { |
| 130 | const retries = test.currentRetry(); |
| 131 | // No retry on the first failure. |
| 132 | if (retries === 0) return; |
| 133 | |
| 134 | // run cleanup for database, provided |
| 135 | if (cleanupFn) { |
| 136 | await cleanupFn(); |
| 137 | } |
| 138 | // See: https://cloud.google.com/storage/docs/exponential-backoff |
| 139 | const ms = Math.pow(2, retries) + Math.random() * 1000; |
| 140 | return new Promise(done => { |
| 141 | console.info(`retrying "${test.title}" in ${ms}ms`); |
| 142 | setTimeout(done, ms); |
| 143 | }); |
| 144 | }; |
| 145 | |
| 146 | async function deleteStaleInstances() { |
| 147 | let [instances] = await spanner.getInstances({ |