Commit 826e1b6f authored by Kerri Miller's avatar Kerri Miller

Merge branch 'jejacks0n/tooling/improve-gitlab-experiment-deprecation-handling' into 'master'

Improve how we handle deprecation warnings

See merge request gitlab-org/gitlab!79994
parents 3312e2b3 7b85759a
# frozen_string_literal: true # frozen_string_literal: true
module Gitlab
class Experiment
class Configuration
def self.deprecated(*args, version:, stack: 0)
# do nothing here
end
end
end
end
Gitlab::Experiment.configure do |config| Gitlab::Experiment.configure do |config|
# The base experiment class that will be instantiated when using the # The base experiment class that will be instantiated when using the
# `experiment` DSL, is our ApplicationExperiment. If a custom experiment # `experiment` DSL, is our ApplicationExperiment. If a custom experiment
...@@ -81,4 +71,31 @@ Gitlab::Experiment.configure do |config| ...@@ -81,4 +71,31 @@ Gitlab::Experiment.configure do |config|
) )
)) ))
end end
# Deprecation warnings resolution for 0.7.0
#
# We're working through deprecation warnings one by one in:
# https://gitlab.com/gitlab-org/gitlab/-/issues/350944
#
config.singleton_class.prepend(Module.new do
# Disable all deprecations in non dev/test environments.
#
def deprecated(*args, version:, stack: 0)
super if Gitlab.dev_or_test_env?
end
# Maintain a list of resolved deprecations to ensure that no new uses appear.
#
# Once a resolved deprecation warning has been added here, any future use will
# raise an exception.
#
ActiveSupport::Deprecation.disallowed_warnings += [
# 'Gitlab::Experiment 0.8 (instead use `control`)', # don't use `use`
# 'Gitlab::Experiment 0.8 (instead use `candidate`)', # don't use `try`
# 'Gitlab::Experiment 0.8 (instead use `variant(:variant_name)`)', # don't use `try(:variant_name)`
# 'Gitlab::Experiment 0.8 (instead use `assigned(:candidate)`)', # don't use variant(:variant_name) to assign
# 'Gitlab::Experiment 0.8 (instead use `assigned`)', # don't use variant.name to get the assigned variant
# 'Gitlab::Experiment 0.8, instead register variants using:', # don't use public `*_behavior` methods
]
end)
end end
...@@ -391,4 +391,29 @@ RSpec.describe ApplicationExperiment, :experiment do ...@@ -391,4 +391,29 @@ RSpec.describe ApplicationExperiment, :experiment do
end end
end end
end end
context "with deprecation warnings" do
before do
Gitlab::Experiment::Configuration.instance_variable_set(:@__dep_versions, nil) # clear the internal memoization
allow(ActiveSupport::Deprecation).to receive(:new).and_call_original
end
it "doesn't warn on non dev/test environments" do
allow(Gitlab).to receive(:dev_or_test_env?).and_return(false)
expect { experiment(:example) { |e| e.use { } } }.not_to raise_error
expect(ActiveSupport::Deprecation).not_to have_received(:new).with(anything, 'Gitlab::Experiment')
end
it "warns on dev and test environments" do
allow(Gitlab).to receive(:dev_or_test_env?).and_return(true)
# This will eventually raise an ActiveSupport::Deprecation exception,
# it's ok to change it when that happens.
expect { experiment(:example) { |e| e.use { } } }.not_to raise_error
expect(ActiveSupport::Deprecation).to have_received(:new).with(anything, 'Gitlab::Experiment')
end
end
end end
...@@ -26,7 +26,3 @@ RSpec.configure do |config| ...@@ -26,7 +26,3 @@ RSpec.configure do |config|
stub_snowplow stub_snowplow
end end
end end
# Once you've resolved a given deprecation, you can disallow it here, which
# will raise an exception if it's used anywhere.
ActiveSupport::Deprecation.disallowed_warnings << "`experiment_group?` is deprecated"
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