Skip to content

Replace let_it_be with let in usage_data_queries_spec.rb

euko requested to merge ek-replace-let-it-be-with-let-usage-data-queries into master

usage_data_queries_spec.rb is timing out in CI pipelines.

https://gitlab.com/gitlab-org/gitlab/-/jobs/5082536272
API::UsageDataQueries
  GET /usage_data/usage_data_queries
    with authentication
      returns queries if user is admin
      returns forbidden if user is not admin
      behaves like GET request permissions for admin mode
        behaves like when admin
          behaves like makes request
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:25: warning: already initialized constant MACROS_MARKER
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:25: warning: previous definition of MACROS_MARKER was here
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:27: warning: already initialized constant DO_NOT_SPLIT
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:27: warning: previous definition of DO_NOT_SPLIT was here
            returns
          behaves like makes request
            returns
        behaves like when user
          returns
          behaves like makes request
            returns
    without authentication
      returns unauthorized
    when feature_flag is disabled
      returns not_found for admin
      returns forbidden for non-admin
    when querying sql metrics
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:25: warning: already initialized constant MACROS_MARKER
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:25: warning: previous definition of MACROS_MARKER was here
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:27: warning: already initialized constant DO_NOT_SPLIT
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:27: warning: previous definition of DO_NOT_SPLIT was here
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:25: warning: already initialized constant MACROS_MARKER
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:25: warning: previous definition of MACROS_MARKER was here
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:27: warning: already initialized constant DO_NOT_SPLIT
/builds/gitlab-org/gitlab/vendor/ruby/3.0.0/gems/ohai-17.9.0/lib/ohai/plugins/rpm.rb:27: warning: previous definition of DO_NOT_SPLIT was here
      matches the generated query
      
An error occurred in an `after(:context)` hook.
Failure/Error: connection.public_send(...)
ActiveRecord::QueryCanceled:
  PG::QueryCanceled: ERROR:  canceling statement due to statement timeout
# ./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:137:in `block in read_write'
# ./lib/gitlab/database/load_balancing/load_balancer.rb:224:in `retry_with_backoff'
# ./lib/gitlab/database/load_balancing/load_balancer.rb:126: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:96:in `method_missing'
# ./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:137:in `block in read_write'
# ./lib/gitlab/database/load_balancing/load_balancer.rb:224:in `retry_with_backoff'
# ./lib/gitlab/database/load_balancing/load_balancer.rb:126: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:96:in `method_missing'
# ./spec/support/db_cleaner.rb:11:in `delete_from_all_tables!'
# ./spec/rake_helper.rb:15:in `block (2 levels) in <top (required)>'
# ------------------
# --- Caused by: ---
# PG::QueryCanceled:
#   ERROR:  canceling statement due to statement timeout
#   ./lib/gitlab/database/load_balancing/connection_proxy.rb:127:in `public_send'

Why? The specs that use Rake tasks run with :delete Rspec metadata tag and let_it_be conflicts with the DatabaseCleaner's deletion strategy leading to PG timeouts.

https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#common-test-setup

let_it_be and before_all do not work with DatabaseCleaner’s deletion strategy. This includes migration specs, Rake task specs, and specs that have the :delete RSpec metadata tag. For more information, see issue 420379.

MR acceptance checklist

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

Merge request reports

Loading