summaryrefslogtreecommitdiff
path: root/spec/workers/stuck_ci_builds_worker_spec.rb
blob: 665ec20f2243a7f5cc68fa72bd244d341bad8ccd (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
require "spec_helper"

describe StuckCiBuildsWorker do
  let!(:build) { create :ci_build }

  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)
        StuckCiBuildsWorker.new.perform
        is_expected.to eq('failed')
      end

      it "is still #{status}" do
        build.update!(updated_at: 1.minute.ago)
        StuckCiBuildsWorker.new.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)
        StuckCiBuildsWorker.new.perform
        is_expected.to eq(status)
      end
    end
  end
end