Skip to content

Commit

Permalink
Fix Scheduler integration spec to ensure jobs are run in the Schedule…
Browse files Browse the repository at this point in the history
…r under test (#276)
  • Loading branch information
bensheldon authored Jun 23, 2021
1 parent e83d274 commit e750696
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions spec/integration/scheduler_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
require 'rails_helper'

RSpec.describe 'Schedule Integration' do
let(:adapter) { GoodJob::Adapter.new(execution_mode: :external) }

before do
ActiveJob::Base.queue_adapter = adapter

Expand Down Expand Up @@ -38,15 +40,15 @@ def perform(*args, **kwargs)
end), transfer_nested_constants: true
end

let(:adapter) { GoodJob::Adapter.new }

context 'when there are a large number of jobs' do
let(:number_of_jobs) { 500 }
let(:max_threads) { 5 }

let!(:good_jobs) do
number_of_jobs.times do |i|
ExampleJob.perform_later(i)
GoodJob::Job.transaction do
number_of_jobs.times do |i|
ExampleJob.perform_later(i)
end
end
end

Expand Down Expand Up @@ -77,8 +79,10 @@ def perform(*args, **kwargs)
let(:number_of_jobs) { 50 }

let!(:good_jobs) do
number_of_jobs.times do |i|
ExampleJob.perform_later(i)
GoodJob::Job.transaction do
number_of_jobs.times do |i|
ExampleJob.perform_later(i)
end
end
end

Expand Down Expand Up @@ -117,6 +121,7 @@ def perform(*args, **kwargs)
it 'warms up and schedules them in a cache' do
performer = GoodJob::JobPerformer.new('*')
scheduler = GoodJob::Scheduler.new(performer, max_threads: 5, max_cache: 5)
scheduler.warm_cache
sleep_until(max: 5, increments_of: 0.5) { GoodJob::Job.count == 0 }
scheduler.shutdown
end
Expand Down

0 comments on commit e750696

Please sign in to comment.