playwright icon indicating copy to clipboard operation
playwright copied to clipboard

[Feature] Flaky Tests - retry all tests at end of the test run

Open mstepin opened this issue 2 years ago • 17 comments

It would be ideal to have a configuration option where flaky tests are retried at the end of the run once all other tests are finished. I see it was discussed here, but that one was closed and not sure the concept was since revisited.

This becomes a lot more relevant when using worker-scoped fixtures, since the thread gets torn down and all the auto: true worker-scoped fixtures are retriggered for the new thread. Since many of these startup actions are expensive both in time and resource, it makes more sense for the failed tests to share new threads at the end of the run.

My personal vision of a solution would be a config setting in playwright.config file eg retry-strategy: 'tailing'. Doing it this way would also open the opportunity for other configurations such as not starting a new thread on failure, or max number of hard fails, conditional retries etc.

mstepin avatar May 29 '23 23:05 mstepin

You can use postinstall to replace one line in the file:

You need to replace this._queue.unshift(result.newJob) with this._queue.push(result.newJob)

Source file: https://github.com/microsoft/playwright/blob/release-1.40/packages/playwright/src/runner/dispatcher.ts#L126 Compiled file (in your project): /node_modules/@playwright/test/lib/runner/dispatcher.js


Можно с помощью postinstall заменить в файле одну строчку:

Нужно заменить this._queue.unshift(result.newJob) на this._queue.push(result.newJob)

Исходный файл: https://github.com/microsoft/playwright/blob/release-1.40/packages/playwright/src/runner/dispatcher.ts#L126 Скомпилированный файл (в вашем проекте): /node_modules/@playwright/test/lib/runner/dispatcher.js

Vovencia avatar Dec 21 '23 15:12 Vovencia

+1

zargham-leanix avatar Mar 05 '24 16:03 zargham-leanix

This would be pretty useful for our team as well

joeflan avatar May 28 '24 15:05 joeflan

+1. It's useful for the case when there is an env issue and all subsequent retries will fail but if they are postponed for a bit later, chances are the test will succeed. Would be good to dynamically manage this.

olekach avatar Jun 06 '24 11:06 olekach

+1 I would like this to be implemented :)

AndiBMGitHub avatar Jun 14 '24 09:06 AndiBMGitHub

+1 This would be really useful when resetting the test data only once in the global setup and the flaky test now does not have a clean state it had on the initial run

DerTimonius avatar Jun 18 '24 08:06 DerTimonius

+1 one for this

marcusNumminen avatar Jul 29 '24 10:07 marcusNumminen

+1 I'd like to see this too. This is also useful for when some specific tests may fail when sharded and the system is under heavy load, and then may have a better chance of succeeding when the number of shards tail off.

I know this all speaks to generally poor systems under test, but that's kind of the reality that we have to test with much of the time.

philipfong avatar Aug 14 '24 20:08 philipfong

+1 for this.

TuxThunderbird avatar Aug 26 '24 07:08 TuxThunderbird

+1 I'd like to see this too.

jonaslewin avatar Aug 26 '24 07:08 jonaslewin

+1 I'd like to see this too.

vbdata avatar Aug 26 '24 07:08 vbdata

+1 I'd like to see this too.

lynn57blocks avatar Sep 14 '24 05:09 lynn57blocks

+1 I'd like to see this too.

kosteklvp avatar Sep 19 '24 12:09 kosteklvp

+1 Would be really useful as a config param.

longmaxx avatar Oct 17 '24 12:10 longmaxx

Any plans for this? Would have been great to have this

marcusNumminen avatar Oct 31 '24 10:10 marcusNumminen

+1 would like this

tragsdale7 avatar Nov 25 '24 19:11 tragsdale7

+1

mastrzyz avatar Dec 04 '24 19:12 mastrzyz

+1

deniss-nikitin avatar Dec 13 '24 11:12 deniss-nikitin

We have discussed this feature request with a team. It looks like an option to run retries one by one at the end, without any parallelism, might be beneficial to reduce flakiness. Note that this will not improve the total run time, but rather slow it down in the hope of making the test suite more stable.

Please let us know whether you would use such a feature. If you would like to see something else, please explain your usecase in details. Thank you!

dgozman avatar Apr 29 '25 08:04 dgozman

i would be very interested in this pattern. We sometimes experience flaky test due to the backend overloading / some things locking up processes. The proposed pattern could adress those

matmair avatar Apr 29 '25 10:04 matmair

Couldn't there be option to either run the failing test in the end with or without parallelism?

marcusNumminen avatar Apr 29 '25 11:04 marcusNumminen

@marcusNumminen If you would like the feature to run retries in the end, but in parallel, please explain your usecase in details. We'd like to understand the problem before shipping a solution.

dgozman avatar Apr 29 '25 12:04 dgozman

@dgozman I assume your proposed solution involves tearing down the threads at the end and creating a new pristine single thread to run the tests one by one?

mstepin avatar Apr 30 '25 05:04 mstepin

@dgozman I assume your proposed solution involves tearing down the threads at the end and creating a new pristine single thread to run the tests one by one?

Yes, we'll create a new worker and start running retries there. If some of them fail again, a new worker will be created as usual.

dgozman avatar Apr 30 '25 06:04 dgozman

Hi! Sorry for the delay. In some cases we are running the test right after a deploy and when the tests start not all the deployed stuff is fully ready and some test fails due to this. But a solution with one worker running the retries in the end of the execution will of solve the problem for us but in this situation running the test in parallel would be faster :)

marcusNumminen avatar May 15 '25 06:05 marcusNumminen

+1

Shaun-Regan avatar Jun 04 '25 08:06 Shaun-Regan