summaryrefslogtreecommitdiff
path: root/spec/workers/stuck_ci_builds_worker_spec.rb
blob: 801fa31b45d8db39becde154f01cf1d2b86fd4e9 (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
54
55
56
57
require "spec_helper"

describe StuckCiBuildsWorker do
  let!(:build) { create :ci_build }
  let(:worker) { described_class.new }

  subject do
    build.reload
    build.status
  end

  %w(pending running).each do |status|
    context "#{status} build" do
      before do
        build.update!(status: status)
      end

      it 'gets dropped if it was updated over 2 days ago' do
        build.update!(updated_at: 2.days.ago)
        worker.perform
        is_expected.to eq('failed')
      end

      it "is still #{status}" do
        build.update!(updated_at: 1.minute.ago)
        worker.perform
        is_expected.to eq(status)
      end
    end
  end

  %w(success failed canceled).each do |status|
    context "#{status} build" do
      before do
        build.update!(status: status)
      end

      it "is still #{status}" do
        build.update!(updated_at: 2.days.ago)
        worker.perform
        is_expected.to eq(status)
      end
    end
  end

  context "for deleted project" do
    before do
      build.update!(status: :running, updated_at: 2.days.ago)
      build.project.update(pending_delete: true)
    end

    it "does not drop build" do
      expect_any_instance_of(Ci::Build).not_to receive(:drop)
      worker.perform
    end
  end
end