Skip to content

Extract stub_settings_source into spec support file

Peter Leitzen requested to merge pl-spec-sidekiq-cli-settings-reload into master

What does this MR do and why?

This MR extracts the RSpec trait stubbing_settings_source into a separate support file.

It also renames stubbing_settings_source to stub_settings_source to keep consistency across other support files.

We need to require this support file in spec where stub_settings_source: true is used.

This avoids order dependent flaky specs like:

bin/rspec spec/commands/sidekiq_cluster/cli_spec.rb spec/lib/gitlab/pagination/offset_header_builder_spec.rb
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
.....................................bundle exec sidekiq -c2 -etest -t25 -gqueues:foo -r/home/peter/devel/gitlab/gdk-ee/gitlab -qfoo,1
.........FFF

Failures:

  1) Gitlab::Pagination::OffsetHeaderBuilder#execute sets headers to request context
     Failure/Error: uri.host = Gitlab.config.gitlab.host

     Settingslogic::MissingSetting:
       Missing setting 'gitlab' in /tmp/gitlab.yml20220120-2766343-4qkoh2
     # ./lib/gitlab/pagination/offset_header_builder.rb:48:in `block in base_request_uri'
     # ./lib/gitlab/pagination/offset_header_builder.rb:47:in `tap'
     # ./lib/gitlab/pagination/offset_header_builder.rb:47:in `base_request_uri'
     # ./lib/gitlab/pagination/offset_header_builder.rb:54:in `build_page_url'
     # ./lib/gitlab/pagination/offset_header_builder.rb:62:in `page_href'
     # ./lib/gitlab/pagination/offset_header_builder.rb:38:in `block in pagination_links'
     # ./lib/gitlab/pagination/offset_header_builder.rb:37:in `tap'
     # ./lib/gitlab/pagination/offset_header_builder.rb:37:in `pagination_links'
     # ./lib/gitlab/pagination/offset_header_builder.rb:26:in `execute'
     # ./spec/lib/gitlab/pagination/offset_header_builder_spec.rb:38:in `block (3 levels) in <main>'

  2) Gitlab::Pagination::OffsetHeaderBuilder#execute exclude total headers does not set total headers to request context
     Failure/Error: uri.host = Gitlab.config.gitlab.host

     Settingslogic::MissingSetting:
       Missing setting 'gitlab' in /tmp/gitlab.yml20220120-2766343-4qkoh2
     # ./lib/gitlab/pagination/offset_header_builder.rb:48:in `block in base_request_uri'
     # ./lib/gitlab/pagination/offset_header_builder.rb:47:in `tap'
     # ./lib/gitlab/pagination/offset_header_builder.rb:47:in `base_request_uri'
     # ./lib/gitlab/pagination/offset_header_builder.rb:54:in `build_page_url'
     # ./lib/gitlab/pagination/offset_header_builder.rb:62:in `page_href'
     # ./lib/gitlab/pagination/offset_header_builder.rb:38:in `block in pagination_links'
     # ./lib/gitlab/pagination/offset_header_builder.rb:37:in `tap'
     # ./lib/gitlab/pagination/offset_header_builder.rb:37:in `pagination_links'
     # ./lib/gitlab/pagination/offset_header_builder.rb:26:in `execute'
     # ./spec/lib/gitlab/pagination/offset_header_builder_spec.rb:46:in `block (4 levels) in <main>'

  3) Gitlab::Pagination::OffsetHeaderBuilder#execute pass data without counts does not set total headers to request context
     Failure/Error: uri.host = Gitlab.config.gitlab.host

     Settingslogic::MissingSetting:
       Missing setting 'gitlab' in /tmp/gitlab.yml20220120-2766343-4qkoh2
     # ./lib/gitlab/pagination/offset_header_builder.rb:48:in `block in base_request_uri'
     # ./lib/gitlab/pagination/offset_header_builder.rb:47:in `tap'
     # ./lib/gitlab/pagination/offset_header_builder.rb:47:in `base_request_uri'
     # ./lib/gitlab/pagination/offset_header_builder.rb:54:in `build_page_url'
     # ./lib/gitlab/pagination/offset_header_builder.rb:62:in `page_href'
     # ./lib/gitlab/pagination/offset_header_builder.rb:38:in `block in pagination_links'
     # ./lib/gitlab/pagination/offset_header_builder.rb:37:in `tap'
     # ./lib/gitlab/pagination/offset_header_builder.rb:37:in `pagination_links'
     # ./lib/gitlab/pagination/offset_header_builder.rb:26:in `execute'
     # ./spec/lib/gitlab/pagination/offset_header_builder_spec.rb:57:in `block (4 levels) in <main>'

Finished in 30.8 seconds (files took 3.61 seconds to load)
49 examples, 3 failures

Failed examples:

rspec ./spec/lib/gitlab/pagination/offset_header_builder_spec.rb:33 # Gitlab::Pagination::OffsetHeaderBuilder#execute sets headers to request context
rspec ./spec/lib/gitlab/pagination/offset_header_builder_spec.rb:42 # Gitlab::Pagination::OffsetHeaderBuilder#execute exclude total headers does not set total headers to request context
rspec ./spec/lib/gitlab/pagination/offset_header_builder_spec.rb:53 # Gitlab::Pagination::OffsetHeaderBuilder#execute pass data without counts does not set total headers to request context

Note, both specs about are run with fast_spec_helper so previously they would fail because RSpec trait stubbing_settings_source was not available.

Contributes to #350739.

How to set up and validate locally

Run:

bin/rspec spec/commands/sidekiq_cluster/cli_spec.rb spec/lib/gitlab/pagination/offset_header_builder_spec.rb

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 Peter Leitzen

Merge request reports

Loading