BigW Consortium Gitlab

stuck_ci_builds_worker_spec.rb 1.24 KB
Newer Older
1 2 3 4
require "spec_helper"

describe StuckCiBuildsWorker do
  let!(:build) { create :ci_build }
5
  let(:worker) { described_class.new }
6 7 8 9 10 11 12 13 14 15 16 17 18

  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
19
        build.update!(updated_at: 2.days.ago)
20
        worker.perform
21 22 23 24 25
        is_expected.to eq('failed')
      end

      it "is still #{status}" do
        build.update!(updated_at: 1.minute.ago)
26
        worker.perform
27 28 29 30 31 32 33 34 35 36 37 38
        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
39
        build.update!(updated_at: 2.days.ago)
40
        worker.perform
41 42 43 44
        is_expected.to eq(status)
      end
    end
  end
45 46 47 48 49 50 51 52 53 54 55 56

  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
57
end