diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-13 00:09:16 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-03-13 00:09:16 +0000 |
commit | aa64fed495bb15fd838be8ef17128988f78e240c (patch) | |
tree | aae87ffa3fa19ffc1abffc518b5bd694b2cab8b4 /spec/experiments | |
parent | 963c6277b29b205c38c24fa907dda933097fbd25 (diff) | |
download | gitlab-ce-aa64fed495bb15fd838be8ef17128988f78e240c.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/experiments')
-rw-r--r-- | spec/experiments/application_experiment_spec.rb | 75 | ||||
-rw-r--r-- | spec/experiments/members/invite_email_experiment_spec.rb | 41 |
2 files changed, 36 insertions, 80 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb index 1a0f35846fe..0a46155b56d 100644 --- a/spec/experiments/application_experiment_spec.rb +++ b/spec/experiments/application_experiment_spec.rb @@ -114,77 +114,22 @@ RSpec.describe ApplicationExperiment, :experiment do end describe "variant resolution" do - context "when using the default feature flag percentage rollout" do - it "uses the default value as specified in the yaml" do - expect(Feature).to receive(:enabled?).with('namespaced_stub', subject, type: :experiment, default_enabled: :yaml) + it "uses the default value as specified in the yaml" do + expect(Feature).to receive(:enabled?).with('namespaced_stub', subject, type: :experiment, default_enabled: :yaml) - expect(subject.variant.name).to eq('control') - end - - it "returns nil when not rolled out" do - stub_feature_flags(namespaced_stub: false) - - expect(subject.variant.name).to eq('control') - end - - context "when rolled out to 100%" do - it "returns the first variant name" do - subject.try(:variant1) {} - subject.try(:variant2) {} - - expect(subject.variant.name).to eq('variant1') - end - end + expect(subject.variant.name).to eq('control') end - context "when using the round_robin strategy", :clean_gitlab_redis_shared_state do - context "when variants aren't supplied" do - subject :inheriting_class do - Class.new(described_class) do - def rollout_strategy - :round_robin - end - end.new('namespaced/stub') - end - - it "raises an error" do - expect { inheriting_class.variants }.to raise_error(NotImplementedError) - end + context "when rolled out to 100%" do + before do + stub_feature_flags(namespaced_stub: true) end - context "when variants are supplied" do - let(:inheriting_class) do - Class.new(described_class) do - def rollout_strategy - :round_robin - end - - def variants - %i[variant1 variant2 control] - end - end - end - - it "proves out round robin in variant selection", :aggregate_failures do - instance_1 = inheriting_class.new('namespaced/stub') - allow(instance_1).to receive(:enabled?).and_return(true) - instance_2 = inheriting_class.new('namespaced/stub') - allow(instance_2).to receive(:enabled?).and_return(true) - instance_3 = inheriting_class.new('namespaced/stub') - allow(instance_3).to receive(:enabled?).and_return(true) - - instance_1.try {} - - expect(instance_1.variant.name).to eq('variant2') - - instance_2.try {} - - expect(instance_2.variant.name).to eq('control') - - instance_3.try {} + it "returns the first variant name" do + subject.try(:variant1) {} + subject.try(:variant2) {} - expect(instance_3.variant.name).to eq('variant1') - end + expect(subject.variant.name).to eq('variant1') end end end diff --git a/spec/experiments/members/invite_email_experiment_spec.rb b/spec/experiments/members/invite_email_experiment_spec.rb index 4376c021385..539230e39b9 100644 --- a/spec/experiments/members/invite_email_experiment_spec.rb +++ b/spec/experiments/members/invite_email_experiment_spec.rb @@ -3,26 +3,14 @@ require 'spec_helper' RSpec.describe Members::InviteEmailExperiment do - subject :invite_email do - experiment('members/invite_email', actor: double('Member', created_by: double('User', avatar_url: '_avatar_url_'))) - end + subject(:invite_email) { experiment('members/invite_email', **context) } + + let(:context) { { actor: double('Member', created_by: double('User', avatar_url: '_avatar_url_')) } } before do allow(invite_email).to receive(:enabled?).and_return(true) end - describe "#rollout_strategy" do - it "resolves to round_robin" do - expect(invite_email.rollout_strategy).to eq(:round_robin) - end - end - - describe "#variants" do - it "has all the expected variants" do - expect(invite_email.variants).to match(%i[avatar permission_info control]) - end - end - describe "exclusions", :experiment do it "excludes when created by is nil" do expect(experiment('members/invite_email')).to exclude(actor: double(created_by: nil)) @@ -34,4 +22,27 @@ RSpec.describe Members::InviteEmailExperiment do expect(experiment('members/invite_email')).to exclude(actor: member_without_avatar_url) end end + + describe "variant resolution", :clean_gitlab_redis_shared_state do + it "proves out round robin in variant selection", :aggregate_failures do + instance_1 = described_class.new('members/invite_email', **context) + allow(instance_1).to receive(:enabled?).and_return(true) + instance_2 = described_class.new('members/invite_email', **context) + allow(instance_2).to receive(:enabled?).and_return(true) + instance_3 = described_class.new('members/invite_email', **context) + allow(instance_3).to receive(:enabled?).and_return(true) + + instance_1.try { } + + expect(instance_1.variant.name).to eq('permission_info') + + instance_2.try { } + + expect(instance_2.variant.name).to eq('control') + + instance_3.try { } + + expect(instance_3.variant.name).to eq('avatar') + end + end end |