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

fix(playwright): test unexpected result if failed and skipped #30276

Conversation

BeeMargarida
Copy link

@BeeMargarida BeeMargarida commented Apr 6, 2024

Fixes #28322

Changes:
A test result should be unexpected if it fails (and is not expected) and skips the rest of the runs.
This MR implements this logic, so that runs in serial mode in specific cases (see added unit test) don't cause false positives.

Checks if a test results are only failed and skipped. If so, it sets the result as unexpected instead of flaky, since they never passed.

Fixes microsoft#28322
@BeeMargarida
Copy link
Author

@microsoft-github-policy-service agree

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

}, { retries: 1 });
expect(result.exitCode).toBe(1);
expect(result.passed).toBe(0);
expect(result.flaky).toBe(1);
Copy link
Member

Choose a reason for hiding this comment

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

I believe in this scenario at least two tests test1 and test2 are flaky, aren't they?

Copy link
Member

Choose a reason for hiding this comment

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

My apologies, read the bug again, this is an intentional change. I'll discuss in the team meeting if this is change that we want.

Copy link
Member

Choose a reason for hiding this comment

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

Discussed this in the meeting, we'll consider all the implications and other possibilities and @dgozman will come back to you.

@@ -290,10 +290,14 @@ export class TestCase extends Base implements reporterTypes.TestCase {
return 'skipped';

const failures = results.filter(result => result.status !== 'skipped' && result.status !== 'interrupted' && result.status !== this.expectedStatus);
const skipped = results.filter(result => result.status === 'skipped' && result.status !== this.expectedStatus);
const passed = results.filter(result => result.status === 'passed');
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const passed = results.filter(result => result.status === 'passed');
const passed = results.filter(result => result.status === this.expectedStatus);

Copy link
Member

Choose a reason for hiding this comment

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

We probably need a test for this.

Copy link
Author

Choose a reason for hiding this comment

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

Not sure I understood, do you mean another test where the expected result is failure?

if (!failures.length) // all passed
return 'expected';
if (failures.length === results.length) // all failed
return 'unexpected';
if (failures.length && skipped.length && !passed.length) // some failed, none succeeded and the rest were skipped
Copy link
Member

Choose a reason for hiding this comment

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

I believe what we need here is instead of lines 297-300 something like:

if (failures.length && !passed.length)
  return 'unexpected';

as we don't care if there were any "skips".

Copy link
Author

Choose a reason for hiding this comment

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

Fixed 👍

@yury-s yury-s requested review from dgozman and yury-s April 17, 2024 16:44
Copy link
Contributor

Test results for "tests 1"

2 flaky ⚠️ [firefox-page] › page/page-click.spec.ts:848:3 › should not hang when frame is detached
⚠️ [playwright-test] › ui-mode-test-screencast.spec.ts:21:5 › should show screenshots

27371 passed, 671 skipped
✔️✔️✔️

Merge workflow run.

@dgozman
Copy link
Contributor

dgozman commented Apr 25, 2024

@BeeMargarida Thank you for the PR! I've researched our past changes in this area, and it turns out things are a bit more complicated:

Given the above, I have decided that it would not be worth it to iterate on this topic together, so I have created a PR myself: #30529, and will most likely close this one.

Thank you for sending the PR though! If you are still willing to contribute to Playwright, I'd recommend to pick an issue marked as "open-to-a-pull-request" and start there.

@BeeMargarida
Copy link
Author

BeeMargarida commented Apr 26, 2024

@BeeMargarida Thank you for the PR! I've researched our past changes in this area, and it turns out things are a bit more complicated:

* We have the same logic that calculates `outcome()` in two places.

* We should also align the "did not run" counter in reporters with this logic.

* There are more tests to be added/changed.

* There is a long history of changes here:
  
  * Related issues: [[BUG] Test mistakenly identified as flaky  #28322](https://github.com/microsoft/playwright/issues/28322), [[BUG] Ambiguous test outcome and status for serial mode #28321](https://github.com/microsoft/playwright/issues/28321), [[BUG] Serial + Retry : Failed test is marked as flaky even if it never passes #27455](https://github.com/microsoft/playwright/issues/27455), [[Question] Skip on retry #17652](https://github.com/microsoft/playwright/issues/17652).
  * Prior changes: [chore(test runner): remove fake skipped test results #27762](https://github.com/microsoft/playwright/pull/27762), [fix(test runner): failed + skipped = flaky #26385](https://github.com/microsoft/playwright/pull/26385), [Revert "chore(test runner): remove fake skipped test results (#27762)" #28360](https://github.com/microsoft/playwright/pull/28360), probably more.

Given the above, I have decided that it would not be worth it to iterate on this topic together, so I have created a PR myself: #30529, and will most likely close this one.

Thank you for sending the PR though! If you are still willing to contribute to Playwright, I'd recommend to pick an issue marked as "open-to-a-pull-request" and start there.

Hey, thank you for looking into this! 🙌 I completely understand, it seems like a big change in the result logic that could have side effects, so it's okay to improve on this in another PR. As long as the bug is solved, it's a happy ending for me 😄 I'll be on the lookout for the next release!

I'll take a look at the issues, always happy to contribute!

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.

[BUG] Test mistakenly identified as flaky
3 participants