Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Clean up tests and get them working again.

  • Loading branch information...
commit 00103390210880bd80f62ea76ad69a8bfeec2d9b 1 parent 64f9e3f
@gaffneyc gaffneyc authored
View
5 Gemfile
@@ -4,5 +4,8 @@ gemspec
group :development do
gem 'rake'
- gem 'SystemTimer', :platform => :ruby_18
+ gem 'SystemTimer', :platform => :ruby_18
+
+ gem 'ruby-debug', :platform => :ruby_18
+ gem 'ruby-debug19', :platform => :ruby_19, :require => 'ruby-debug'
end
View
8 test/helper.rb
@@ -1,8 +0,0 @@
-require 'rubygems'
-require 'test/unit'
-
-$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
-$LOAD_PATH.unshift(File.dirname(__FILE__))
-$TESTING = true
-
-require 'resque-jobs-per-fork'
View
11 test/test_helper.rb
@@ -0,0 +1,11 @@
+require 'rubygems'
+require 'bundler/setup'
+
+require 'test/unit'
+
+$:.unshift File.expand_path('../', __FILE__)
+$:.unshift File.expand_path('../../lib', __FILE__)
+
+require 'resque-jobs-per-fork'
+
+Bundler.require(:default, :development)
View
22 test/test_resque-jobs-per-fork.rb
@@ -1,32 +1,32 @@
-require 'helper'
+require 'test_helper'
class SomeJob
def self.perform(i)
$SEQUENCE << "work_#{i}".to_sym
- puts 'working...'
- sleep(0.1)
end
end
Resque.before_perform_jobs_per_fork do |worker|
- $SEQUENCE << "before_perform_jobs_per_fork".to_sym
+ $SEQUENCE << :before_perform_jobs_per_fork
end
Resque.after_perform_jobs_per_fork do |worker|
- $SEQUENCE << "after_perform_jobs_per_fork".to_sym
+ $SEQUENCE << :after_perform_jobs_per_fork
end
class TestResqueMultiJobFork < Test::Unit::TestCase
def setup
$SEQUENCE = []
- Resque.redis.flushdb
+
ENV['JOBS_PER_FORK'] = '2'
@worker = Resque::Worker.new(:jobs)
+ @worker.cant_fork = true
end
def test_one_job
Resque::Job.create(:jobs, SomeJob, 1)
@worker.work(0)
+
assert_equal([:before_perform_jobs_per_fork, :work_1, :after_perform_jobs_per_fork], $SEQUENCE)
end
@@ -42,8 +42,11 @@ def test_three_jobs
Resque::Job.create(:jobs, SomeJob, 2)
Resque::Job.create(:jobs, SomeJob, 3)
@worker.work(0)
- assert_equal([:before_perform_jobs_per_fork, :work_1, :work_2, :after_perform_jobs_per_fork,
- :before_perform_jobs_per_fork, :work_3, :after_perform_jobs_per_fork], $SEQUENCE)
+
+ assert_equal([
+ :before_perform_jobs_per_fork, :work_1, :work_2, :after_perform_jobs_per_fork,
+ :before_perform_jobs_per_fork, :work_3, :after_perform_jobs_per_fork
+ ], $SEQUENCE)
end
def test_work_normally_if_env_var_set
@@ -55,9 +58,10 @@ def test_work_normally_if_env_var_set
def test_crash_if_no_env_var_set
ENV.delete('JOBS_PER_FORK')
+
assert_raise(RuntimeError) do
Resque::Job.create(:jobs, SomeJob, 1)
@worker.work(0)
end
end
-end
+end
Please sign in to comment.
Something went wrong with that request. Please try again.