From e08860665aef1e1194c8963a2d036d98fc4c777e Mon Sep 17 00:00:00 2001 From: Lucy Fu Date: Mon, 21 May 2018 09:27:22 -0400 Subject: [PATCH] Add test cases. https://bugzilla.redhat.com/show_bug.cgi?id=1535237 --- .../miq_provision/state_machine_spec.rb | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) 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