Skip to content

Cleaner backtrace for Rspec tests

What does this MR do and why?

When tests fails in rspec and raises active record exception. Backtrace includes several lines from lib/gitlab/database which makes reading backtrace difficult. This commit removes this file from the rspec backtrace so that developer can focus on what really matters in the backtrace

Before

2) Gitlab::BackgroundMigration::BackfillOrganizationIdKeys#perform when deploy key is associated with multiple projects uses organization_id from the first associated project
     Failure/Error: connection.public_send(...)

     ActiveRecord::RecordNotUnique:
       PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_projects_on_project_namespace_id"
       DETAIL:  Key (project_namespace_id)=(108) already exists.
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `public_send'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `block in write_using_load_balancer'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:150:in `block in read_write'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:248:in `retry_with_backoff'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:140:in `read_write'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:126:in `write_using_load_balancer'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:61:in `block (2 levels) in <class:ConnectionProxy>'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `public_send'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `block in write_using_load_balancer'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:150:in `block in read_write'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:248:in `retry_with_backoff'
     # ./lib/gitlab/database/load_balancing/load_balancer.rb:140:in `read_write'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:126:in `write_using_load_balancer'
     # ./lib/gitlab/database/load_balancing/connection_proxy.rb:78:in `transaction'
     # ./spec/lib/gitlab/background_migration/backfill_organization_id_keys_spec.rb:184:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:604:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:564:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:496:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/sidekiq_sharding/validator.rb:42:in `enabled'
     # ./spec/spec_helper.rb:495:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:490:in `block (3 levels) in <top (required)>'
     # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:481:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:477:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/application_context.rb:103:in `with_raw_context'
     # ./spec/spec_helper.rb:477:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:448:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/ci/config/feature_flags.rb:38:in `ensure_correct_usage'
     # ./spec/spec_helper.rb:447:in `block (2 levels) in <top (required)>'
     # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <main>'
     # ./spec/support/migration.rb:52: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>'
     # ------------------
     # --- Caused by: ---

After

   ActiveRecord::RecordNotUnique:
       PG::UniqueViolation: ERROR:  duplicate key value violates unique constraint "index_projects_on_project_namespace_id"
       DETAIL:  Key (project_namespace_id)=(122) already exists.
     # ./spec/lib/gitlab/background_migration/backfill_organization_id_keys_spec.rb:184:in `block (4 levels) in <top (required)>'
     # ./spec/spec_helper.rb:604:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:564:in `block (3 levels) in <top (required)>'
     # ./spec/spec_helper.rb:496:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/sidekiq_sharding/validator.rb:42:in `enabled'
     # ./spec/spec_helper.rb:495:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:490:in `block (3 levels) in <top (required)>'
     # ./spec/support/sidekiq_middleware.rb:9:in `with_sidekiq_server_middleware'
     # ./spec/spec_helper.rb:481:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:477:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/application_context.rb:103:in `with_raw_context'
     # ./spec/spec_helper.rb:477:in `block (2 levels) in <top (required)>'
     # ./spec/spec_helper.rb:448:in `block (3 levels) in <top (required)>'
     # ./lib/gitlab/ci/config/feature_flags.rb:38:in `ensure_correct_usage'
     # ./spec/spec_helper.rb:447:in `block (2 levels) in <top (required)>'
     # ./spec/support/system_exit_detected.rb:7:in `block (2 levels) in <main>'
     # ./spec/support/migration.rb:52: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>'
     # ------------------
     # --- Caused by: ---
     # PG::UniqueViolation:
     #   ERROR:  duplicate key value violates unique constraint "index_projects_on_project_namespace_id"

References

Screenshots or screen recordings

Before After

How to set up and validate locally

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Aboobacker MK

Merge request reports

Loading