Skip to content

Commit

Permalink
Fix configuration for combined experiments
Browse files Browse the repository at this point in the history
Made sure configuration for parent experiment is available
for children(combined)
  • Loading branch information
Jealrock committed Jul 5, 2024
1 parent cdd66da commit bf3efdb
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 3 deletions.
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.except(:combined_experiments, "combined_experiments")
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

0 comments on commit bf3efdb

Please sign in to comment.