diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-02-18 09:45:46 +0000 |
commit | a7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch) | |
tree | 7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/experiments | |
parent | ee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff) | |
download | gitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz |
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/experiments')
3 files changed, 53 insertions, 108 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb index 5146fe3e752..70ee4bd3c5a 100644 --- a/spec/experiments/application_experiment_spec.rb +++ b/spec/experiments/application_experiment_spec.rb @@ -24,38 +24,6 @@ RSpec.describe ApplicationExperiment, :experiment do expect { experiment('namespaced/stub') { } }.not_to raise_error end - describe "#enabled?" do - before do - allow(application_experiment).to receive(:enabled?).and_call_original - - allow(Feature::Definition).to receive(:get).and_return('_instance_') - allow(Gitlab).to receive(:dev_env_or_com?).and_return(true) - allow(Feature).to receive(:get).and_return(double(state: :on)) - end - - it "is enabled when all criteria are met" do - expect(application_experiment).to be_enabled - end - - it "isn't enabled if the feature definition doesn't exist" do - expect(Feature::Definition).to receive(:get).with('namespaced_stub').and_return(nil) - - expect(application_experiment).not_to be_enabled - end - - it "isn't enabled if we're not in dev or dotcom environments" do - expect(Gitlab).to receive(:dev_env_or_com?).and_return(false) - - expect(application_experiment).not_to be_enabled - end - - it "isn't enabled if the feature flag state is :off" do - expect(Feature).to receive(:get).with('namespaced_stub').and_return(double(state: :off)) - - expect(application_experiment).not_to be_enabled - end - end - describe "#publish" do let(:should_track) { true } @@ -117,7 +85,7 @@ RSpec.describe ApplicationExperiment, :experiment do describe '#publish_to_database' do using RSpec::Parameterized::TableSyntax - let(:publish_to_database) { application_experiment.publish_to_database } + let(:publish_to_database) { ActiveSupport::Deprecation.silence { application_experiment.publish_to_database } } shared_examples 'does not record to the database' do it 'does not create an experiment record' do @@ -214,26 +182,6 @@ RSpec.describe ApplicationExperiment, :experiment do ) end - it "tracks the event correctly even when using the base class" do - subject = Gitlab::Experiment.new(:unnamed) - subject.track(:action, context: [fake_context]) - - expect_snowplow_event( - category: 'unnamed', - action: 'action', - context: [ - { - schema: 'iglu:com.gitlab/fake/jsonschema/0-0-0', - data: { data: '_data_' } - }, - { - schema: 'iglu:com.gitlab/gitlab_experiment/jsonschema/1-0-0', - data: { experiment: 'unnamed', key: subject.context.key, variant: 'control' } - } - ] - ) - end - context "when using known context resources" do let(:user) { build(:user, id: non_existing_record_id) } let(:project) { build(:project, id: non_existing_record_id) } @@ -347,23 +295,15 @@ RSpec.describe ApplicationExperiment, :experiment do end context "when resolving variants" do - it "uses the default value as specified in the yaml" do - expect(Feature).to receive(:enabled?).with('namespaced_stub', application_experiment, type: :experiment, default_enabled: :yaml) - - expect(application_experiment.variant.name).to eq('control') + before do + stub_feature_flags(namespaced_stub: true) end - context "when rolled out to 100%" do - before do - stub_feature_flags(namespaced_stub: true) - end - - it "returns the first variant name" do - application_experiment.try(:variant1) {} - application_experiment.try(:variant2) {} + it "returns an assigned name" do + application_experiment.variant(:variant1) {} + application_experiment.variant(:variant2) {} - expect(application_experiment.variant.name).to eq('variant1') - end + expect(application_experiment.assigned.name).to eq('variant2') end end @@ -395,8 +335,8 @@ RSpec.describe ApplicationExperiment, :experiment do cache.clear(key: application_experiment.name) - application_experiment.use { } # setup the control - application_experiment.try { } # setup the candidate + application_experiment.control { } + application_experiment.candidate { } end it "caches the variant determined by the variant resolver" do @@ -451,4 +391,29 @@ RSpec.describe ApplicationExperiment, :experiment do 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 diff --git a/spec/experiments/new_project_readme_content_experiment_spec.rb b/spec/experiments/new_project_readme_content_experiment_spec.rb deleted file mode 100644 index a6a81580a29..00000000000 --- a/spec/experiments/new_project_readme_content_experiment_spec.rb +++ /dev/null @@ -1,38 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe NewProjectReadmeContentExperiment, :experiment do - subject { described_class.new(namespace: project.namespace) } - - let(:project) { create(:project, name: 'Experimental', description: 'An experiment project') } - - it "renders the basic README" do - expect(subject.run_with(project)).to eq(<<~MARKDOWN.strip) - # Experimental - - An experiment project - MARKDOWN - end - - describe "the advanced variant" do - let(:markdown) { subject.run_with(project, variant: :advanced) } - let(:initial_url) { 'https://docs.gitlab.com/ee/user/project/repository/web_editor.html#create-a-file' } - - it "renders the project details" do - expect(markdown).to include(<<~MARKDOWN.strip) - # Experimental - - An experiment project - - ## Getting started - MARKDOWN - end - - it "renders redirect URLs" do - url = Rails.application.routes.url_helpers.experiment_redirect_url(subject, url: initial_url) - expect(url).to include("/-/experiment/#{subject.to_param}?") - expect(markdown).to include(url) - end - end -end diff --git a/spec/experiments/require_verification_for_namespace_creation_experiment_spec.rb b/spec/experiments/require_verification_for_namespace_creation_experiment_spec.rb index 87417fe1637..269b6222020 100644 --- a/spec/experiments/require_verification_for_namespace_creation_experiment_spec.rb +++ b/spec/experiments/require_verification_for_namespace_creation_experiment_spec.rb @@ -5,7 +5,8 @@ require 'spec_helper' RSpec.describe RequireVerificationForNamespaceCreationExperiment, :experiment do subject(:experiment) { described_class.new(user: user) } - let_it_be(:user) { create(:user) } + let(:user_created_at) { RequireVerificationForNamespaceCreationExperiment::EXPERIMENT_START_DATE + 1.hour } + let(:user) { create(:user, created_at: user_created_at) } describe '#candidate?' do context 'when experiment subject is candidate' do @@ -56,4 +57,21 @@ RSpec.describe RequireVerificationForNamespaceCreationExperiment, :experiment do end end end + + describe 'exclusions' do + context 'when user is new' do + it 'is not excluded' do + expect(subject).not_to exclude(user: user) + end + end + + context 'when user is NOT new' do + let(:user_created_at) { RequireVerificationForNamespaceCreationExperiment::EXPERIMENT_START_DATE - 1.day } + let(:user) { create(:user, created_at: user_created_at) } + + it 'is excluded' do + expect(subject).to exclude(user: user) + end + end + end end |