spec/models/massive/job_spec.rb in massive-0.3.0 vs spec/models/massive/job_spec.rb in massive-0.4.0
- old
+ new
@@ -6,10 +6,12 @@
let(:process) { Massive::Process.new }
let(:step) { process.steps.build }
subject(:job) { step.jobs.build }
+ before { job.stub(:process).and_return(process) }
+
describe ".perform" do
before do
Massive::Process.stub(:find_job).with(process.id, step.id, job.id).and_return(job)
end
@@ -18,13 +20,61 @@
Massive::Job.perform(process.id, step.id, job.id)
end
end
describe ".queue" do
+ after { Massive::Job.queue_prefix(:massive_job) }
+
it "should be massive_job" do
Massive::Job.queue.should eq(:massive_job)
end
+
+ it "should use queue_prefix" do
+ Massive::Job.queue_prefix(:my_job_queue)
+ Massive::Job.queue.should eq(:my_job_queue)
+ end
+
+ context "when Massive.split_jobs is set to 100" do
+ before { Massive.split_jobs = 100 }
+ after { Massive.split_jobs = false }
+
+ it "should be massive_job_XXX where XXX is a random number" do
+ values = 10000.times.inject({}) do |memo, index|
+ match = Massive::Job.queue.to_s.match(/massive_job_(\d+)/)
+ memo[match[1].to_i] ||= 0
+ memo[match[1].to_i] += 1
+ memo
+ end
+
+ (1..100).each do |key|
+ expect(values.keys.sort).to include(key)
+ end
+ end
+
+ it "should use the queue prefix" do
+ Massive::Job.queue_prefix(:my_job_queue)
+ expect(Massive::Job.queue.to_s).to start_with('my_job_queue')
+ end
+
+ context "when Job split_jobs is set to 10" do
+ before { Massive::Job.split_jobs 200 }
+ after { Massive::Job.split_jobs false }
+
+ it "should be massive_job_XXX where XXX is a random number between 1 and 10" do
+ values = 10000.times.inject({}) do |memo, index|
+ match = Massive::Job.queue.to_s.match(/massive_job_(\d+)/)
+ memo[match[1].to_i] ||= 0
+ memo[match[1].to_i] += 1
+ memo
+ end
+
+ (1..200).each do |key|
+ expect(values.keys.sort).to include(key)
+ end
+ end
+ end
+ end
end
describe "#enqueue" do
it "enqueues itself, passing ids as strings" do
Resque.should_receive(:enqueue).with(job.class, process.id.to_s, step.id.to_s, job.id.to_s)
@@ -215,9 +265,23 @@
step.should_receive(:notify).with(:failed)
begin
job.work
rescue StandardError, SignalException
+ end
+ end
+
+ context "when it is configured to cancel when failed" do
+ before { Massive::Job.cancel_when_failed true }
+ after { Massive::Job.cancel_when_failed false }
+
+ it "cancels the process" do
+ expect(process).to receive(:cancel)
+
+ begin
+ job.work
+ rescue StandardError, SignalException
+ end
end
end
end
context "when an error occurs" do