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(is_feature_enabled): Added rollout experiment key map for onboarding datafile #168

Merged
merged 2 commits into from
May 17, 2019
Merged
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
10 changes: 5 additions & 5 deletions lib/optimizely/project_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class ProjectConfig
attr_reader :feature_variable_key_map
attr_reader :group_key_map
attr_reader :rollout_id_map
attr_reader :rollout_experiment_id_map
attr_reader :rollout_experiment_key_map
attr_reader :variation_id_map
attr_reader :variation_id_to_variable_usage_map
attr_reader :variation_key_map
Expand Down Expand Up @@ -120,13 +120,13 @@ def initialize(datafile, logger, error_handler)
end
end
@rollout_id_map = generate_key_map(@rollouts, 'id')
# split out the experiment id map for rollouts
@rollout_experiment_id_map = {}
# split out the experiment key map for rollouts
@rollout_experiment_key_map = {}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now where rollout_experiment_id_map is being used in the code.

@rollout_id_map.each_value do |rollout|
exps = rollout.fetch('experiments')
@rollout_experiment_id_map = @rollout_experiment_id_map.merge(generate_key_map(exps, 'id'))
@rollout_experiment_key_map = @rollout_experiment_key_map.merge(generate_key_map(exps, 'key'))
end
@all_experiments = @experiment_key_map.merge(@rollout_experiment_id_map)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wow this is a big mistake we didn't catch in the code review last time around

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Luckily IDs and keys have been same, but if it had changed things would be really very bad.

@all_experiments = @experiment_key_map.merge(@rollout_experiment_key_map)
@all_experiments.each do |key, exp|
variations = exp.fetch('variations')
variations.each do |variation|
Expand Down
26 changes: 22 additions & 4 deletions spec/project_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,14 @@
feature_enabled => true,
'variables' => []
}
},
'rollout_exp_with_diff_id_and_key' => {
'177781' => {
'id' => '177781',
'key' => 'rollout_var_with_diff_id_and_key',
feature_enabled => true,
'variables' => []
}
}
}

Expand Down Expand Up @@ -448,6 +456,14 @@
feature_enabled => true,
'variables' => []
}
},
'rollout_exp_with_diff_id_and_key' => {
'rollout_var_with_diff_id_and_key' => {
'id' => '177781',
'key' => 'rollout_var_with_diff_id_and_key',
feature_enabled => true,
'variables' => []
}
}
}

Expand Down Expand Up @@ -641,20 +657,22 @@
'value' => 'false'
}
},
'177780' => {}
'177780' => {},
'177781' => {}
}

expected_rollout_id_map = {
'166660' => config_body['rollouts'][0],
'166661' => config_body['rollouts'][1]
}

expected_rollout_experiment_id_map = {
expected_rollout_experiment_key_map = {
'177770' => config_body['rollouts'][0]['experiments'][0],
'177772' => config_body['rollouts'][0]['experiments'][1],
'177776' => config_body['rollouts'][0]['experiments'][2],
'177774' => config_body['rollouts'][1]['experiments'][0],
'177779' => config_body['rollouts'][1]['experiments'][1]
'177779' => config_body['rollouts'][1]['experiments'][1],
'rollout_exp_with_diff_id_and_key' => config_body['rollouts'][1]['experiments'][2]
}

expect(project_config.attribute_key_map).to eq(expected_attribute_key_map)
Expand All @@ -668,7 +686,7 @@
expect(project_config.variation_key_map).to eq(expected_variation_key_map)
expect(project_config.variation_id_to_variable_usage_map).to eq(expected_variation_id_to_variable_usage_map)
expect(project_config.rollout_id_map).to eq(expected_rollout_id_map)
expect(project_config.rollout_experiment_id_map).to eq(expected_rollout_experiment_id_map)
expect(project_config.rollout_experiment_key_map).to eq(expected_rollout_experiment_key_map)
end

it 'should initialize properties correctly upon creating project with typed audience dict' do
Expand Down
16 changes: 16 additions & 0 deletions spec/spec_params.rb
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,22 @@ module OptimizelySpec
'entityId' => '177780',
'endOfRange' => 1500
}]
}, {
'id' => '177780',
'key' => 'rollout_exp_with_diff_id_and_key',
'status' => 'Running',
'layerId' => '166661',
'audienceIds' => [],
'variations' => [{
'id' => '177781',
'key' => 'rollout_var_with_diff_id_and_key',
'featureEnabled' => true,
'variables' => []
}],
'trafficAllocation' => [{
'entityId' => '177781',
'endOfRange' => 1500
}]
}]
}]
}.freeze
Expand Down