Skip to content

Commit 3e40ca7

Browse files
committed
fix: correct exponential backoff delay in tests to prevent RESOURCE_EXHAUSTED errors
1 parent 23ba3f6 commit 3e40ca7

1 file changed

Lines changed: 6 additions & 3 deletions

File tree

contact-center-insights/test/createAnalysis.test.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,14 @@ const delay = async (test, addMs) => {
3131
return;
3232
}
3333
const retries = test.currentRetry();
34-
await new Promise(r => setTimeout(r, addMs));
35-
// No retry on the first failure.
34+
if (addMs) {
35+
await new Promise(r => setTimeout(r, addMs));
36+
} // No retry on the first failure.
3637
if (retries === 0) return;
3738
// See: https://cloud.google.com/storage/docs/exponential-backoff
38-
const ms = Math.pow(2, retries) + Math.random() * 1000;
39+
const backoffBase = Math.pow(2, retries) * 1000;
40+
const jitter = Math.random() * 1000;
41+
const ms = backoffBase + jitter;
3942
return new Promise(done => {
4043
console.info(`retrying "${test.title}" in ${ms}ms`);
4144
setTimeout(done, ms);

0 commit comments

Comments
 (0)