Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-02-13 00:09:01 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2021-02-13 00:09:01 +0300
commiteef0c69d45082b370f1e41e50f12488a216944f2 (patch)
tree5c4a5c0e4db3fff89b9b4146b799e5de9dca57b9 /spec/experiments/application_experiment_spec.rb
parent6d533fe8b44007d82b8de29a4b706da69e5f5936 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/experiments/application_experiment_spec.rb')
-rw-r--r--spec/experiments/application_experiment_spec.rb77
1 files changed, 65 insertions, 12 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb
index 6b4a3ece59e..501d344e920 100644
--- a/spec/experiments/application_experiment_spec.rb
+++ b/spec/experiments/application_experiment_spec.rb
@@ -115,24 +115,77 @@ RSpec.describe ApplicationExperiment, :experiment do
end
describe "variant resolution" 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)
+ 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)
- expect(subject.variant.name).to eq('control')
- end
+ 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
- it "returns nil when not rolled out" do
- stub_feature_flags(namespaced_stub: false)
+ 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('control')
+ expect(subject.variant.name).to eq('variant1')
+ end
+ end
end
- context "when rolled out to 100%" do
- it "returns the first variant name" do
- subject.try(:variant1) {}
- subject.try(:variant2) {}
+ 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
+ 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 {}
- expect(subject.variant.name).to eq('variant1')
+ expect(instance_3.variant.name).to eq('variant1')
+ end
end
end
end