Commit 45525eb0 authored by jejacks0n's avatar jejacks0n

Stub gitlab-experiment config.cache in before each

- This shifts the stubbing behavior to all specs instead of a few.
parent dc9c2c37
# frozen_string_literal: true
Gitlab::Experiment.configure do |config|
config.define_singleton_method(:_default_cache) do
Gitlab::Experiment::Cache::RedisHashStore.new(
config.base_class = 'ApplicationExperiment'
config.cache = Gitlab::Experiment::Cache::RedisHashStore.new(
pool: ->(&block) { Gitlab::Redis::SharedState.with { |redis| block.call(redis) } }
)
end
config.base_class = 'ApplicationExperiment'
config.cache = config._default_cache
end
......@@ -191,15 +191,15 @@ RSpec.describe ApplicationExperiment, :experiment do
end
context "when caching" do
let(:cache) { Gitlab::Experiment::Configuration._default_cache } # as defined in the initializer
let(:cache) { Gitlab::Experiment::Configuration.cache }
before do
allow(Gitlab::Experiment::Configuration).to receive(:cache).and_call_original
cache.clear(key: subject.name)
subject.use { } # setup the control
subject.try { } # setup the candidate
allow(Gitlab::Experiment::Configuration).to receive(:cache).and_return(cache)
end
it "caches the variant determined by the variant resolver" do
......
......@@ -12,5 +12,9 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
end
end
# Disable all caching for experiments in tests.
Gitlab::Experiment::Configuration.cache = nil
RSpec.configure do |config|
# Disable all caching for experiments in tests.
config.before do
allow(Gitlab::Experiment::Configuration).to receive(:cache).and_return(nil)
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment