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: retried scenarios which are run after another scenario with a passed result are still counted as failed #250

Closed
wants to merge 8 commits into from

Conversation

thukim
Copy link

@thukim thukim commented Jun 6, 2023

Description

Issue: Retried scenarios which are run after another scenario with a passed result are still counted as failed
Tests written to ensure the fix works: https://github.com/cucumber/cucumber-ruby-core/pull/250/files#diff-9bded15ebb1a2a9b74f58b63b24f0ff35f75c5cc44037e14b976ef1f3fde87d5R85-R112

Proposed changes:

  • change @previous_test_case to @previous_test_cases which is a Ruby Set object, so that it holds a collection of all the unique test scenarios which have been run, regardless whether they pass or fail.
  • instead of checking if the current test case is equal to the @previous_test_case value, the current event.test_case will be checked if it's included in the set @previous_test_cases. This ensures regardless whether the retried test case is run immediately after that test case or after another test case, it is still counted as retried one instead of a new test case as with the current logic.

These changes are backward compatible and don't impact future contributions, so I only bump the patch version, from 11.1.0 to 11.1.1
Please let me know if there is anything else I need to add or fix in this PR.

Thanks!

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

Your PR is ready for review once the following checklist is
complete. You can also add some checks if you want to.

  • Tests have been added for any changes to behaviour of the code
  • New and existing tests are passing locally and on CI
  • bundle exec rubocop reports no offenses
  • RDoc comments have been updated
  • CHANGELOG.md has been updated

@thukim thukim marked this pull request as ready for review June 6, 2023 06:58
@luke-hill
Copy link
Contributor

The original post sounds like quite a big bug, which has not been encountered by myself in years of running this. Can you maybe share a reproducible script that generates the failures you mention.

The specs/tests are a little hard to follow, but I think I need a better understanding of where this error comes from first.

@thukim
Copy link
Author

thukim commented Jun 15, 2023

Hi @luke-hill ,

The original post sounds like quite a big bug, which has not been encountered by myself in years of running this.

Most of the time, if we use the built-in --retry option, it won't happen to have any issue since the failed scenario will be retried immediately, thus the condition event.test_case != @previous_test_case will be true.

However, sometimes, we might want to have a custom way to retry those failed scenarios, for example: retry the failed scenarios after all the scenarios have been run. With this case, the condition event.test_case != @previous_test_case might not be true anymore since it only stores the last scenario to the var @previous_test_case, not all the scenarios which have been run previously.

This PR improves the cucumber retry so that it works for both cases: retry immediately right after 1 failed scenario, or retry later after other scenarios too.

Can you maybe share a reproducible script that generates the failures you mention.

Sure, I have created this Github repo to test - just need to run bundle and then bundle exec cucumber to reproduce it.

I also attached the screenshots below for the differences when running the cucumber tests before and after this PR:

Before (with cucumber-core v11.1.0)
Screenshot 2023-06-15 at 17 14 53

After (with this PR)
Screenshot 2023-06-15 at 17 14 19

Let me know if you have any other questions!

@luke-hill
Copy link
Contributor

I'll need a good few weeks owing to other responsibilities to check on this. So apologies in advance.

Everything you've given looks enough for me for now to repro

@luke-hill
Copy link
Contributor

Hi @thukim

As/when I get around to releasing a v12 version of this gem (Nothing huge changing don't worry). This PR will need a rebase and slight fix / re-gen of the rubocop TODO file.

I'll then plan during the v12 phase to start clicking off some of the offenses (Which number 2k+)

@thukim
Copy link
Author

thukim commented Sep 17, 2023

Hi @luke-hill ,

Sorry for the late reply! I have been able to switch back to this PR and resolved the conflicts.

Please let me know if there is any thing else I need to update/add in the PR.

Thank you!

CHANGELOG.md Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

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

Hi there. I've not forgot about this, just I've got 7 or 8 other things I'm trying to fix up atm. I will get to reviewing this in the next week or so.

Copy link
Contributor

@luke-hill luke-hill left a comment

Choose a reason for hiding this comment

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

Few language tweaks and a request to re-structure the tests to help the next person coming to read them

@@ -17,6 +17,7 @@ Please visit [cucumber/CONTRIBUTING.md](https://github.com/cucumber/cucumber/blo
See upgrading notes for [13.0.0.md](upgrading_notes/13.0.0.md#upgrading-to-1300)
([#261](https://github.com/cucumber/cucumber-ruby-core/pull/261))
- Permit usage of gherkin v27
- Fixed retried scenarios which are run after another scenario with a passed result are still counted as failed ([#250](https://github.com/cucumber/cucumber-ruby-core/pull/250)
Copy link
Contributor

Choose a reason for hiding this comment

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

Can you place this under a ### Fixed heading

event_bus.send(:test_case_finished, test_case, passed_result)
end

it 'reports 0 passed test' do
Copy link
Contributor

Choose a reason for hiding this comment

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

tests when using 0 as an input number or 2+
test when using 1 as an input number

allow(test_case).to receive(:==).and_return(false, true)
event_bus.send(:test_case_finished, test_case, failed_result)
event_bus.send(:test_case_finished, test_case, passed_result)
context 'handles flaky test cases' do
Copy link
Contributor

Choose a reason for hiding this comment

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

If possible it would be better to write each of these as just 1 level of nesting under context with a better description. It's a bit hard for me to work out what's different here. Admittedly I don't know the code that well.

@thukim thukim closed this by deleting the head repository Nov 10, 2023
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.

3 participants