Geo: Improve tests for Geo verification scopes
Problem
The recent fix in !205710 (merged) revealed that our existing tests for Geo::VerificationState scopes failed to catch a PG::UndefinedColumn error that was occurring in production environments. The needs_reverification scope was generating invalid SQL by trying to query verified_at on the wrong table, but our tests didn't detect this issue.
This suggests our current test suite is likely:
- Using mocks instead of actual database queries
- Not validating the generated SQL
- Not testing the full query execution path
Root Cause
The issue occurred because:
- The
needs_reverificationscope was usingverified_atdirectly instead ofverification_arel_table[:verified_at] - For models with separate state tables (e.g.,
uploadvsupload_state), this generated invalid SQL - Our tests didn't catch this because they weren't actually executing the database queries
Proposed Solution
Add comprehensive integration tests that:
- Test actual SQL execution - Ensure scopes actually run against a real database
- Verify cross-table relationships - Test models that use separate state tables (uploads, etc.)
-
Test scope combinations - Verify that chained scopes like
verification_succeeded.where(...)work correctly - Add SQL assertion helpers - Create test utilities to verify generated SQL structure
Example test cases needed:
describe 'needs_reverification scope' do
before do
stub_current_geo_node(primary_node)
end
let_it_be(:old_verified_upload) do
create(:upload).tap do |upload|
upload.verification_succeeded!
upload.update_column(:verified_at, 20.days.ago)
end
end
let_it_be(:recent_verified_upload) do
create(:upload).tap do |upload|
upload.verification_succeeded!
upload.update_column(:verified_at, 2.days.ago)
end
end
it 'returns uploads verified more than minimum_reverification_interval days ago' do
expect(Upload.needs_reverification).to contain_exactly(old_verified_upload)
end
end
Files to update:
ee/spec/models/concerns/geo/verification_state_spec.rb- Add new integration test files for specific replicable models
- Consider adding shared examples for verification scope testing
Acceptance Criteria
-
Tests execute actual database queries (no mocking of core ActiveRecord methods) -
Tests cover models with separate state tables (Upload, LfsObject, etc.) -
Tests verify that scopes can be chained without SQL errors
Edited by Scott Murray