diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/migrations/clean_up_pending_builds_table_spec.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/migrations/clean_up_pending_builds_table_spec.rb')
-rw-r--r-- | spec/migrations/clean_up_pending_builds_table_spec.rb | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/spec/migrations/clean_up_pending_builds_table_spec.rb b/spec/migrations/clean_up_pending_builds_table_spec.rb new file mode 100644 index 00000000000..9c8d4413337 --- /dev/null +++ b/spec/migrations/clean_up_pending_builds_table_spec.rb @@ -0,0 +1,47 @@ +# frozen_string_literal: true + +require 'spec_helper' +require_migration! + +RSpec.describe CleanUpPendingBuildsTable do + let(:namespaces) { table(:namespaces) } + let(:projects) { table(:projects) } + let(:queue) { table(:ci_pending_builds) } + let(:builds) { table(:ci_builds) } + + before do + namespaces.create!(id: 123, name: 'sample', path: 'sample') + projects.create!(id: 123, name: 'sample', path: 'sample', namespace_id: 123) + + builds.create!(id: 1, project_id: 123, status: 'pending', type: 'Ci::Build') + builds.create!(id: 2, project_id: 123, status: 'pending', type: 'GenericCommitStatus') + builds.create!(id: 3, project_id: 123, status: 'success', type: 'Ci::Bridge') + builds.create!(id: 4, project_id: 123, status: 'success', type: 'Ci::Build') + builds.create!(id: 5, project_id: 123, status: 'running', type: 'Ci::Build') + builds.create!(id: 6, project_id: 123, status: 'created', type: 'Ci::Build') + + queue.create!(id: 1, project_id: 123, build_id: 1) + queue.create!(id: 2, project_id: 123, build_id: 4) + queue.create!(id: 3, project_id: 123, build_id: 5) + end + + it 'removes duplicated data from pending builds table' do + migrate! + + expect(queue.all.count).to eq 1 + expect(queue.first.id).to eq 1 + expect(builds.all.count).to eq 6 + end + + context 'when there are multiple batches' do + before do + stub_const("#{described_class}::BATCH_SIZE", 1) + end + + it 'iterates the data correctly' do + migrate! + + expect(queue.all.count).to eq 1 + end + end +end |