Skip to content

Commit

Permalink
chore(test): add delay between ecosystem tests retry (#651)
Browse files Browse the repository at this point in the history
  • Loading branch information
stainless-bot authored Jan 30, 2024
1 parent c9bb4ed commit 6a4cc5c
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions ecosystem-tests/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,15 @@ function parseArgs() {
description: 'number of parallel jobs to run',
},
retry: {
type: 'number',
type: 'count',
default: 0,
description: 'number of times to retry failing jobs',
},
retryDelay: {
type: 'number',
default: 100,
description: 'delay between retries in ms',
},
parallel: {
type: 'boolean',
default: false,
Expand Down Expand Up @@ -271,7 +276,7 @@ async function main() {
console.error('\n');

try {
await withRetry(fn, project, state.retry);
await withRetry(fn, project, state.retry, state.retryDelay);
console.error('\n');
console.error(`✅ ${project}`);
} catch (err) {
Expand All @@ -297,13 +302,21 @@ async function main() {
process.exit(0);
}

async function withRetry(fn: () => Promise<void>, identifier: string, retryAmount: number): Promise<void> {
async function withRetry(
fn: () => Promise<void>,
identifier: string,
retryAmount: number,
retryDelayMs: number,
): Promise<void> {
do {
try {
return await fn();
} catch (err) {
if (--retryAmount <= 0) throw err;
console.error(`${identifier} failed due to ${err}; retries left ${retryAmount}`);
console.error(
`${identifier} failed due to ${err}; retries left ${retryAmount}, next retry in ${retryDelayMs}ms`,
);
await new Promise((resolve) => setTimeout(resolve, retryDelayMs));
}
} while (retryAmount > 0);
}
Expand Down

0 comments on commit 6a4cc5c

Please sign in to comment.