Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix configuration for combined experiments #724

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion lib/split/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,13 @@ def bots

def experiments=(experiments)
raise InvalidExperimentsFormatError.new("Experiments must be a Hash") unless experiments.respond_to?(:keys)
@experiments = experiments
@experiments = experiments.clone
experiments.each do |name, settings|
value_for(settings, :combined_experiments)&.each do |combined_name|
@experiments[combined_name] =
settings.reject { |k, v| [:combined_experiments, "combined_experiments"].include?(k) }
end
end
end

def disabled?
Expand Down
19 changes: 17 additions & 2 deletions spec/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,28 @@
alternatives:
- a
- b
combined_experiment:
alternatives:
- a
- b
combined_experiments:
- combined1
- combined2
resettable: false
eos
@config.experiments = YAML.load(experiments_yaml)
end

it "should normalize experiments" do
expect(@config.normalized_experiments).to eq({ my_experiment: { resettable: false, alternatives: [{ "Control Opt"=>0.67 },
[{ "Alt One"=>0.1 }, { "Alt Two"=>0.23 }]] }, another_experiment: { alternatives: ["a", ["b"]] } })
result = {
my_experiment: { resettable: false, alternatives: [{ "Control Opt"=>0.67 }, [{ "Alt One"=>0.1 }, { "Alt Two"=>0.23 }]] },
another_experiment: { alternatives: ["a", ["b"]] },
combined_experiment: { resettable: false, alternatives: ["a", ["b"]] },
combined1: { resettable: false, alternatives: ["a", ["b"]] },
combined2: { resettable: false, alternatives: ["a", ["b"]] }
}

expect(@config.normalized_experiments).to eq(result)
end

it "should recognize metrics" do
Expand Down
18 changes: 18 additions & 0 deletions spec/helper_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,24 @@
expect(ab_user[experiment.key]).to eq(alternative)
expect(ab_user[experiment.finished_key]).to eq(true)
end

context "combined experiment" do
it "passes reset option" do
Split.configuration.experiments = {
combined: {
alternatives: ["one", "two"],
combined_experiments: [:combined1],
resettable: false,
},
}
alternative = ab_test(:combined1)
experiment = Split::ExperimentCatalog.find :combined1

ab_finished :combined1
expect(ab_user[experiment.key]).to eq(alternative)
expect(ab_user[experiment.finished_key]).to eq(true)
end
end
end

context "finished with metric name" do
Expand Down