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

feat(test runner): shuffle order of tests with sharding seed #30817

Merged
merged 9 commits into from
May 22, 2024

Conversation

muhqu
Copy link
Contributor

@muhqu muhqu commented May 15, 2024

Adds a new feature to the test runner which allows to specify a seed value to randomize the test group order before sharding.

Problem

For example, if the first half of your tests are slower than the rest of your tests and you are using 4 shards to run your tests across multiple machines, it means that shard 1 and 2 will take significantly more time to complete than shard 3 and 4.

Solution

By randomizing the order of test groups before sharding in a deterministic way we can achieve a better distribution of slow and fast tests across all shards.

Example

Below are some runtime stats from a project I've been working on, which shows the potential benefit of this change.
Previously our distributed test job required around 30 minutes to complete due to individual shards requiring between 9-29 minutes. Now, with the seeded shuffling we're down to 20 minutes with individual shards requiring between 15-19 minutes.

image image

@muhqu
Copy link
Contributor Author

muhqu commented May 15, 2024

@microsoft-github-policy-service agree company="Adobe"

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@muhqu
Copy link
Contributor Author

muhqu commented May 15, 2024

retest

This comment has been minimized.

@john-griffin
Copy link

This looks great, thank you!

This comment has been minimized.

Copy link
Member

@pavelfeldman pavelfeldman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good overall!

docs/src/test-api/class-fullconfig.md Outdated Show resolved Hide resolved
docs/src/test-api/class-fullconfig.md Outdated Show resolved Hide resolved
docs/src/test-api/class-testconfig.md Outdated Show resolved Hide resolved
packages/playwright/src/common/config.ts Outdated Show resolved Hide resolved
@@ -32,6 +32,7 @@ export type ConfigCLIOverrides = {
reporter?: ReporterDescription[];
additionalReporters?: ReporterDescription[];
shard?: { current: number, total: number };
shardingSeed?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

revert: no need to pass it to the workers.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shardingSeed is required on ConfigCLIOverrides to support --sharding-seed cli option... It would be limiting to only support this via config file. Or am I missing something?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

…OR if not via cli option, it would be great to support it via environment variable e.g.export PW_SHARDING_SEED=...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you are right, we need it here since we are setting it in the command line.

packages/playwright/src/isomorphic/teleReceiver.ts Outdated Show resolved Hide resolved
packages/playwright/src/runner/loadUtils.ts Outdated Show resolved Hide resolved
* ```
*
*/
shardingSeed?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These will disappear.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like it did not. Is that a problem?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have user-defined config TestConfig and resolved FullConfig. Should be in TestConfig and not in FullConfig. So you seem to be fine.

This comment has been minimized.

Copy link
Contributor

Test results for "tests 1"

1 flaky ⚠️ [firefox-page] › page/page-request-continue.spec.ts:481:3 › continue should not change multipart/form-data body

27030 passed, 610 skipped
✔️✔️✔️

Merge workflow run.

@muhqu
Copy link
Contributor Author

muhqu commented May 22, 2024

I think there is some more room for improvement regarding the sharding logic.

Currently the way sharding works something like this…

         [  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12]
Shard 1:  ^---------^                                      : [  1, 2, 3 ]
Shard 2:              ^---------^                          : [  4, 5, 6 ]
Shard 3:                          ^---------^              : [  7, 8, 9 ]
Shard 4:                                      ^---------^  : [ 10,11,12 ]

I think it would be better to change the distribution logic to something like this…

         [  1,  2,  3,  4,  5,  6,  7,  8,  9, 10, 11, 12]
Shard 1:    ^               ^               ^              : [  1, 5, 9 ]
Shard 2:        ^               ^               ^          : [  2, 6,10 ]
Shard 3:            ^               ^               ^      : [  3, 7,11 ]
Shard 4:                ^               ^               ^  : [  4, 8,12 ]

And when we are able to sort the test groups by duration (e.g. given the results of a previous test run), we could achieve better distribution than this shuffle logic in this PR. However, that can be explored in a different PR

@muhqu muhqu requested a review from pavelfeldman May 22, 2024 09:12
@@ -32,6 +32,7 @@ export type ConfigCLIOverrides = {
reporter?: ReporterDescription[];
additionalReporters?: ReporterDescription[];
shard?: { current: number, total: number };
shardingSeed?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you are right, we need it here since we are setting it in the command line.

* ```
*
*/
shardingSeed?: string;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We have user-defined config TestConfig and resolved FullConfig. Should be in TestConfig and not in FullConfig. So you seem to be fine.

@pavelfeldman pavelfeldman merged commit 825e0e4 into microsoft:main May 22, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants