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 sectionEnded() not popping corresponding section from sectionStarted() in case where error was thrown in some section. #1651

Closed
wants to merge 5 commits into from

Conversation

DanielPBak
Copy link

@DanielPBak DanielPBak commented Jun 5, 2019

Description

In a failing test, the sectionend() corresponding to a sectionstart() could possibly pop different data than was pushed. This is because sectionEndedEarly() would push the failing section onto another stack (m_unfinishedSections), and then the next sectionEnded() would close the hanging sectionStarted(). Then the m_unfinishedSections would be popped, filling up the remaining hanging sections.

This caused two issues:

One: any reporter relying on SectionEnd() having accurate section data was broken. SectionEnd() would present different data than SectionStarted(). This caused an issue for the junit reporter, which relies on that data matching to manage the parralel m_sectionStack

However, this also applied to other reporters; having the xml reporter write the "name" attribute to the OverallResults written in sectionEnded revealed that it was not matching the section.

Two: I noticed where tests containing failing sections would pass through again, but not hit any nodes. Since a failing section would not be popped, it would remain on the stack, and this causes the test runner to believe that the test requires another pass because there are unresolved open sections (when all sections were actually closed).

This PR fixes both of these problems and does not seem to have any down side. Is there some edge case where it is important to pop the stack out of order? To me this looks like legacy code that is no longer useful.

The change I made was just to always call sectionEnded() and never sectionEndedEarly().

In my opinion, this needs a larger workaround to avoid introducing similar bugs. sectionEnded() shouldn't consume anything and should automatically pop the top.

Sorry about the verbose description.

GitHub Issues

Closes #1650
Closes #417
It also looks related to #1210

@DanielPBak DanielPBak changed the title In a failing test, the sectionend() corresponding to a sectionstart()… Fix sectionEnded() not popping corresponding section from sectionStarted() in case where error was thrown in some section. Jun 5, 2019
@DanielPBak
Copy link
Author

DanielPBak commented Jun 5, 2019

I wasn't aware of the existence of the approval tests and I see the issue. Will find a solution, and add an approval test which fails against the behavior in master.

@horenmar
Copy link
Member

horenmar commented Jun 6, 2019

While the tracking code probably could use a clean-up, it is fairly battle-tested, and as you've found out yourself, the behaviour required can be subtle.

OTOH, if you can improve things, it would be helpful.

@codecov
Copy link

codecov bot commented Jun 6, 2019

Codecov Report

Merging #1651 into master will decrease coverage by 0.33%.
The diff coverage is 100%.

@@            Coverage Diff             @@
##           master    #1651      +/-   ##
==========================================
- Coverage   81.05%   80.72%   -0.33%     
==========================================
  Files         124      124              
  Lines        3478     3476       -2     
==========================================
- Hits         2819     2806      -13     
- Misses        659      670      +11

@codecov
Copy link

codecov bot commented Jun 6, 2019

Codecov Report

Merging #1651 into master will decrease coverage by 2.97%.
The diff coverage is 100%.

@@            Coverage Diff            @@
##           master   #1651      +/-   ##
=========================================
- Coverage   83.67%   80.7%   -2.97%     
=========================================
  Files         123     124       +1     
  Lines        3380    3476      +96     
=========================================
- Hits         2828    2805      -23     
- Misses        552     671     +119

DanielPBak and others added 5 commits June 6, 2019 13:27
Editied approval tests to expect correct behavior.
… could possibly pop different data than

was pushed. This is because sectionEndedEarly() would push the failing section onto another stack
(m_unfinishedSections), and then the next sectionEnded() would close the hanging sectionStarted(). Then the
m_unfinishedSections would be popped, filling up the remaining hanging sections.

This caused two issues:

One: any reporter relying on SectionEnd() having accurate section data was broken.
SectionEnd() would present different data than SectionStarted(). This caused an issue for the junit reporter, which relies on that data matching to manage the parralel m_sectionStack.
However, this also applied to other reporters; having the xml reporter write the "name" attribute to the OverallResults written in sectionEnded revealed that it was not matching the section.

Two: I noticed where tests containing failing sections would pass through again, but not hit any nodes. Since a failing section would not be popped, it would remain on the stack, and this causes the test runner to
believe that the test requires another pass because there are unresolved open sections (when all sections were actually closed).
@DanielPBak
Copy link
Author

I don't believe that it only requires a clean-up - this is legitimately broken behavior. But it certainly requires a solution that doesn't break significantly more than it fixes :P

I've submitted #1654 which is a separate PR containing only the approval tests which reveal the problem.

@horenmar horenmar closed this Oct 20, 2020
@horenmar horenmar deleted the branch catchorg:master October 20, 2020 21:26
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.

Junit Reporter breaks when BDD Sections fail Junit reporter: sections are mixed up when expression fails
2 participants