-
Notifications
You must be signed in to change notification settings - Fork 29
fix(audience evaluation): evaluate unknown audience id to null and continue #153
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2016-2018, Optimizely | ||
| * Copyright 2016-2019, Optimizely | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -160,7 +160,12 @@ public static function isUserInExperiment($config, $experiment, $userAttributes) | |
|
|
||
| $evaluateAudience = function($audienceId) use ($config, $evaluateCustomAttr) { | ||
| $conditionTreeEvaluator = new ConditionTreeEvaluator(); | ||
|
|
||
| $audience = $config->getAudience($audienceId); | ||
| if ($audience === null) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think I have a preference to keep previous behavior and check if
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do you prefer it this way? I don't see any advantage to returning empty entity objects. Instead, they have caused issues. #107
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I see your point. Like I said it is a preference and I am not married to the idea. |
||
| return null; | ||
| } | ||
|
|
||
| return $conditionTreeEvaluator->evaluate($audience->getConditionsList(), $evaluateCustomAttr); | ||
| }; | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,6 @@ | ||
| <?php | ||
| /** | ||
| * Copyright 2016-2018, Optimizely | ||
| * Copyright 2016-2019, Optimizely | ||
| * | ||
| * Licensed under the Apache License, Version 2.0 (the "License"); | ||
| * you may not use this file except in compliance with the License. | ||
|
|
@@ -346,6 +346,25 @@ public function testIsUserInExperimentWithAudienceConditionsSetToAudienceIdStrin | |
| ); | ||
| } | ||
|
|
||
| public function testIsUserInExperimentWithUnknownAudienceId() | ||
| { | ||
| $config = new ProjectConfig(DATAFILE, $this->loggerMock, new NoOpErrorHandler()); | ||
| $experiment = $config->getExperimentFromKey('test_experiment'); | ||
|
|
||
| // Both audience Ids and audience conditions exist. Audience Ids is ignored. | ||
| $experiment->setAudienceIds([]); | ||
| $experiment->setAudienceConditions(["or", "unknown_audience_id", "7718080042"]); | ||
|
|
||
| // User qualifies for audience with ID "7718080042". | ||
| $this->assertTrue( | ||
| Validator::isUserInExperiment( | ||
| $config, | ||
| $experiment, | ||
| ['device_type' => 'iPhone', 'location' => 'San Francisco'] | ||
| ) | ||
| ); | ||
| } | ||
|
|
||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a pretty minimalist test case, but I think it's good enough. @aliabbasrizvi thoughts?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test is fine, but no way do I know that iPhone San Francisco users are in audience 7718080042. May be add more comments.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, yes, we could make it clearer that the experiment activates because the user passes the conditions for the known audience |
||
| // test that isUserInExperiment evaluates simple audience. | ||
| public function testIsUserInExperimentWithSimpleAudience() | ||
| { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I will keep the previous behavior.