Skip to content

Commit

Permalink
Avoid premature failure with parallel_tests
Browse files Browse the repository at this point in the history
When running within
[parallel_tests](https://github.com/grosser/parallel_tests/wiki), wait
until all test processes complete before evaluating coverage statistics.
This avoids a premature failure exit code if an early run finishes with
coverage that does not meet the configured criteria.
  • Loading branch information
f1sherman committed Dec 9, 2018
1 parent 994dbff commit 9ba0171
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
0.16.2 (TBD)
===================

## Bugfixes

* Avoid a premature failure exit code when setting `minimum_coverage` in combination with using [parallel_tests](https://github.com/grosser/parallel_tests)

0.16.1 (2018-03-16)
===================

Expand Down
18 changes: 17 additions & 1 deletion lib/simplecov.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def result
# If we're using merging of results, store the current result
# first (if there is one), then merge the results and return those
if use_merging
wait_for_other_processes
SimpleCov::ResultMerger.store_result(@result) if result?
@result = SimpleCov::ResultMerger.merged_result
end
Expand Down Expand Up @@ -220,7 +221,7 @@ def process_result(result, exit_status)
if result_exit_status == SimpleCov::ExitCodes::SUCCESS # No result errors
write_last_run(covered_percent)
end
result_exit_status
final_result_process? ? result_exit_status : SimpleCov::ExitCodes::SUCCESS
end

# @api private
Expand Down Expand Up @@ -248,6 +249,21 @@ def result_exit_status(result, covered_percent)
end
# rubocop:enable Metrics/MethodLength

#
# @api private
#
def final_result_process?
!defined?(ParallelTests) || ParallelTests.last_process?
end

#
# @api private
#
def wait_for_other_processes
return unless defined?(ParallelTests) && final_result_process?
ParallelTests.wait_for_other_processes_to_finish
end

#
# @api private
#
Expand Down
2 changes: 1 addition & 1 deletion lib/simplecov/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module SimpleCov
VERSION = "0.16.1".freeze
VERSION = "0.16.2".freeze
end
23 changes: 23 additions & 0 deletions spec/simplecov_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
context "with merging disabled" do
before do
allow(SimpleCov).to receive(:use_merging).once.and_return(false)
expect(SimpleCov).to_not receive(:wait_for_other_processes)
end

context "when not running" do
Expand Down Expand Up @@ -64,6 +65,7 @@
allow(SimpleCov).to receive(:use_merging).once.and_return(true)
allow(SimpleCov::ResultMerger).to receive(:store_result).once
allow(SimpleCov::ResultMerger).to receive(:merged_result).once.and_return(the_merged_result)
expect(SimpleCov).to receive(:wait_for_other_processes)
end

context "when not running" do
Expand Down Expand Up @@ -170,5 +172,26 @@
end
end
end

describe '.process_result' do
before do
expect(SimpleCov).to receive(:result_exit_status).and_return SimpleCov::ExitCodes::MINIMUM_COVERAGE
expect(SimpleCov).to receive(:result?).and_return true
end
context 'when the final result process' do
let(:result) { double(SimpleCov::Result, :covered_percent => 0.0) }
before { expect(SimpleCov).to receive(:final_result_process?).and_return true }
it "returns the exit code from .result_exit_status" do
expect(SimpleCov.process_result(result, SimpleCov::ExitCodes::SUCCESS)).to eq SimpleCov::ExitCodes::MINIMUM_COVERAGE
end
end
context 'when not the final result process' do
let(:result) { double(SimpleCov::Result, :covered_percent => 0.0) }
before { expect(SimpleCov).to receive(:final_result_process?).and_return false }
it "returns the success exit code" do
expect(SimpleCov.process_result(result, SimpleCov::ExitCodes::SUCCESS)).to eq SimpleCov::ExitCodes::SUCCESS
end
end
end
end
end

0 comments on commit 9ba0171

Please sign in to comment.