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

Don't call SimpleCov.result before checking SimpleCov.result? #674

Merged

Conversation

tomeon
Copy link
Contributor

@tomeon tomeon commented Apr 11, 2018

Encountered in infertux/bashcov#36.

In the following snippet, SimpleCov.process_result is called with SimpleCov.result as the first parameter. Because of this, the SimpleCov.result? check at the very beginning of SimpleCov.process_result will always return true, as @result was initialized by the preceding SimpleCov.result call:

https://github.com/colszowka/simplecov/blob/03a9f7fde44a9388580977e4002b4f6823c2b4cc/lib/simplecov.rb#L197-L224

Due to the misordering of the .result and .result? calls, any code that (like bashcov) stores results manually with ResultMerger.store_result will have its coverage data clobbered when SimpleCov.result calls SimpleCov::ResultMerger.store_result (as long as SimpleCov.command_name hasn't changed between the two .store_result calls). See this Travis build, which contains the test case from this PR but not the code fix, for an illustration of the problem.

This PR makes the call to SimpleCov.process_result conditional on SimpleCov.result? returning true, ensuring that existing data is overwritten only if SimpleCov.result has already been instantiated elsewhere.

Thanks in advance for your consideration!

…ess_result

in order to avoid instantiating SimpleCov.result prior to performing the .result? check, as doing so guarantees that .result? will always return 'true'
…data isn't clobbered by SimpleCov.run_exit_tasks\!/.process_results
@tomeon
Copy link
Contributor Author

tomeon commented Apr 13, 2018

Re the failing test -- looks like the same error has happened in at least one prior Travis build. I have not been able reproduce the issue in the local travici/ci-garnet Docker container I use for development, and the Travis build from my fork succeeded.

Copy link
Collaborator

@PragTob PragTob 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,

sorry for the long time to get back to you - life and all :) That seems like a good fix to me I'll restart the build with the fail and meditate a bit about it

@tomeon
Copy link
Contributor Author

tomeon commented Apr 24, 2018

Awesome -- thanks, @PragTob!

FWIW, I ran while bundle exec cucumber --order random; : ; done until it bombed out with the same error seen in Travis. When I re-ran cucumber --order random:<seed> with the seed from the failing run, the suite passed 🤷‍♂️

@infertux
Copy link
Contributor

Ping @PragTob :)

@bf4
Copy link
Collaborator

bf4 commented Jan 18, 2019

So the error is intermittent but not order dependent. Fun

@PragTob
Copy link
Collaborator

PragTob commented Jun 25, 2019

Hey sorry, I took a bit of a break from simplecov. Looks good rereading it all. Thanks a ton for your contribution 💚

@PragTob PragTob merged commit 27d7ee7 into simplecov-ruby:master Jun 25, 2019
netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this pull request Nov 2, 2019
Update ruby-simplecov to 0.17.1.


0.17.1 (2019-09-16)
===================

Bugfix release for problems with ParallelTests.

## Bugfixes

* Avoid hanging with parallel_tests. See [#746](simplecov-ruby/simplecov#746) (thanks [@annaswims](https://github.com/annaswims))

0.17.0 (2019-07-02)
===================

Maintenance release with nice convenience features and important bugfixes.
Notably this **will be the last release to support ruby versions that have reached their end of life**. Moving forward official CRuby support will be 2.4+ and JRuby support will be 9.1+. Older versions might still work but no guarantees.

## Enhancements

* Per default filter hidden files and folders. See [#721](simplecov-ruby/simplecov#721) (thanks [Renuo AG](https://www.renuo.ch))
* Print the exit status explicitly when it's not a successful build so it's easier figure out SimpleCov failed the build in the output. See [#688](simplecov-ruby/simplecov#688) (thanks [@daemonsy](https://github.com/daemonsy))

## Bugfixes

* Avoid a premature failure exit code when setting `minimum_coverage` in combination with using [parallel_tests](https://github.com/grosser/parallel_tests). See [#706](simplecov-ruby/simplecov#706) (thanks [@f1sherman](https://github.com/f1sherman))
* Project roots with special characters no longer cause crashes. See [#717](simplecov-ruby/simplecov#717) (thanks [@deivid-rodriguez](https://github.com/deivid-rodriguez))
* Avoid continously overriding test results with manual `ResultMergere.store_results` usage. See [#674](simplecov-ruby/simplecov#674) (thanks [@tomeon](https://github.com/tomeon))
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

4 participants