From 29467dd05a59d3c8f5e25e116fd0dc4a9444e061 Mon Sep 17 00:00:00 2001 From: Eugene Burmakin Date: Sat, 13 Dec 2025 21:23:20 +0100 Subject: [PATCH] Fix failing specs --- app/services/points/raw_data/verifier.rb | 21 +++++++++++++++---- config/schedule.yml | 8 +++---- .../services/points/raw_data/archiver_spec.rb | 2 +- spec/services/points/raw_data/clearer_spec.rb | 5 ++++- .../services/points/raw_data/verifier_spec.rb | 19 +++++++++++------ 5 files changed, 39 insertions(+), 16 deletions(-) diff --git a/app/services/points/raw_data/verifier.rb b/app/services/points/raw_data/verifier.rb index 833c1f38..de42229f 100644 --- a/app/services/points/raw_data/verifier.rb +++ b/app/services/points/raw_data/verifier.rb @@ -141,14 +141,19 @@ module Points end def verify_raw_data_matches(archived_data) - # Sample verification: check random points to ensure archived data matches database - # For performance, we'll verify a sample rather than all points - sample_size = [archived_data.size, 100].min - point_ids_to_check = archived_data.keys.sample(sample_size) + # For small archives, verify all points. For large archives, sample up to 100 points. + # Always verify all if 100 or fewer points for maximum accuracy + if archived_data.size <= 100 + point_ids_to_check = archived_data.keys + else + point_ids_to_check = archived_data.keys.sample(100) + end mismatches = [] + found_points = 0 Point.where(id: point_ids_to_check).find_each do |point| + found_points += 1 archived_raw_data = archived_data[point.id] current_raw_data = point.raw_data @@ -162,6 +167,14 @@ module Points end end + # Check if we found all the points we were looking for + if found_points != point_ids_to_check.size + return { + success: false, + error: "Missing points during data verification: expected #{point_ids_to_check.size}, found #{found_points}" + } + end + if mismatches.any? return { success: false, diff --git a/config/schedule.yml b/config/schedule.yml index 11f81d24..ea4e4351 100644 --- a/config/schedule.yml +++ b/config/schedule.yml @@ -50,7 +50,7 @@ nightly_family_invitations_cleanup_job: class: "Family::Invitations::CleanupJob" queue: family -raw_data_archival_job: - cron: "0 2 1 * *" # Monthly on the 1st at 2 AM - class: "Points::RawData::ArchiveJob" - queue: archival +# raw_data_archival_job: +# cron: "0 2 1 * *" # Monthly on the 1st at 2 AM +# class: "Points::RawData::ArchiveJob" +# queue: archival diff --git a/spec/services/points/raw_data/archiver_spec.rb b/spec/services/points/raw_data/archiver_spec.rb index 7ab5e334..259056de 100644 --- a/spec/services/points/raw_data/archiver_spec.rb +++ b/spec/services/points/raw_data/archiver_spec.rb @@ -51,7 +51,7 @@ RSpec.describe Points::RawData::Archiver do it 'keeps raw_data intact (does not clear yet)' do archiver.call Point.where(user: user).find_each do |point| - expect(point.raw_data).to eq({ lon: 13.4, lat: 52.5 }) + expect(point.raw_data).to eq({ 'lon' => 13.4, 'lat' => 52.5 }) end end diff --git a/spec/services/points/raw_data/clearer_spec.rb b/spec/services/points/raw_data/clearer_spec.rb index eef68804..536e6fb7 100644 --- a/spec/services/points/raw_data/clearer_spec.rb +++ b/spec/services/points/raw_data/clearer_spec.rb @@ -143,7 +143,10 @@ RSpec.describe Points::RawData::Clearer do it 'is idempotent (safe to run multiple times)' do first_result = clearer.call - second_result = clearer.call + + # Use a new instance for second call + new_clearer = Points::RawData::Clearer.new + second_result = new_clearer.call expect(first_result[:cleared]).to eq(5) expect(second_result[:cleared]).to eq(0) # Already cleared diff --git a/spec/services/points/raw_data/verifier_spec.rb b/spec/services/points/raw_data/verifier_spec.rb index ed77ce55..5611748a 100644 --- a/spec/services/points/raw_data/verifier_spec.rb +++ b/spec/services/points/raw_data/verifier_spec.rb @@ -62,20 +62,26 @@ RSpec.describe Points::RawData::Verifier do end it 'detects deleted points' do - # Delete one point from database + # Force archive creation first + archive_id = archive.id + + # Then delete one point from database points.first.destroy expect do - verifier.verify_specific_archive(archive.id) + verifier.verify_specific_archive(archive_id) end.not_to change { archive.reload.verified_at } end it 'detects raw_data mismatch between archive and database' do - # Modify raw_data in database after archiving + # Force archive creation first + archive_id = archive.id + + # Then modify raw_data in database after archiving points.first.update_column(:raw_data, { lon: 999.0, lat: 999.0 }) expect do - verifier.verify_specific_archive(archive.id) + verifier.verify_specific_archive(archive_id) end.not_to change { archive.reload.verified_at } end @@ -149,8 +155,9 @@ RSpec.describe Points::RawData::Verifier do # Verify once verifier.call - # Try to verify again - result = verifier.call + # Try to verify again with a new verifier instance + new_verifier = Points::RawData::Verifier.new + result = new_verifier.call expect(result[:verified]).to eq(0) expect(result[:failed]).to eq(0)