microsoft / playwright

Playwright is a framework for Web Testing and Automation. It allows testing Chromium, Firefox and WebKit with a single API.
https://playwright.dev
Apache License 2.0
66.98k stars 3.67k forks source link

[Feature]: Add 'retryDelayInMs' Property to API Requests #32318

Open hardeep-qa opened 2 months ago

hardeep-qa commented 2 months ago

🚀 Feature Request

Hi team, I have noticed that the new feature 'maxRetries' has been released in the release 1.46 for the API request, which is great. Can I also please request another property 'retryDelayInMs' to be added alongside 'maxRetries'? This will help us set a delay within the retries.

Please also include the option to retry based on HTTP response code errors.

Example

const response = await request.get(${host}/${projectKey}/categories/key=${data.updateCategory.key}, { failOnStatusCode: true, maxRetries: 4, retryDelayInMs: 3000 });

Motivation

Adding the 'retryDelayInMs' property will allow us to specify a delay between retries, which can help in managing the load on the server and improve the overall stability of the API requests. This feature will be beneficial in scenarios where immediate retries may not be ideal, and a delay can help in achieving better performance and reliability.

refactoreric commented 2 months ago

Asked this in Discord, but probably should do that here (also): Hi @hardeep-qa , do you get that many ECONNRESET errors?

Because that's the only thing that these built-in retries are for: https://playwright.dev/docs/api/class-apirequestcontext#api-request-context-get-option-max-retries

maxRetries number (optional) Added in: v1.46#

Maximum number of times network errors should be retried. Currently only ECONNRESET error is retried. Does not retry based on HTTP response codes. An error will be thrown if the limit is exceeded. Defaults to 0 - no retries.

For the more typical retries (like polling), we use expect.poll: https://playwright.dev/docs/test-assertions#expectpoll

This has built-in support for exponential backoff (sort of), which seems to be close to what you're asking.