From ce53319cf928c1e7490c4ca79deeed17e40f4510 Mon Sep 17 00:00:00 2001
From: Mehmet Emin INAC <minac@gitlab.com>
Date: Fri, 8 Jan 2021 14:22:55 +0100
Subject: [PATCH] Add test for error capturing

---
 ...ing_uuid_for_vulnerability_feedback_spec.rb | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb b/spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb
index 12cadabf8cd..8e74935e127 100644
--- a/spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb
+++ b/spec/lib/gitlab/background_migration/populate_finding_uuid_for_vulnerability_feedback_spec.rb
@@ -91,5 +91,23 @@ RSpec.describe Gitlab::BackgroundMigration::PopulateFindingUuidForVulnerabilityF
       # Load feedback records(1), load findings(2), load identifiers(3) and finally update feedback records one by one(6)
       expect { populate_finding_uuids }.not_to exceed_query_limit(6)
     end
+
+    context 'when setting the `finding_uuid` attribute of a feedback record fails' do
+      let(:expected_error) { RuntimeError.new }
+
+      before do
+        allow(Gitlab::ErrorTracking).to receive(:track_and_raise_for_dev_exception)
+
+        allow_next_found_instance_of(described_class::VulnerabilityFeedback) do |feedback|
+          allow(feedback).to receive(:update_column).and_raise(expected_error)
+        end
+      end
+
+      it 'captures the errors and does not crash entirely' do
+        expect { populate_finding_uuids }.not_to raise_error
+
+        expect(Gitlab::ErrorTracking).to have_received(:track_and_raise_for_dev_exception).with(expected_error).exactly(3).times
+      end
+    end
   end
 end
-- 
2.30.9