Skip to content

Commit

Permalink
Fix job_finished?
Browse files Browse the repository at this point in the history
  • Loading branch information
ShimShtein committed Sep 12, 2023
1 parent 1ab49ba commit 6f782ac
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ def job_finished?
job_invocation.finished?
end

def all_hosts_finished?(current_status)
current_status[:hosts_state].values.all? do |status|
ActiveModel::Type::Boolean.new.cast(status['report_done'] == true)
end
end

# noop, we don't want to do anything when the polling task starts
def invoke_external_task
poll_external_task
Expand Down Expand Up @@ -165,7 +171,7 @@ def report_job_progress(invocation_status)
end
end

if (job_invocation.finished? || all_hosts_success)
if (job_finished? || all_hosts_finished?(invocation_status))
generator.job_finished_message(all_hosts_success)
invocation_status[:task_state][:task_done_reported] = true
end
Expand Down
18 changes: 9 additions & 9 deletions test/jobs/connector_playbook_execution_reporter_task_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ def send_report(report)
host1_task.state = 'stopped'
host1_task.save!

JobInvocation.any_instance.stubs(:finished?).returns(true)
TestConnectorPlaybookExecutionReporterTask.any_instance.stubs(:job_finished?).returns(true)

actual = ForemanTasks.sync_task(TestConnectorPlaybookExecutionReporterTask, @job_invocation)

Expand Down Expand Up @@ -76,24 +76,24 @@ def send_report(report)
actual = ForemanTasks.sync_task(ArrangeTestHost, @job_invocation)

actual_report = actual.output[:saved_reports].first.to_s
assert_equal 1, actual.output[:saved_reports].size
assert_equal 2, actual.output[:saved_reports].size
assert_not_nil actual_report

actual_jsonl = read_jsonl(actual_report)

assert_equal 'stopped', @job_invocation.sub_task_for_host(Host.where(name: 'host1').first)['state']

assert_not_nil actual_report_finished = actual_jsonl.find { |l| l['type'] == 'playbook_run_update' }
assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
assert_equal 'TEST_UUID1', actual_report_finished['host']
assert_not_nil actual_report_updated = actual_jsonl.find { |l| l['type'] == 'playbook_run_update' && l['host'] == 'TEST_UUID1' }
assert_equal 'TEST_CORRELATION', actual_report_updated['correlation_id']
assert_equal 'TEST_UUID1', actual_report_updated['host']

assert_not_nil actual_host_finished = actual_jsonl.find { |l| l['type'] == 'playbook_run_finished' && l['host'] == 'TEST_UUID1' }
assert_equal 'TEST_CORRELATION', actual_host_finished['correlation_id']
assert_equal 'success', actual_host_finished['status']

assert_not_nil actual_report_finished = actual_jsonl.find { |l| l['type'] == 'playbook_run_completed' }
assert_equal 'TEST_CORRELATION', actual_report_finished['correlation_id']
assert_equal 'success', actual_report_finished['status']

assert_not_nil actual_host_finished = actual_jsonl.find { |l| l['type'] == 'playbook_run_finished' }
assert_equal 'TEST_CORRELATION', actual_host_finished['correlation_id']
assert_equal 'success', actual_host_finished['status']
end

private
Expand Down

0 comments on commit 6f782ac

Please sign in to comment.