diff --git a/spec/models/miq_provision/state_machine_spec.rb b/spec/models/miq_provision/state_machine_spec.rb index 51ce44177d0b..8e42832705e3 100644 --- a/spec/models/miq_provision/state_machine_spec.rb +++ b/spec/models/miq_provision/state_machine_spec.rb @@ -151,5 +151,29 @@ template.reload.with_relationship_type("genealogy") { |v| expect(v.children).to eq([vm]) } end end + + context "#log_last_worker" do + let(:server) { FactoryGirl.create(:miq_server, :name => "test_server", :zone => FactoryGirl.create(:zone)) } + let(:worker) { FactoryGirl.create(:miq_worker, :miq_server => server) } + + it "logs worker/server info with last_worker_id in phase_context" do + task.update_attributes(:phase_context => {:last_worker_id => worker.id}) + expect($log).to receive(:info).with(/Task was previously processed by Worker id:.*Server id/) + task.log_last_worker + end + + it "logs worker id with worker does not exist" do + task.update_attributes(:phase_context => {:last_worker_id => worker.id}) + expect($log).to receive(:info).with(/Task was previously processed by Worker id:.*which does not exist any more/) + worker.delete + task.log_last_worker + end + + it "doesn't write a message if no last_worker_id in phase_context" do + expect(MiqWorker).not_to receive(:find_by) + expect($log).not_to receive(:info).with(/Task was previously processed by Worker id:/) + task.log_last_worker + end + end end end