Commit 4d4e99a2 authored by Tomasz Maczukin's avatar Tomasz Maczukin

Renable StuckCiBuildsWorker to StucjCiJobsWorker

parent b66fe22a
class StuckCiBuildsWorker
class StuckCiJobsWorker
include Sidekiq::Worker
include CronjobQueue
......
......@@ -177,8 +177,8 @@ production: &base
# Periodically executed jobs, to self-heal Gitlab, do external synchronizations, etc.
# Please read here for more information: https://github.com/ondrejbartas/sidekiq-cron#adding-cron-job
cron_jobs:
# Flag stuck CI builds as failed
stuck_ci_builds_worker:
# Flag stuck CI jobs as failed
stuck_ci_jobs_worker:
cron: "0 * * * *"
# Remove expired build artifacts
expire_build_artifacts_worker:
......
......@@ -308,9 +308,9 @@ Settings.gravatar['host'] = Settings.host_without_www(Settings.gravatar[
# Cron Jobs
#
Settings['cron_jobs'] ||= Settingslogic.new({})
Settings.cron_jobs['stuck_ci_builds_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['stuck_ci_builds_worker']['cron'] ||= '0 * * * *'
Settings.cron_jobs['stuck_ci_builds_worker']['job_class'] = 'StuckCiBuildsWorker'
Settings.cron_jobs['stuck_ci_jobs_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['stuck_ci_jobs_worker']['cron'] ||= '0 * * * *'
Settings.cron_jobs['stuck_ci_jobs_worker']['job_class'] = 'StuckCiJobsWorker'
Settings.cron_jobs['expire_build_artifacts_worker'] ||= Settingslogic.new({})
Settings.cron_jobs['expire_build_artifacts_worker']['cron'] ||= '50 * * * *'
Settings.cron_jobs['expire_build_artifacts_worker']['job_class'] = 'ExpireBuildArtifactsWorker'
......
require 'spec_helper'
describe StuckCiBuildsWorker do
describe StuckCiJobsWorker do
let!(:runner) { create :ci_runner }
let!(:build) { create :ci_build, runner: runner }
let!(:job) { create :ci_build, runner: runner }
let(:worker) { described_class.new }
let(:exclusive_lease_uuid) { SecureRandom.uuid }
subject do
build.reload
build.status
job.reload
job.status
end
before do
build.update!(status: status, updated_at: updated_at)
job.update!(status: status, updated_at: updated_at)
allow_any_instance_of(Gitlab::ExclusiveLease).to receive(:try_obtain).and_return(exclusive_lease_uuid)
end
shared_examples 'build is dropped' do
shared_examples 'job is dropped' do
it 'changes status' do
worker.perform
is_expected.to eq('failed')
end
end
shared_examples 'build is unchanged' do
shared_examples 'job is unchanged' do
it "doesn't change status" do
worker.perform
is_expected.to eq(status)
end
end
context 'when build is pending' do
context 'when job is pending' do
let(:status) { 'pending' }
context 'when build is not stuck' do
context 'when job is not stuck' do
before { allow_any_instance_of(Ci::Build).to receive(:stuck?).and_return(false) }
context 'when build was not updated for more than 1 day ago' do
context 'when job was not updated for more than 1 day ago' do
let(:updated_at) { 2.days.ago }
it_behaves_like 'build is dropped'
it_behaves_like 'job is dropped'
end
context 'when build was updated in less than 1 day ago' do
context 'when job was updated in less than 1 day ago' do
let(:updated_at) { 6.hours.ago }
it_behaves_like 'build is unchanged'
it_behaves_like 'job is unchanged'
end
context 'when build was not updated for more than 1 hour ago' do
context 'when job was not updated for more than 1 hour ago' do
let(:updated_at) { 2.hours.ago }
it_behaves_like 'build is unchanged'
it_behaves_like 'job is unchanged'
end
end
context 'when build is stuck' do
context 'when job is stuck' do
before { allow_any_instance_of(Ci::Build).to receive(:stuck?).and_return(true) }
context 'when build was not updated for more than 1 hour ago' do
context 'when job was not updated for more than 1 hour ago' do
let(:updated_at) { 2.hours.ago }
it_behaves_like 'build is dropped'
it_behaves_like 'job is dropped'
end
context 'when build was updated in less than 1 hour ago' do
context 'when job was updated in less than 1 hour ago' do
let(:updated_at) { 30.minutes.ago }
it_behaves_like 'build is unchanged'
it_behaves_like 'job is unchanged'
end
end
end
context 'when build is running' do
context 'when job is running' do
let(:status) { 'running' }
context 'when build was not updated for more than 1 hour ago' do
context 'when job was not updated for more than 1 hour ago' do
let(:updated_at) { 2.hours.ago }
it_behaves_like 'build is dropped'
it_behaves_like 'job is dropped'
end
context 'when build was updated in less than 1 hour ago' do
context 'when job was updated in less than 1 hour ago' do
let(:updated_at) { 30.minutes.ago }
it_behaves_like 'build is unchanged'
it_behaves_like 'job is unchanged'
end
end
%w(success skipped failed canceled).each do |status|
context "when build is #{status}" do
context "when job is #{status}" do
let(:status) { status }
let(:updated_at) { 2.days.ago }
it_behaves_like 'build is unchanged'
it_behaves_like 'job is unchanged'
end
end
......@@ -93,9 +93,9 @@ describe StuckCiBuildsWorker do
let(:status) { 'running' }
let(:updated_at) { 2.days.ago }
before { build.project.update(pending_delete: true) }
before { job.project.update(pending_delete: true) }
it 'does not drop build' do
it 'does not drop job' do
expect_any_instance_of(Ci::Build).not_to receive(:drop)
worker.perform
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment