Skip to content

Fix flaky restrict_gitlab_schema_spec.rb

Stan Hu requested to merge sh-fix-issue-416143 into master

What does this MR do and why?

This test was failing because Feature.enabled?(:redis_hll_tracking) was called in the migration and expecting the feature_names database table to be accessed. However, it wasn't accessed for two reasons:

  1. In tests we stub out feature flag access and use an in-memory cache. However, even though the test had stub_feature_flags: false set in the metadata, a stale Feature was still memoized and had to be cleared out. More specifically, https://gitlab.com/gitlab-org/gitlab/-/blob/73607c34155759294e3aae4c94213d2a4c0bcefe/spec/spec_helper.rb#L253-254 calls stub_all_feature_flags and stub_feature_flags(main_branch_over_master: false) immediately before the test. As a result, there was a stale Flipper instance at startup. unstub_all_feature_flags won't work properly until it's cleared out.

  2. With the feature flag stubs disabled, this enabled the Redis cache for feature flags. We need to clear this out between tests to ensure the database is hit.

Relates to #416143 (closed)

How to set up and validate locally

Locally this test failed for me regularly via:

bundle exec rspec "./spec/lib/gitlab/database/migration_helpers/restrict_gitlab_schema_spec.rb[1:2:17:1:3:1]"
bundle exec rspec "./spec/lib/gitlab/database/migration_helpers/restrict_gitlab_schema_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 Stan Hu

Merge request reports