Skip to content

Commit

Permalink
Optimize request and add specs for .waiting?
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiendupont committed Sep 11, 2019
1 parent ea17a7b commit 5d483da
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/models/job_proxy_dispatcher.rb
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ def assign_proxy_to_job(proxy, job)
end

def self.waiting?
Job.where(:state => 'waiting_to_start').exists? || InfraConversionJob.where.not(:state => ['finished', 'waiting_to_start']).exists?
Job.where(:state => "waiting_to_start").or(Job.where(:type => "InfraConversionJob").where.not(:state => ["finished", "waiting_to_start"]))
end

def pending_jobs(job_class = VmScan)
Expand Down
29 changes: 29 additions & 0 deletions spec/models/job_proxy_dispatcher_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,35 @@
@server = EvmSpecHelper.local_miq_server(:name => "test_server_main_server", :zone => zone)
end

describe '.waiting?' do
let(:vm_scan_job) { VmScan.create_job }
let(:infra_conversion_job) { InfraConversionJob.create_job }

it 'returns true if VmScan state is waiting to start and InfraConversionJob state is finished' do
vm_scan_job.update!(:state => 'waiting_to_start')
infra_conversion_job.update!(:state => 'finished')
expect(JobProxyDispatcher.waiting?).to be_truthy
end

it 'returns true if VmScan state is fake_state and InfraConversionJob state is waiting_to_start' do
vm_scan_job.update!(:state => 'fake_state')
infra_conversion_job.update!(:state => 'waiting_to_start')
expect(JobProxyDispatcher.waiting?).to be_truthy
end

it 'returns true if VmScan state is fake_state and InfraConversionJob state is restoring_vm_attributes' do
vm_scan_job.update!(:state => 'fake_state')
infra_conversion_job.update!(:state => 'restoring_vm_attributes')
expect(JobProxyDispatcher.waiting?).to be_truthy
end

it 'returns false if VmScan state is fake_state and no InfraConversionJob state is finished' do
vm_scan_job.update!(:state => 'fake_state')
infra_conversion_job.update!(:state => 'restoring_vm_attributes')
expect(JobProxyDispatcher.waiting?).to be_truthy
end
end

context "With a default zone, server, with hosts with a miq_proxy, vmware vms on storages" do
before do
(NUM_SERVERS - 1).times do |i|
Expand Down

0 comments on commit 5d483da

Please sign in to comment.