Skip to content

Improve LFK spec failure message

Thong Kuah requested to merge improve_spec_failure_message into master

What does this MR do and why?

Show the exact column / table missing instead of the connection object.

Also aggregate failures

Related issue: #346432 (closed)

Screenshots or screen recordings

Example improved failure message

Failures:

  1) Gitlab::Database::LooseForeignKeys verify all definitions ensuring database integrity all `from_table` tables are present
     Got 2 failures:

     1.1) Failure/Error:
            expect(model.connection).to be_column_exist(definition.from_table, definition.column),
              "Column #{definition.column} in #{definition.from_table} does not exist"
          
            Column project_idx in ci_build_report_results does not exist
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:80:in `block (6 levels) in <top (required)>'
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:77:in `each'
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:77:in `block (5 levels) in <top (required)>'
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:76:in `each'
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:76:in `block (4 levels) in <top (required)>'
          # ./spec/spec_helper.rb:421:in `block (3 levels) in <top (required)>'
          # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
          # ./spec/spec_helper.rb:412:in `block (2 levels) in <top (required)>'
          # ./spec/spec_helper.rb:408:in `block (3 levels) in <top (required)>'
          # ./lib/gitlab/application_context.rb:52:in `with_raw_context'
          # ./spec/spec_helper.rb:408:in `block (2 levels) in <top (required)>'
          # ./spec/spec_helper.rb:263:in `block (2 levels) in <top (required)>'
          # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <main>'
          # ./spec/support/database/prevent_cross_joins.rb:106:in `block (3 levels) in <main>'
          # ./spec/support/database/prevent_cross_joins.rb:60:in `with_cross_joins_prevented'
          # ./spec/support/database/prevent_cross_joins.rb:106:in `block (2 levels) in <main>'

     1.2) Failure/Error:
            expect(model.connection).to be_column_exist(definition.from_table, definition.column),
              "Column #{definition.column} in #{definition.from_table} does not exist"
          
            Column user_idx in ci_builds does not exist
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:80:in `block (6 levels) in <top (required)>'
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:77:in `each'
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:77:in `block (5 levels) in <top (required)>'
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:76:in `each'
          # ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:76:in `block (4 levels) in <top (required)>'
          # ./spec/spec_helper.rb:421:in `block (3 levels) in <top (required)>'
          # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
          # ./spec/spec_helper.rb:412:in `block (2 levels) in <top (required)>'
          # ./spec/spec_helper.rb:408:in `block (3 levels) in <top (required)>'
          # ./lib/gitlab/application_context.rb:52:in `with_raw_context'
          # ./spec/spec_helper.rb:408:in `block (2 levels) in <top (required)>'
          # ./spec/spec_helper.rb:263:in `block (2 levels) in <top (required)>'
          # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <main>'
          # ./spec/support/database/prevent_cross_joins.rb:106:in `block (3 levels) in <main>'
          # ./spec/support/database/prevent_cross_joins.rb:60:in `with_cross_joins_prevented'
          # ./spec/support/database/prevent_cross_joins.rb:106:in `block (2 levels) in <main>'

Finished in 9.8 seconds (files took 8.99 seconds to load)
2 examples, 1 failure

Failed examples:

rspec ./spec/lib/gitlab/database/loose_foreign_keys_spec.rb:75 # Gitlab::Database::LooseForeignKeys verify all definitions ensuring database integrity all `from_table` tables are present

How to set up and validate locally

Numbered steps to set up and validate the change are strongly suggested.

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Thong Kuah

Merge request reports

Loading