Skip to content

Commit

Permalink
Merge c9703c9 into 32d5547
Browse files Browse the repository at this point in the history
  • Loading branch information
danmayer committed May 29, 2019
2 parents 32d5547 + c9703c9 commit 36233d6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 18 deletions.
12 changes: 9 additions & 3 deletions lib/coverband.rb
Expand Up @@ -66,10 +66,16 @@ def self.configuration

def self.start
Coverband::Collectors::Coverage.instance
# TODO: Railtie sets up at_exit after forks, via middleware, perhaps this hsould be
# TODO: Railtie sets up at_exit after forks, via middleware, perhaps this should be
# added if not rails or if rails but not rackserverrunning
AtExit.register
Background.start if configuration.background_reporting_enabled && !RackServerCheck.running?
AtExit.register unless tasks_to_ignore?
Background.start if configuration.background_reporting_enabled && !RackServerCheck.running? && !tasks_to_ignore?
end

def self.tasks_to_ignore?
(defined?(Rake) &&
Rake.respond_to?(:application) &&
(Rake&.application&.top_level_tasks || []).any? { |task| Coverband::Configuration::IGNORE_TASKS.include?(task) })
end

def self.eager_loading_coverage!
Expand Down
13 changes: 1 addition & 12 deletions lib/coverband/at_exit.rb
Expand Up @@ -16,18 +16,7 @@ def self.register
at_exit do
::Coverband::Background.stop

#####
# TODO: This is is brittle and not a great solution to avoid deploy time
# actions polluting the 'runtime' metrics
#
# * should we skip /bin/rails webpacker:compile ?
# * Perhaps detect heroku deployment ENV var opposed to tasks?
#####
default_heroku_tasks = ['assets:clean', 'assets:precompile']
if !Coverband.configuration.report_on_exit ||
(defined?(Rake) &&
Rake.respond_to?(:application) &&
(Rake&.application&.top_level_tasks || []).any? { |task| default_heroku_tasks.include?(task) })
if !Coverband.configuration.report_on_exit
# skip reporting
else
Coverband.report_coverage
Expand Down
12 changes: 12 additions & 0 deletions lib/coverband/configuration.rb
Expand Up @@ -12,6 +12,18 @@ class Configuration
attr_writer :logger, :s3_region, :s3_bucket, :s3_access_key_id, :s3_secret_access_key
attr_reader :track_gems, :ignore, :use_oneshot_lines_coverage

#####
# TODO: This is is brittle and not a great solution to avoid deploy time
# actions polluting the 'runtime' metrics
#
# * should we skip /bin/rails webpacker:compile ?
# * Perhaps detect heroku deployment ENV var opposed to tasks?
#####
IGNORE_TASKS = ['coverband:clear',
'coverband:coverage',
'coverband:coverage_server',
'coverband:migrate']

# Heroku when building assets runs code from a dynamic directory
# /tmp was added to avoid coverage from /tmp/build directories during
# heroku asset compilation
Expand Down
1 change: 1 addition & 0 deletions test/coverband/integrations/resque_worker_test.rb
Expand Up @@ -17,6 +17,7 @@ def setup
config.background_reporting_enabled = false
config.root_paths = ["#{File.expand_path('../', File.dirname(__FILE__))}/"]
end
Coverband.configuration.store.instance_variable_set(:@redis_namespace, 'coverband_test')
Coverband.start
redis = Coverband.configuration.store.send(:redis)
Resque.redis = redis
Expand Down
12 changes: 12 additions & 0 deletions test/forked/rails_rake_full_stack_test.rb
Expand Up @@ -17,4 +17,16 @@ class RailsRakeFullStackTest < Minitest::Test
pundit_coverage = store.coverage[pundit_file]
assert_nil pundit_coverage
end

test "ignored rake tasks don't add coverage" do
store.instance_variable_set(:@redis_namespace, 'coverband_test')
store.send(:save_report, basic_coverage_full_path)
output = `COVERBAND_CONFIG=./test/rails#{Rails::VERSION::MAJOR}_dummy/config/coverband.rb bundle exec rake -f test/rails#{Rails::VERSION::MAJOR}_dummy/Rakefile coverband:clear`
assert_nil output.match(/Coverband: Reported coverage via thread/)
coverage_report = store.get_coverage_report
empty_hash = {}
assert_equal empty_hash, coverage_report[nil]
assert_equal empty_hash, coverage_report[:eager_loading]
assert_equal empty_hash, coverage_report[:merged]
end
end
4 changes: 2 additions & 2 deletions test/rails4_dummy/config/coverband.rb
Expand Up @@ -3,9 +3,9 @@
config.store = Coverband::Adapters::RedisStore.new(Redis.new(url: ENV['REDIS_URL']), redis_namespace: 'coverband_test') if defined? Redis
config.ignore = %w[vendor .erb$ .slim$]
config.root_paths = []
config.logger = Rails.logger
config.logger = Rails.logger
config.verbose = true
config.background_reporting_enabled = false
config.background_reporting_enabled = true
config.track_gems = true
config.gem_details = true
end
2 changes: 1 addition & 1 deletion test/rails5_dummy/config/coverband.rb
Expand Up @@ -5,7 +5,7 @@
config.root_paths = []
config.logger = Rails.logger
config.verbose = true
config.background_reporting_enabled = false
config.background_reporting_enabled = true
config.track_gems = true
config.gem_details = true
end

0 comments on commit 36233d6

Please sign in to comment.