Welcome to mirror list, hosted at ThFree Co, Russian Federation.

drop_scheduled_service_spec.rb « stuck_builds « ci « services « spec - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 5a95b55054fd8ff887b0c6d8aeeaa61be649673f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Ci::StuckBuilds::DropScheduledService, feature_category: :fleet_visibility do
  let_it_be(:runner) { create :ci_runner }

  let!(:job) { create :ci_build, :scheduled, scheduled_at: scheduled_at, runner: runner }

  subject(:service) { described_class.new }

  context 'when job is scheduled' do
    context 'for more than an hour ago' do
      let(:scheduled_at) { 2.hours.ago }

      it_behaves_like 'job is dropped with failure reason', 'stale_schedule'
    end

    context 'for less than 1 hour ago' do
      let(:scheduled_at) { 30.minutes.ago }

      it_behaves_like 'job is unchanged'
    end
  end

  %w[success skipped failed canceled running pending].each do |status|
    context "when job is #{status}" do
      before do
        job.update!(status: status)
      end

      context 'and scheduled for more than an hour ago' do
        let(:scheduled_at) { 2.hours.ago }

        it_behaves_like 'job is unchanged'
      end

      context 'and scheduled for less than 1 hour ago' do
        let(:scheduled_at) { 30.minutes.ago }

        it_behaves_like 'job is unchanged'
      end
    end
  end

  context 'when there are no stale scheduled builds' do
    let(:job) {}

    it 'does not drop the stale scheduled build yet' do
      expect { service.execute }.not_to raise_error
    end
  end
end