Skip to content

Commit

Permalink
Execution Hanging Detection
Browse files Browse the repository at this point in the history
Increasing code coverage.
Minor fixes

Signed-off-by: Rodrigo Nardi <[email protected]>
  • Loading branch information
RodrigoMNardi committed Oct 4, 2024
1 parent 7ed4e9a commit 5235435
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/models/check_suite.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,6 @@ def execution_started?
end

def last_job_updated_at_timer
ci_jobs.max_by(&:updated_at)&.updated_at
ci_jobs.max_by(&:updated_at).to_s.updated_at
end
end
34 changes: 34 additions & 0 deletions spec/lib/models/check_suite_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# SPDX-License-Identifier: BSD-2-Clause
#
# ci_job_spec.rb
# Part of NetDEF CI System
#
# Copyright (c) 2023 by
# Network Device Education Foundation, Inc. ("NetDEF")
#
# frozen_string_literal: true

describe CheckSuite do
context '#execution_started?' do
let(:check_suite) { create(:check_suite) }
let(:check_suite_running) { create(:check_suite, :with_in_progress) }

it 'returns true when there are less than 2 jobs in progress' do
expect(check_suite.execution_started?).to be_truthy
end

it 'returns false' do
expect(check_suite_running.execution_started?).to be_falsey
end
end

context '#last_job_updated_at_timer?' do
let(:ci_job) { create(:ci_job, updated_at: nil) }
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
end
end
end
2 changes: 1 addition & 1 deletion workers/timeout_execution.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def rescheduling(resp, check_suite_id)

@logger.info("Rescheduling check_suite_id: #{check_suite_id}")

Delayed::Job.where('handler LIKE ?', "%TimeoutExecution%args%-%#{check_suite_id}%")&.delete_all
Delayed::Job.where('handler LIKE ?', "%TimeoutExecution%args%-%#{check_suite_id}%").delete_all

TimeoutExecution
.delay(run_at: 2.hours.from_now.utc, queue: 'timeout_execution')
Expand Down

0 comments on commit 5235435

Please sign in to comment.