From caeaf16a2bde41bac0591f62c70aa0bdfae161d9 Mon Sep 17 00:00:00 2001 From: Rodrigo Nardi Date: Fri, 4 Oct 2024 17:57:41 -0300 Subject: [PATCH] Execution Hanging Detection Increasing code coverage. Signed-off-by: Rodrigo Nardi --- lib/models/check_suite.rb | 2 +- spec/lib/models/check_suite_spec.rb | 16 ++++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/models/check_suite.rb b/lib/models/check_suite.rb index 3a24799..667bc56 100644 --- a/lib/models/check_suite.rb +++ b/lib/models/check_suite.rb @@ -50,6 +50,6 @@ def execution_started? end def last_job_updated_at_timer - ci_jobs.max_by(&:updated_at).to_s.updated_at + ci_jobs.max_by(&:updated_at)&.updated_at end end diff --git a/spec/lib/models/check_suite_spec.rb b/spec/lib/models/check_suite_spec.rb index 833f46c..c45733e 100644 --- a/spec/lib/models/check_suite_spec.rb +++ b/spec/lib/models/check_suite_spec.rb @@ -22,13 +22,21 @@ end end - context '#last_job_updated_at_timer?' do - let(:ci_job) { create(:ci_job, updated_at: nil) } + context '#last_job_updated_at_timer? -> success' do + let(:ci_job) { create(:ci_job) } let(:check_suite) { create(:check_suite, ci_jobs: [ci_job]) } - let(:check_suite_running) { create(:check_suite, :with_in_progress) } it 'returns false' do - expect(check_suite_running.last_job_updated_at_timer).not_to be_nil + expect(check_suite.last_job_updated_at_timer).not_to be_nil + end + end + + context '#last_job_updated_at_timer? -> error' do + let(:ci_job) { create(:ci_job, updated_at: nil) } + let(:check_suite) { create(:check_suite, ci_jobs: []) } + + it 'returns false' do + expect(check_suite.last_job_updated_at_timer).to be_nil end end end