Skip to content

refact: return decide reasons instead of appending to a reference parameter #221

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

Merged
merged 12 commits into from
Jan 8, 2021

Conversation

oakbani
Copy link
Contributor

@oakbani oakbani commented Dec 17, 2020

Summary

This PR refactors the way we collect logs for decideReasons. Previously, an array was being passed as reference to each method and each method appended it's log in the passed array. Now, each method returns it's logs along with it's response.

Test plan

  • Modified Unit Tests.
  • All existing checks should pass.

Issues

@coveralls
Copy link

coveralls commented Dec 17, 2020

Coverage Status

Coverage increased (+0.03%) to 97.608% when pulling db2b10e on oakbani/reasons-n-context into 7ebb702 on oakbani/decide-api.

@oakbani oakbani marked this pull request as ready for review December 17, 2020 12:56
@oakbani oakbani requested a review from a team as a code owner December 17, 2020 12:56
@oakbani oakbani removed their assignment Dec 17, 2020
@oakbani oakbani requested a review from jaeopt December 17, 2020 12:57
Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

It looks good!
Can we add a few more tests validating reasons collecting for decision hierarchical paths. No need for validating all messages.

}

$userExperimentId = $this->findBucket($bucketingId, $userId, $group->getId(), $group->getTrafficAllocation());
Copy link
Contributor

Choose a reason for hiding this comment

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

Did we have a bug before? "reasons" were not passed down? :)

@@ -599,23 +611,23 @@ public function testGetVariationUserWithSetForcedVariation()
$optlyObject->activate($experimentKey, $userId, $userAttributes);

// confirm normal bucketing occurs before setting the forced variation
$forcedVariationKey = $optlyObject->getVariation($experimentKey, $userId, $userAttributes);
$forcedVariationKey = $optlyObject->getVariation($experimentKey, $userId, $userAttributes);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: remove space

Comment on lines 605 to 630
// test valid experiment
$this->assertTrue($optlyObject->setForcedVariation($experimentKey, $userId, $forcedVariationKey), sprintf('Set variation to "%s" failed.', $forcedVariationKey));
$forcedVariationKey = $optlyObject->getVariation($experimentKey, $userId, $userAttributes);
$this->assertEquals($forcedVariationKey, $forcedVariationKey);
// // test valid experiment
// $this->assertTrue($optlyObject->setForcedVariation($experimentKey, $userId, $forcedVariationKey), sprintf('Set variation to "%s" failed.', $forcedVariationKey));
// $forcedVariationKey = $optlyObject->getVariation($experimentKey, $userId, $userAttributes);
// $this->assertEquals($forcedVariationKey, $forcedVariationKey);

// clear forced variation and confirm that normal bucketing occurs
$this->assertTrue($optlyObject->setForcedVariation($experimentKey, $userId, null), sprintf('Set variation to "%s" failed.', $forcedVariationKey));
$forcedVariationKey = $optlyObject->getVariation($experimentKey, $userId, $userAttributes);
$this->assertEquals($bucketedVariationKey, $forcedVariationKey);
// // clear forced variation and confirm that normal bucketing occurs
// $this->assertTrue($optlyObject->setForcedVariation($experimentKey, $userId, null), sprintf('Set variation to "%s" failed.', $forcedVariationKey));
// $forcedVariationKey = $optlyObject->getVariation($experimentKey, $userId, $userAttributes);
// $this->assertEquals($bucketedVariationKey, $forcedVariationKey);

// check that a paused experiment returns null
$this->assertTrue($optlyObject->setForcedVariation($pausedExperimentKey, $userId, 'variation'), sprintf('Set variation to "%s" failed.', $forcedVariationKey));
$forcedVariationKey = $optlyObject->getVariation($pausedExperimentKey, $userId, $userAttributes);
$this->assertNull($forcedVariationKey);
// // check that a paused experiment returns null
// $this->assertTrue($optlyObject->setForcedVariation($pausedExperimentKey, $userId, 'variation'), sprintf('Set variation to "%s" failed.', $forcedVariationKey));
// $forcedVariationKey = $optlyObject->getVariation($pausedExperimentKey, $userId, $userAttributes);
// $this->assertNull($forcedVariationKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why these tests commented out? Intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nice catch. Probably was trying to test something and forgot to revert it.

Copy link
Contributor

@jaeopt jaeopt left a comment

Choose a reason for hiding this comment

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

LGTM

@oakbani oakbani merged commit c319f7a into oakbani/decide-api Jan 8, 2021
@oakbani oakbani deleted the oakbani/reasons-n-context branch January 8, 2021 13:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants