-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat: add enhanced retry options with delay and condition support #8548
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your PR. Looks good, but needs some polishing.
Please, add this change to the documentation and add some tests that work with this feature
packages/runner/src/types/runner.ts
Outdated
testTimeout: number | ||
hookTimeout: number | ||
retry: number | ||
retry: number | { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see that the type is repeated often. Maybe it should be a separate type in ./tasks
?
packages/runner/src/run.ts
Outdated
catch (e) { | ||
failTask(test.result, e, runner.config.diffOptions) | ||
|
||
const error = test.result.errors?.[0]?.error as Error |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain this line, please? Why do we need to go to test.result.errors?.[0]?.error
when e
is available already?
} | ||
} | ||
|
||
// update retry info |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not remove comments not related to the changes made
} | ||
} | ||
|
||
// if test is marked to be failed, flip the result |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's not remove comments not related to the changes made
description: | ||
'Retry the test specific number of times if it fails (default: `0`)', | ||
argument: '<times>', | ||
'Retry configuration. Can be a number or JSON string with advanced options (default: `0`)', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It cannot be a JSON string, the value would be defined as --retry.count=5 --retry.strategy=immediate
'Stop test execution when given number of tests have failed (default: `0`)', | ||
argument: '<number>', | ||
}, | ||
retry: { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please, add a test for CLI input to test/core/cli-test.test.ts
argument: '<milliseconds>', | ||
}, | ||
condition: { | ||
description: 'Condition for retrying: RegExp pattern or custom function', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this needs an explanation where this pattern is applied. According to types, you can also pass down a string, but this message doesn't mention it
* @default 0 | ||
*/ | ||
retry?: number | ||
retry?: number | { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep comments, please
@@ -0,0 +1,70 @@ | |||
import type { SerializedConfig } from '../runtime/config' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This whole file should be in packages/runner
. There is no reason to keep it in another package
export function calculateBackoffDelay( | ||
baseDelay: number, | ||
retryCount: number, | ||
algorithm: 'linear' | 'exponential' = 'linear' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am a bit confused why this needs to be customizable when we always pass down exponential
. Should this check be removed?
7d78989
to
2b66c7c
Compare
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
✅ Deploy Preview for vitest-dev ready!Built without sensitive environment variables
To edit notification comments on pull requests, go to your Netlify project configuration. |
The tests are failing. |
/** | ||
* Times to retry the test if fails. Useful for making flaky tests more stable. | ||
* When retries is up, the last test error will be thrown. | ||
* | ||
* @default 0 | ||
*/ | ||
retry?: number |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't the doc-comment be replaced/extended instead of removed completely?
Description
This PR implements enhanced retry options for Vitest tests, extending the current simple retry mechanism with advanced configuration capabilities.
fixes: #8482
What This PR Solves
The current Vitest retry mechanism only supports a fixed number of retries on any kind of error. This PR adds:
New Retry Features:
retryStrategy
: Choose when retries are executed ("immediate"
,"test-file"
,"deferred"
)retryDelay
: Configurable delay between retries with exponential backoffretryCondition
: Conditional retry based on error type (string patterns, RegExp, or custom functions)Backward Compatibility:
retry: number
syntaxImplementation Details
Files Modified:
packages/vitest/src/node/types/config.ts
packages/runner/src/run.ts
packages/vitest/src/node/cli/cli-config.ts
packages/vitest/src/utils/retry.ts
(new file)Key Features: