Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(test): add delay between ecosystem tests retry #651

Merged
merged 1 commit into from
Jan 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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