Skip to content
Snippets Groups Projects
Unverified Commit 7864aea4 authored by Stan Hu's avatar Stan Hu Committed by GitLab
Browse files

Fix flaky restrict_gitlab_schema_spec.rb

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.

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 https://gitlab.com/gitlab-org/gitlab/-/issues/416143
parent 7739ec3a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -68,11 +68,8 @@ def stop_working
if server
# we close sockets if thread is not longer running
# this happens, when the process forks
if thread.alive?
server.shutdown
else
server.listeners.each(&:close)
end
server.listeners.each(&:close) unless thread.alive?
server.shutdown
end
 
@server = nil
Loading
Loading
Loading
Loading
@@ -3,7 +3,7 @@
require 'spec_helper'
 
RSpec.describe Gitlab::Database::MigrationHelpers::RestrictGitlabSchema, query_analyzers: false,
stub_feature_flags: false, feature_category: :cell do
stub_feature_flags: false, use_clean_rails_redis_caching: true, feature_category: :cell do
let(:schema_class) { Class.new(Gitlab::Database::Migration[1.0]).include(described_class) }
 
# We keep only the GitlabSchemasValidateConnection analyzer running
Loading
Loading
Loading
Loading
@@ -216,7 +216,7 @@ def call(env)
# in separate thread
allow_any_instance_of(::WEBrick::HTTPServer)
.to receive(:start).and_wrap_original do |m, *args|
Thread.new do
@server_thread = Thread.new do # rubocop:disable RSpec/InstanceVariable -- let does not work for this case
m.call(*args)
rescue IOError
# is raised as we close listeners
Loading
Loading
@@ -224,8 +224,17 @@ def call(env)
end
end
 
attr_reader :server_thread
after do
exporter.stop
next unless server_thread
server_thread.join(0.05)
raise '`exporter.stop` should terminate `server_thread`' if server_thread.alive?
ensure
server_thread.kill.join if server_thread
end
 
with_them do
Loading
Loading
Loading
Loading
@@ -22,6 +22,7 @@ def stub_all_feature_flags
 
def unstub_all_feature_flags
Feature.stub = false
Feature.reset_flipper
end
 
# Stub Feature flags with `flag_name: true/false`
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment