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: implement flag to fail flaky tests #30618

Merged
merged 1 commit into from May 15, 2024
Merged

Conversation

Joe-Hendley
Copy link
Contributor

@Joe-Hendley Joe-Hendley commented May 1, 2024

Implements feature requested in #30457

The test runner treats flaky tests as failures when the flag is enabled, but still reports flaky tests as flaky in the reporting interface. It feels like something worth discussing as this behaviour makes sense to me, but looked a bit odd to @BJSS-russell-pollock when I ran this past him.

Closes #30457.

@Joe-Hendley
Copy link
Contributor Author

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

This comment has been minimized.

@BJSS-russell-pollock
Copy link

BJSS-russell-pollock commented May 1, 2024

Talking point of the failing on flaky behaviour, is about the reporter not indicating that the suite failed because of the flaky test. The exit code is 1 but the reporter doesn't look like it.

To try this out, I set the the playwright.config to:

retries: process.env.CI ? 2 : 5,
failOnFlakyTests: true,

And then the test:

test('flaky test', async () => {

  const randomFail = Math.round(Math.random());
  expect(randomFail).toBe(0)
});

When running the test through the CLI - the retry would pass and then mark the test as flaky:
retry
result flaky

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

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

Thank you for the PR!

I'd like to understand the feature a little better. Do we want to stop recognizing flaky tests at all? Are we after the test runner exit code? Or some changes in the terminal/html report?

Looking at the issue, my initial understanding is "introduce --fail-on-flaky cli option that will set exitCode=1 when at least one test was flaky". However, this PR introduces many more changes, so let's align on the intended behavior first.

@Joe-Hendley
Copy link
Contributor Author

Hi there,

The intended behaviour from this PR, and my understanding of the issue matches yours - any changes in the code extra to that reflect my unfamiliarity with the codebase.

I think Russell's comment / the discussion around behaviour reflects the user / manual tester perspective where the change in exit code isn't immediately visible.

@dgozman
Copy link
Contributor

dgozman commented May 2, 2024

The intended behaviour from this PR, and my understanding of the issue matches yours - any changes in the code extra to that reflect my unfamiliarity with the codebase.

Sounds great! In this case, I think we should plumb the new CLI option similar to --pass-with-no-tests. Search for passWithNoTests across the codebase for the reference. And this is a place that determines whether everything was successful or something has failed, and it needs to be tweaked.

@BJSS-russell-pollock I think this should be clear since reporter shows the "Flaky" count as non-zero. I'd assume anyone using this option will know that flakiness means "failed test run", because the behavior was opt in. Let me know what you think.

@BJSS-russell-pollock
Copy link

@BJSS-russell-pollock I think this should be clear since reporter shows the "Flaky" count as non-zero. I'd assume anyone using this option will know that flakiness means "failed test run", because the behavior was opt in. Let me know what you think.

Absolutely makes sense.

@Joe-Hendley
Copy link
Contributor Author

Sounds great! In this case, I think we should plumb the new CLI option similar to --pass-with-no-tests. Search for passWithNoTests across the codebase for the reference. And this is a place that determines whether everything was successful or something has failed, and it needs to be tweaked.

Excellent - I'll have a look and update it accordingly.

This comment has been minimized.

@Joe-Hendley Joe-Hendley force-pushed the fail-flaky-flag branch 2 times, most recently from be62f16 to 013b61f Compare May 9, 2024 11:10

This comment has been minimized.

This comment has been minimized.

@Joe-Hendley Joe-Hendley force-pushed the fail-flaky-flag branch 2 times, most recently from 2af62ce to faf8d5d Compare May 9, 2024 13:36

This comment has been minimized.

@Joe-Hendley
Copy link
Contributor Author

Okay, reworked as suggested - much less additional code!

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@Joe-Hendley
Copy link
Contributor Author

@dgozman This should be ok for re-review when you're ready - the failed tests in previous pipeline runs look like noise to me, but happy to dig if you think it's deeper

Copy link
Contributor

Test results for "tests 1"

1 failed
❌ [playwright-test] › playwright.ct-react.spec.ts:253:5 › should pass "key" attribute from JSX in variable

2 flaky ⚠️ [playwright-test] › ui-mode-test-screencast.spec.ts:21:5 › should show screenshots
⚠️ [playwright-test] › ui-mode-test-watch.spec.ts:96:5 › should batch watch updates

27346 passed, 662 skipped
✔️✔️✔️

Merge workflow run.

Copy link
Contributor

@dgozman dgozman left a comment

Choose a reason for hiding this comment

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

Looks great, merging in. Thank you for the PR!

@dgozman dgozman merged commit 6ae5cd3 into microsoft:main May 15, 2024
29 of 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.

[Feature]: Add Configuration Option to Mark Test Suite as Failed When Containing Flaky Tests
3 participants