2022-02-04 13:17:50 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
require_migration!('remove_dangling_running_builds')
|
|
|
|
|
2022-07-25 17:08:32 -04:00
|
|
|
RSpec.describe RemoveDanglingRunningBuilds, :suppress_gitlab_schemas_validate_connection do
|
2022-02-04 13:17:50 -05:00
|
|
|
let(:namespace) { table(:namespaces).create!(name: 'user', path: 'user') }
|
|
|
|
let(:project) { table(:projects).create!(namespace_id: namespace.id) }
|
|
|
|
let(:runner) { table(:ci_runners).create!(runner_type: 1) }
|
|
|
|
let(:builds) { table(:ci_builds) }
|
|
|
|
let(:running_builds) { table(:ci_running_builds) }
|
|
|
|
|
|
|
|
let(:running_build) do
|
|
|
|
builds.create!(
|
|
|
|
name: 'test 1',
|
|
|
|
status: 'running',
|
|
|
|
project_id: project.id,
|
|
|
|
type: 'Ci::Build')
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:failed_build) do
|
|
|
|
builds.create!(
|
|
|
|
name: 'test 2',
|
|
|
|
status: 'failed',
|
|
|
|
project_id: project.id,
|
|
|
|
type: 'Ci::Build')
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:running_metadata) do
|
|
|
|
running_builds.create!(
|
|
|
|
build_id: running_build.id,
|
|
|
|
project_id: project.id,
|
|
|
|
runner_id: runner.id,
|
|
|
|
runner_type:
|
|
|
|
runner.runner_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
let!(:failed_metadata) do
|
|
|
|
running_builds.create!(
|
|
|
|
build_id: failed_build.id,
|
|
|
|
project_id: project.id,
|
|
|
|
runner_id: runner.id,
|
|
|
|
runner_type: runner.runner_type)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'removes failed builds' do
|
|
|
|
migrate!
|
|
|
|
|
|
|
|
expect(running_metadata.reload).to be_present
|
2022-07-28 17:09:42 -04:00
|
|
|
expect { failed_metadata.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
2022-02-04 13:17:50 -05:00
|
|
|
end
|
|
|
|
end
|