Skip to content

Commit ec4dcfc

Browse files
committed
Fix: Rollout experiment mapping issue
1 parent 486357d commit ec4dcfc

File tree

3 files changed

+51
-4
lines changed

3 files changed

+51
-4
lines changed

lib/optimizely/project_config.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class ProjectConfig
5555
attr_reader :group_key_map
5656
attr_reader :rollout_id_map
5757
attr_reader :rollout_experiment_id_map
58+
attr_reader :rollout_experiment_key_map
5859
attr_reader :variation_id_map
5960
attr_reader :variation_id_to_variable_usage_map
6061
attr_reader :variation_key_map
@@ -120,13 +121,15 @@ def initialize(datafile, logger, error_handler)
120121
end
121122
end
122123
@rollout_id_map = generate_key_map(@rollouts, 'id')
123-
# split out the experiment id map for rollouts
124+
# split out the experiment id and key map for rollouts
124125
@rollout_experiment_id_map = {}
126+
@rollout_experiment_key_map = {}
125127
@rollout_id_map.each_value do |rollout|
126128
exps = rollout.fetch('experiments')
127129
@rollout_experiment_id_map = @rollout_experiment_id_map.merge(generate_key_map(exps, 'id'))
130+
@rollout_experiment_key_map = @rollout_experiment_key_map.merge(generate_key_map(exps, 'key'))
128131
end
129-
@all_experiments = @experiment_key_map.merge(@rollout_experiment_id_map)
132+
@all_experiments = @experiment_key_map.merge(@rollout_experiment_key_map)
130133
@all_experiments.each do |key, exp|
131134
variations = exp.fetch('variations')
132135
variations.each do |variation|

spec/project_config_spec.rb

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,14 @@
264264
feature_enabled => true,
265265
'variables' => []
266266
}
267+
},
268+
'rollout_exp_with_diff_id_and_key' => {
269+
'177781' => {
270+
'id' => '177781',
271+
'key' => 'rollout_var_with_diff_id_and_key',
272+
feature_enabled => true,
273+
'variables' => []
274+
}
267275
}
268276
}
269277

@@ -448,6 +456,14 @@
448456
feature_enabled => true,
449457
'variables' => []
450458
}
459+
},
460+
'rollout_exp_with_diff_id_and_key' => {
461+
'rollout_var_with_diff_id_and_key' => {
462+
'id' => '177781',
463+
'key' => 'rollout_var_with_diff_id_and_key',
464+
feature_enabled => true,
465+
'variables' => []
466+
}
451467
}
452468
}
453469

@@ -641,7 +657,8 @@
641657
'value' => 'false'
642658
}
643659
},
644-
'177780' => {}
660+
'177780' => {},
661+
'177781' => {}
645662
}
646663

647664
expected_rollout_id_map = {
@@ -654,7 +671,17 @@
654671
'177772' => config_body['rollouts'][0]['experiments'][1],
655672
'177776' => config_body['rollouts'][0]['experiments'][2],
656673
'177774' => config_body['rollouts'][1]['experiments'][0],
657-
'177779' => config_body['rollouts'][1]['experiments'][1]
674+
'177779' => config_body['rollouts'][1]['experiments'][1],
675+
'177780' => config_body['rollouts'][1]['experiments'][2]
676+
}
677+
678+
expected_rollout_experiment_key_map = {
679+
'177770' => config_body['rollouts'][0]['experiments'][0],
680+
'177772' => config_body['rollouts'][0]['experiments'][1],
681+
'177776' => config_body['rollouts'][0]['experiments'][2],
682+
'177774' => config_body['rollouts'][1]['experiments'][0],
683+
'177779' => config_body['rollouts'][1]['experiments'][1],
684+
'rollout_exp_with_diff_id_and_key' => config_body['rollouts'][1]['experiments'][2]
658685
}
659686

660687
expect(project_config.attribute_key_map).to eq(expected_attribute_key_map)
@@ -669,6 +696,7 @@
669696
expect(project_config.variation_id_to_variable_usage_map).to eq(expected_variation_id_to_variable_usage_map)
670697
expect(project_config.rollout_id_map).to eq(expected_rollout_id_map)
671698
expect(project_config.rollout_experiment_id_map).to eq(expected_rollout_experiment_id_map)
699+
expect(project_config.rollout_experiment_key_map).to eq(expected_rollout_experiment_key_map)
672700
end
673701

674702
it 'should initialize properties correctly upon creating project with typed audience dict' do

spec/spec_params.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -659,6 +659,22 @@ module OptimizelySpec
659659
'entityId' => '177780',
660660
'endOfRange' => 1500
661661
}]
662+
}, {
663+
'id' => '177780',
664+
'key' => 'rollout_exp_with_diff_id_and_key',
665+
'status' => 'Running',
666+
'layerId' => '166661',
667+
'audienceIds' => [],
668+
'variations' => [{
669+
'id' => '177781',
670+
'key' => 'rollout_var_with_diff_id_and_key',
671+
'featureEnabled' => true,
672+
'variables' => []
673+
}],
674+
'trafficAllocation' => [{
675+
'entityId' => '177781',
676+
'endOfRange' => 1500
677+
}]
662678
}]
663679
}]
664680
}.freeze

0 commit comments

Comments
 (0)