Skip to content

Commit b55b67a

Browse files
committed
Revert "Add launched state check (#44)"
This reverts commit 7bf5e30.
1 parent 7bf5e30 commit b55b67a

File tree

5 files changed

+22
-144
lines changed

5 files changed

+22
-144
lines changed

src/Optimizely/Entity/Experiment.php

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,6 @@ class Experiment
2626
*/
2727
const STATUS_RUNNING = 'Running';
2828

29-
/**
30-
* @const string String denoting launched state of the experiment.
31-
*/
32-
const STATUS_LAUNCHED = 'Launched';
33-
3429
/**
3530
* @const string String denoting policy of mutually exclusive group.
3631
*/
@@ -290,15 +285,6 @@ public function isExperimentRunning()
290285
return !is_null($this->_status) && $this->_status == self::STATUS_RUNNING;
291286
}
292287

293-
/**
294-
* Determine if experiment is in launched state or not.
295-
*
296-
* @return boolean True if experiment has status "Launched". False otherwise.
297-
*/
298-
public function isExperimentLaunched() {
299-
return !is_null($this->_status) && $this->_status == self::STATUS_LAUNCHED;
300-
}
301-
302288
/**
303289
* Determine if user is in forced variation of experiment.
304290
*

src/Optimizely/Optimizely.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private function validatePreconditions($experiment, $userId, $attributes)
152152
return false;
153153
}
154154

155-
if (!$experiment->isExperimentRunning() && !$experiment->isExperimentLaunched()) {
155+
if (!$experiment->isExperimentRunning()) {
156156
$this->_logger->log(Logger::INFO, sprintf('Experiment "%s" is not running.', $experiment->getKey()));
157157
return false;
158158
}
@@ -204,14 +204,8 @@ private function getValidExperimentsForEvent($event, $userId, $attributes = null
204204
forEach ($event->getExperimentIds() as $experimentId) {
205205
$experiment = $this->_config->getExperimentFromId($experimentId);
206206
$experimentKey = $experiment->getKey();
207-
208-
// Do not track events for experiment if it is in "Launched" state.
209-
if ($experiment->isExperimentLaunched()) {
210-
$this->_logger->log(Logger::DEBUG, sprintf('Experiment %s is in "Launched" state. Not tracking user for it.', $experimentKey));
211-
continue;
212-
}
213-
214207
$variationKey = $this->getVariation($experimentKey, $userId, $attributes);
208+
215209
if (is_null($variationKey)) {
216210
$this->_logger->log(Logger::INFO, sprintf('Not tracking user "%s" for experiment "%s".',
217211
$userId, $experimentKey));
@@ -247,17 +241,9 @@ public function activate($experimentKey, $userId, $attributes = null)
247241
return $variationKey;
248242
}
249243

250-
$this->_logger->log(Logger::INFO, sprintf('Activating user "%s" in experiment "%s".', $userId, $experimentKey));
251-
252-
// Do not send impression event for experiment if it is in "Launched" state.
253-
$experiment = $this->_config->getExperimentFromKey($experimentKey);
254-
if ($experiment->isExperimentLaunched()) {
255-
$this->_logger->log(Logger::DEBUG, sprintf('Experiment %s is in "Launched" state. Not dispatching impression event.', $experimentKey));
256-
return $variationKey;
257-
}
258-
259244
$impressionEvent = $this->_eventBuilder
260245
->createImpressionEvent($this->_config, $experimentKey, $variationKey, $userId, $attributes);
246+
$this->_logger->log(Logger::INFO, sprintf('Activating user "%s" in experiment "%s".', $userId, $experimentKey));
261247
$this->_logger->log(
262248
Logger::DEBUG,
263249
sprintf('Dispatching impression event to URL %s with params %s.',

tests/OptimizelyTest.php

Lines changed: 1 addition & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
use TypeError;
2828
use Optimizely\ErrorHandler\DefaultErrorHandler;
2929
use Optimizely\Event\Builder\EventBuilder;
30-
use Optimizely\Event\Dispatcher\DefaultEventDispatcher;
3130
use Optimizely\Logger\DefaultLogger;
3231
use Optimizely\Optimizely;
3332

@@ -36,7 +35,6 @@ class OptimizelyTest extends \PHPUnit_Framework_TestCase
3635
{
3736
private $datafile;
3837
private $eventBuilderMock;
39-
private $eventDispatcherMock;
4038
private $loggerMock;
4139
private $optimizelyObject;
4240
private $projectConfig;
@@ -49,13 +47,7 @@ public function setUp()
4947
$this->loggerMock = $this->getMockBuilder(NoOpLogger::class)
5048
->setMethods(array('log'))
5149
->getMock();
52-
53-
// Mock Event Dispatcher
54-
$this->eventDispatcherMock = $this->getMockBuilder(DefaultEventDispatcher::class)
55-
->setMethods(array('dispatchEvent'))
56-
->getMock();
57-
58-
$this->optimizelyObject = new Optimizely($this->datafile, $this->eventDispatcherMock, $this->loggerMock);
50+
$this->optimizelyObject = new Optimizely($this->datafile, null, $this->loggerMock);
5951

6052
$this->projectConfig = new ProjectConfig($this->datafile, $this->loggerMock, new NoOpErrorHandler());
6153

@@ -403,36 +395,6 @@ public function testActivateExperimentNotRunning()
403395
$this->assertNull($optlyObject->activate('paused_experiment', 'test_user', null));
404396
}
405397

406-
public function testActivateExperimentLaunched()
407-
{
408-
$this->loggerMock->expects($this->exactly(4))
409-
->method('log');
410-
$this->loggerMock->expects($this->at(0))
411-
->method('log')
412-
->with(Logger::DEBUG, 'Assigned bucket 6329 to user "test_user".');
413-
$this->loggerMock->expects($this->at(1))
414-
->method('log')
415-
->with(Logger::INFO,
416-
'User "test_user" is in variation variation of experiment launched_experiment.');
417-
$this->loggerMock->expects($this->at(2))
418-
->method('log')
419-
->with(Logger::INFO, 'Activating user "test_user" in experiment "launched_experiment".');
420-
$this->loggerMock->expects($this->at(3))
421-
->method('log')
422-
->with(Logger::DEBUG,
423-
'Experiment launched_experiment is in "Launched" state. Not dispatching impression event.');
424-
425-
// Launched experiments don't send impressions
426-
$this->eventDispatcherMock->expects($this->never())
427-
->method('dispatchEvent');
428-
429-
// Call activate
430-
$this->assertEquals(
431-
'variation',
432-
$this->optimizelyObject->activate('launched_experiment', 'test_user')
433-
);
434-
}
435-
436398
public function testGetVariationInvalidOptimizelyObject()
437399
{
438400
$optlyObject = new Optimizely('Random datafile');
@@ -501,23 +463,6 @@ public function testGetVariationExperimentNotRunning()
501463
$this->assertNull($this->optimizelyObject->getVariation('paused_experiment', 'test_user'));
502464
}
503465

504-
public function testGetVariationExperimentLaunched() {
505-
$this->loggerMock->expects($this->exactly(2))
506-
->method('log');
507-
$this->loggerMock->expects($this->at(0))
508-
->method('log')
509-
->with(Logger::DEBUG, 'Assigned bucket 6329 to user "test_user".');
510-
$this->loggerMock->expects($this->at(1))
511-
->method('log')
512-
->with(Logger::INFO,
513-
'User "test_user" is in variation variation of experiment launched_experiment.');
514-
515-
$this->assertEquals(
516-
'variation',
517-
$this->optimizelyObject->getVariation('launched_experiment', 'test_user')
518-
);
519-
}
520-
521466
public function testGetVariationUserInForcedVariationInExperiment()
522467
{
523468
$this->loggerMock->expects($this->exactly(1))
@@ -1182,25 +1127,4 @@ public function testTrackWithAttributesWithEventValue()
11821127
// Call track
11831128
$optlyObject->track('purchase', 'test_user', $userAttributes, array('revenue' => 42));
11841129
}
1185-
1186-
public function testTrackExperimentLaunched()
1187-
{
1188-
$callIndex = 0;
1189-
$this->loggerMock->expects($this->exactly(2))
1190-
->method('log');
1191-
$this->loggerMock->expects($this->at($callIndex++))
1192-
->method('log')
1193-
->with(Logger::DEBUG,
1194-
'Experiment launched_experiment is in "Launched" state. Not tracking user for it.');
1195-
$this->loggerMock->expects($this->at($callIndex++))
1196-
->method('log')
1197-
->with(Logger::INFO,
1198-
'There are no valid experiments for event "click" to track.');
1199-
1200-
// Launched experiments don't send impressions
1201-
$this->eventDispatcherMock->expects($this->never())
1202-
->method('dispatchEvent');
1203-
1204-
$this->optimizelyObject->track('click', 'test_user');
1205-
}
12061130
}

tests/ProjectConfigTest.php

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,7 @@ public function testInit()
9191
'test_experiment' => $this->config->getExperimentFromKey('test_experiment'),
9292
'paused_experiment' => $this->config->getExperimentFromKey('paused_experiment'),
9393
'group_experiment_1' => $this->config->getExperimentFromKey('group_experiment_1'),
94-
'group_experiment_2' => $this->config->getExperimentFromKey('group_experiment_2'),
95-
'launched_experiment' => $this->config->getExperimentFromKey('launched_experiment')
94+
'group_experiment_2' => $this->config->getExperimentFromKey('group_experiment_2')
9695
], $experimentKeyMap->getValue($this->config));
9796

9897
// Check experiment ID map
@@ -102,16 +101,14 @@ public function testInit()
102101
'7716830082' => $this->config->getExperimentFromId('7716830082'),
103102
'7723330021' => $this->config->getExperimentFromId('7723330021'),
104103
'7718750065' => $this->config->getExperimentFromId('7718750065'),
105-
'7716830585' => $this->config->getExperimentFromId('7716830585'),
106-
'7716830586' => $this->config->getExperimentFromId('7716830586')
104+
'7716830585' => $this->config->getExperimentFromId('7716830585')
107105
], $experimentIdMap->getValue($this->config));
108106

109107
// Check event key map
110108
$eventKeyMap = new \ReflectionProperty(ProjectConfig::class, '_eventKeyMap');
111109
$eventKeyMap->setAccessible(true);
112110
$this->assertEquals([
113-
'purchase' => $this->config->getEvent('purchase'),
114-
'click' => $this->config->getEvent('click')
111+
'purchase' => $this->config->getEvent('purchase')
115112
], $eventKeyMap->getValue($this->config));
116113

117114
// Check attribute key map
@@ -148,10 +145,6 @@ public function testInit()
148145
'group_experiment_2' => [
149146
'group_exp_2_var_1' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_1'),
150147
'group_exp_2_var_2' => $this->config->getVariationFromKey('group_experiment_2', 'group_exp_2_var_2')
151-
],
152-
'launched_experiment' => [
153-
'control' => $this->config->getVariationFromKey('launched_experiment', 'control'),
154-
'variation' => $this->config->getVariationFromKey('launched_experiment', 'variation')
155148
]
156149
], $variationKeyMap->getValue($this->config));
157150

@@ -174,10 +167,6 @@ public function testInit()
174167
'group_experiment_2' => [
175168
'7713030086' => $this->config->getVariationFromId('group_experiment_2', '7713030086'),
176169
'7725250007' => $this->config->getVariationFromId('group_experiment_2', '7725250007')
177-
],
178-
'launched_experiment' => [
179-
'7722370428' => $this->config->getVariationFromId('launched_experiment', '7722370428'),
180-
'7721010510' => $this->config->getVariationFromId('launched_experiment', '7721010510')
181170
]
182171
], $variationIdMap->getValue($this->config));
183172
}

tests/TestData.php

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,21 @@
2222
use Optimizely\Event\LogEvent;
2323

2424
define('DATAFILE',
25-
'{"experiments": [{"status": "Running", "key": "test_experiment", "layerId": "7719770039",
26-
"trafficAllocation": [{"entityId": "", "endOfRange": 1500}, {"entityId": "7722370027", "endOfRange": 4000},
27-
{"entityId": "7721010009", "endOfRange": 8000}], "audienceIds": ["7718080042"],
28-
"variations": [{"id": "7722370027", "key": "control"}, {"id": "7721010009", "key": "variation"}],
29-
"forcedVariations": {"user1": "control"}, "id": "7716830082"},
30-
{"status": "Paused", "key": "paused_experiment", "layerId": "7719779139",
31-
"trafficAllocation": [{"entityId": "7722370427", "endOfRange": 5000},
32-
{"entityId": "7721010509", "endOfRange": 8000}], "audienceIds": [],
33-
"variations": [{"id": "7722370427", "key": "control"}, {"id": "7721010509", "key": "variation"}],
34-
"forcedVariations": {}, "id": "7716830585"},
35-
{"status": "Launched", "key": "launched_experiment", "layerId": "7719779140",
36-
"trafficAllocation": [{"entityId": "7722370428", "endOfRange": 5000},
37-
{"entityId": "7721010510", "endOfRange": 8000}], "audienceIds": [],
38-
"variations": [{"id": "7722370428", "key": "control"}, {"id": "7721010510", "key": "variation"}],
39-
"forcedVariations": {}, "id": "7716830586"}], "version": "2",
40-
"audiences": [{"conditions": "[\"and\", [\"or\", [\"or\", {\"name\": \"device_type\", \"type\": \"custom_attribute\", \"value\": \"iPhone\"}]], [\"or\", [\"or\", {\"name\": \"location\", \"type\": \"custom_attribute\", \"value\": \"San Francisco\"}]]]", "id": "7718080042", "name": "iPhone users in San Francisco"}],
41-
"groups": [{"policy": "random", "trafficAllocation": [{"entityId": "", "endOfRange": 500}, {"entityId": "7723330021", "endOfRange": 2000}, {"entityId": "7718750065", "endOfRange": 6000}], "experiments": [{"status": "Running", "key": "group_experiment_1", "layerId": "7721010011", "trafficAllocation": [{"entityId": "7722260071", "endOfRange": 5000}, {"entityId": "7722360022", "endOfRange": 10000}], "audienceIds": [], "variations": [{"id": "7722260071", "key": "group_exp_1_var_1"}, {"id": "7722360022", "key": "group_exp_1_var_2"}], "forcedVariations": {"user1": "group_exp_1_var_1"}, "id": "7723330021"}, {"status": "Running", "key": "group_experiment_2", "layerId": "7721020020", "trafficAllocation": [{"entityId": "7713030086", "endOfRange": 5000}, {"entityId": "7725250007", "endOfRange": 10000}], "audienceIds": [],
42-
"variations": [{"id": "7713030086", "key": "group_exp_2_var_1"}, {"id": "7725250007", "key": "group_exp_2_var_2"}], "forcedVariations": {}, "id": "7718750065"}], "id": "7722400015"}],
43-
"attributes": [{"id": "7723280020", "key": "device_type"}, {"id": "7723340004", "key": "location"}],
44-
"projectId": "7720880029", "accountId": "1592310167",
45-
"events": [{"experimentIds": ["7716830082", "7723330021", "7718750065", "7716830585"], "id": "7718020063", "key": "purchase"},
46-
{"experimentIds": ["7716830586"], "id": "7718020064", "key": "click"}],
25+
'{"experiments": [{"status": "Running", "key": "test_experiment", "layerId": "7719770039",
26+
"trafficAllocation": [{"entityId": "", "endOfRange": 1500}, {"entityId": "7722370027", "endOfRange": 4000},
27+
{"entityId": "7721010009", "endOfRange": 8000}], "audienceIds": ["7718080042"],
28+
"variations": [{"id": "7722370027", "key": "control"}, {"id": "7721010009", "key": "variation"}],
29+
"forcedVariations": {"user1": "control"}, "id": "7716830082"}, {"status": "Paused", "key": "paused_experiment", "layerId": "7719779139",
30+
"trafficAllocation": [{"entityId": "7722370427", "endOfRange": 5000},
31+
{"entityId": "7721010509", "endOfRange": 8000}], "audienceIds": [],
32+
"variations": [{"id": "7722370427", "key": "control"}, {"id": "7721010509", "key": "variation"}],
33+
"forcedVariations": {}, "id": "7716830585"}], "version": "2",
34+
"audiences": [{"conditions": "[\"and\", [\"or\", [\"or\", {\"name\": \"device_type\", \"type\": \"custom_attribute\", \"value\": \"iPhone\"}]], [\"or\", [\"or\", {\"name\": \"location\", \"type\": \"custom_attribute\", \"value\": \"San Francisco\"}]]]", "id": "7718080042", "name": "iPhone users in San Francisco"}],
35+
"groups": [{"policy": "random", "trafficAllocation": [{"entityId": "", "endOfRange": 500}, {"entityId": "7723330021", "endOfRange": 2000}, {"entityId": "7718750065", "endOfRange": 6000}], "experiments": [{"status": "Running", "key": "group_experiment_1", "layerId": "7721010011", "trafficAllocation": [{"entityId": "7722260071", "endOfRange": 5000}, {"entityId": "7722360022", "endOfRange": 10000}], "audienceIds": [], "variations": [{"id": "7722260071", "key": "group_exp_1_var_1"}, {"id": "7722360022", "key": "group_exp_1_var_2"}], "forcedVariations": {"user1": "group_exp_1_var_1"}, "id": "7723330021"}, {"status": "Running", "key": "group_experiment_2", "layerId": "7721020020", "trafficAllocation": [{"entityId": "7713030086", "endOfRange": 5000}, {"entityId": "7725250007", "endOfRange": 10000}], "audienceIds": [],
36+
"variations": [{"id": "7713030086", "key": "group_exp_2_var_1"}, {"id": "7725250007", "key": "group_exp_2_var_2"}], "forcedVariations": {}, "id": "7718750065"}], "id": "7722400015"}],
37+
"attributes": [{"id": "7723280020", "key": "device_type"}, {"id": "7723340004", "key": "location"}],
38+
"projectId": "7720880029", "accountId": "1592310167",
39+
"events": [{"experimentIds": ["7716830082", "7723330021", "7718750065", "7716830585"], "id": "7718020063", "key": "purchase"}],
4740
"revision": "15"}');
4841

4942
define('DATAFILE_V3',

0 commit comments

Comments
 (0)