summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb')
-rw-r--r--spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb32
1 files changed, 20 insertions, 12 deletions
diff --git a/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb b/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb
index 79699375a8d..f642ec8c20d 100644
--- a/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb
+++ b/spec/lib/gitlab/background_migration/backfill_vulnerability_reads_cluster_agent_spec.rb
@@ -23,8 +23,6 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillVulnerabilityReadsClusterAge
let(:sub_batch_size) { 1_000 }
let(:pause_ms) { 0 }
- subject(:perform_migration) { migration.perform }
-
before do
users_table.create!(id: 1, name: 'John Doe', email: 'test@example.com', projects_limit: 5)
@@ -49,20 +47,30 @@ RSpec.describe Gitlab::BackgroundMigration::BackfillVulnerabilityReadsClusterAge
add_vulnerability_read!(11, project_id: 1, cluster_agent_id: 1, report_type: 7)
end
- it 'backfills `casted_cluster_agent_id` for the selected records', :aggregate_failures do
- queries = ActiveRecord::QueryRecorder.new do
- perform_migration
+ describe '#filter_batch' do
+ it 'pick only vulnerability reads where report_type = 7' do
+ expect(migration.filter_batch(vulnerability_reads_table).pluck(:id)).to contain_exactly(1, 3, 7, 9, 10, 11)
end
-
- expect(queries.count).to eq(3)
- expect(vulnerability_reads_table.where.not(casted_cluster_agent_id: nil).count).to eq 3
- expect(vulnerability_reads_table.where.not(casted_cluster_agent_id: nil).pluck(:id)).to match_array([1, 9, 10])
end
- it 'tracks timings of queries' do
- expect(migration.batch_metrics.timings).to be_empty
+ describe '#perform' do
+ subject(:perform_migration) { migration.perform }
- expect { perform_migration }.to change { migration.batch_metrics.timings }
+ it 'backfills `casted_cluster_agent_id` for the selected records', :aggregate_failures do
+ queries = ActiveRecord::QueryRecorder.new do
+ perform_migration
+ end
+
+ expect(queries.count).to eq(3)
+ expect(vulnerability_reads_table.where.not(casted_cluster_agent_id: nil).count).to eq 3
+ expect(vulnerability_reads_table.where.not(casted_cluster_agent_id: nil).pluck(:id)).to match_array([1, 9, 10])
+ end
+
+ it 'tracks timings of queries' do
+ expect(migration.batch_metrics.timings).to be_empty
+
+ expect { perform_migration }.to change { migration.batch_metrics.timings }
+ end
end
private