Skip to content

Instantly share code, notes, and snippets.

@k-yamada
Created October 22, 2012 10:48
Show Gist options
  • Save k-yamada/3930916 to your computer and use it in GitHub Desktop.
Save k-yamada/3930916 to your computer and use it in GitHub Desktop.
simplecov hangs after all spec passed when running on jruby. the temporary solution is to add at_exit hook like this.
#!/usr/bin/env ruby
system("jruby -S bundle exec rspec spec")
exit 0
require 'sc'
require 'pp'
require 'rspec/mocks'
require 'simplecov'
require 'simplecov-rcov'
SimpleCov.formatter = SimpleCov::Formatter::RcovFormatter
SimpleCov.start do
add_filter "/vendor/bundle/"
end
at_exit do
if $! #was an exception thrown?
@exit_status = $!.is_a?(SystemExit) ? $!.status : SimpleCov::ExitCodes::EXCEPTION
end
SimpleCov.at_exit.call
if SimpleCov.result? # Result has been computed
covered_percent = SimpleCov.result.covered_percent.round(2)
if @exit_status.to_i == 0 # No other errors
@exit_status = if covered_percent < SimpleCov.minimum_coverage
$stderr.puts "Coverage (%.2f%%) is below the expected minimum coverage (%.2f%%)." % \
[covered_percent, SimpleCov.minimum_coverage]
SimpleCov::ExitCodes::MINIMUM_COVERAGE
elsif (last_run = SimpleCov::LastRun.read)
diff = last_run['result']['covered_percent'] - covered_percent
if diff > SimpleCov.maximum_coverage_drop
$stderr.puts "Coverage has dropped by %.2f%% since the last time (maximum allowed: %.2f%%)." % \
[diff, SimpleCov.maximum_coverage_drop]
SimpleCov::ExitCodes::MAXIMUM_COVERAGE_DROP
end
end
end
metrics = {
:result => { :covered_percent => covered_percent }
}
SimpleCov::LastRun.write(metrics)
end
# HACK: temporary solution.
#exit @exit_status if @exit_status # Force exit with stored status (see github issue #5)
exit! !($!.nil? || $!.is_a?(SystemExit) && $!.success?)
end
RSpec.configure do |config|
# some (optional) config here
end
@phs
Copy link

phs commented Nov 20, 2013

For me, the culprit was not actually jruby, but the fact that I was running on a virtual box vm with a synched directory.

When simplecov exists, by default it will try to merge the recorded coverage with what's on disk. To avoid corruption it uses a lock file to guard this merge. Because my virtual box shared fs is not actually posix compliant, the lock file would never acquire, and silently block forever here.

Since I don't care about merging coverage results, the solution for me was to simply disable this behavior with the use_merging flag:

SimpleCov.start do
  use_merging false
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment