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

Add resque support #177

Merged
merged 1 commit into from
Jan 27, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions coverband.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'rack'
spec.add_development_dependency 'rack-test'
spec.add_development_dependency 'rake'
spec.add_development_dependency 'resque'

# TODO: used for benchmarking and tests I think we have other better benchmarking
# perhaps time to drop this and refactor.
Expand Down
1 change: 1 addition & 0 deletions lib/coverband.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
require 'coverband/reporters/web'
require 'coverband/integrations/middleware'
require 'coverband/integrations/background'
require 'coverband/integrations/resque' if defined? Resque

module Coverband
CONFIG_FILE = './config/coverband.rb'
Expand Down
18 changes: 18 additions & 0 deletions lib/coverband/integrations/resque.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# frozen_string_literal: true

Resque.after_fork do |job|
Coverband.start
end

module Coverband
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice this is very clean, well done

module ResqueWorker
def perform
super
ensure
Coverband::Collectors::Coverage.instance.report_coverage(true)
end
end
end

Resque::Job.prepend(Coverband::ResqueWorker)

1 change: 1 addition & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require 'ostruct'
require 'json'
require 'redis'
require 'resque'
require 'pry-byebug'
$VERBOSE = original_verbosity

Expand Down
25 changes: 25 additions & 0 deletions test/unit/resque_worker_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# frozen_string_literal: true

require File.expand_path('../test_helper', File.dirname(__FILE__))

class ResqueWorkerTest < Minitest::Test
def enqueue_and_run_job
Resque.enqueue(TestResqueJob)
ENV['QUEUE'] ='resque_coverband'
Resque::Worker.new.work_one_job
end

test 'resque job coverage' do
resque_job_file = File.expand_path('./test_resque_job.rb', File.dirname(__FILE__))
require resque_job_file

#report after loading the file in parent process
Coverband::Collectors::Coverage.instance.report_coverage(true)

enqueue_and_run_job

expected = [1, 1, nil, 1, 1, nil, nil]
assert_equal expected, Coverband.configuration.store.coverage[resque_job_file]['data']
end
end

7 changes: 7 additions & 0 deletions test/unit/test_resque_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class TestResqueJob
@queue = :resque_coverband

def self.perform
puts "perform"
end
end