Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed bug: timeout was not triggered for Image Scanning Job after removing Job#agent_class #14791

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/models/job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,9 @@ def self.check_jobs_for_timeout

# Allow jobs to run longer if the MiqQueue task is still active. (Limited to MiqServer for now.)
# TODO: can we add method_name, queue_name, role, instance_id to the exists?
next if MiqQueue.exists?(:state => %w(dequeue ready), :task_id => job.guid)
if job.miq_server_id
next if MiqQueue.exists?(:state => %w(dequeue ready), :task_id => job.guid, :class_name => "MiqServer")
end
job.timeout!
end
rescue Exception
Expand Down
55 changes: 55 additions & 0 deletions spec/models/job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,51 @@
end
end
end

describe "#timeout!" do
it "adds to MiqQueue signal 'signal_abort' for this job " do
@job.timeout!
expect_signal_abort_and_timeout_message
end
end

describe ".check_jobs_for_timeout" do
before(:each) do
@job.update_attributes(:state => "active")
@queue_item = MiqQueue.put(:task_id => @job.guid)
end

context "job timed out" do
it "calls 'job#timeout!' if server was not assigned to job" do
Timecop.travel 5.minutes
Job.check_jobs_for_timeout
expect_signal_abort_and_timeout_message
end

it "calls 'job#timeout!' if server was assigned to job but queue item not in 'ready' or 'dequeue' state" do
@queue_item.update_attributes(:state => MiqQueue::STATE_WARN, :class_name => "MiqServer")
@job.update_attributes(:miq_server_id => @server1.id)
Timecop.travel 5.minutes
Job.check_jobs_for_timeout
expect_signal_abort_and_timeout_message
end

it "does not call 'job#timeout!' if queue state is 'ready' and server was assigned to job" do
@queue_item.update_attributes(:state => MiqQueue::STATE_READY, :class_name => "MiqServer")
@job.update_attributes(:miq_server_id => @server1.id)
Timecop.travel 5.minutes
Job.check_jobs_for_timeout
expect_no_signal_abort
end
end

context "job not timed out" do
it "does not call 'job#timeout!'" do
Job.check_jobs_for_timeout
expect_no_signal_abort
end
end
end
end

context "before_destroy callback" do
Expand Down Expand Up @@ -372,6 +417,16 @@

private

def expect_signal_abort_and_timeout_message
queue_item = MiqQueue.find_by(:instance_id => @job.id, :class_name => "Job", :method_name => "signal_abort")
expect(queue_item.args[0].starts_with?("job timed out after")).to be true
end

def expect_no_signal_abort
queue_item = MiqQueue.find_by(:instance_id => @job.id, :class_name => "Job", :method_name => "signal_abort")
expect(queue_item).to be nil
end

def assert_queue_message
expect(MiqQueue.count).to eq(1)
q = MiqQueue.first
Expand Down