Skip to content

Store either "someexp" or "-someexp" in cookie, never both. #6762

Merged
lannka merged 4 commits intoampproject:masterfrom
lannka:cookie-flag-dedup
Dec 20, 2016
Merged

Store either "someexp" or "-someexp" in cookie, never both. #6762
lannka merged 4 commits intoampproject:masterfrom
lannka:cookie-flag-dedup

Conversation

@lannka
Copy link
Copy Markdown
Contributor

@lannka lannka commented Dec 20, 2016

This is to fix the duplicated experiment entries in cookie as mentioned here .

It's done by deserializing the experiment cookie into an object instead of an array:
AMP_EXP=e1,-e2,e3 =>

{
  e1: true,
  e2: false,
  e3: true,
}

…o fix the duplicated experiment entries in cookie.
* @visibleForTesting
*/
function getExperimentIds(win) {
export function getExperimentTogglesFromCookie(win) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Lately, I've been directing to keep the original method private to the module, but instead creating a specifically test method, e.g.

function getExperimentTogglesFromCookie(win) {
  ...
 ..
  ..
}

export function getExperimentToglesFromCookieForTesting(win) {
  return getExperimentTogglesFromCookie(win);
}

"xForTesting" methods are stripped, so we get a better protection.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

sounds cool. done.

toggles[experimentId] = true;
} else {
experimentIds.splice(experimentIds.indexOf(experimentId), 1);
toggles[experimentId] = false;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@zhouyx this should fix the bug

toggles[experimentId] = on;

const cookieToggles = getExperimentTogglesFromCookie(win);
cookieToggles[experimentId] = on;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This means opt_transientExperiment stores could be persisted if anything after it persists.

if (cookieFlag) {
return true;
if (cookieToggles[experimentId] !== undefined) {
return cookieToggles[experimentId];
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This won't reflect transient experiment toggles, now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

as talked offline, it works fine. I added a test to prove.

@lannka lannka merged commit 61442ba into ampproject:master Dec 20, 2016
@lannka lannka deleted the cookie-flag-dedup branch December 20, 2016 22:23
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
…ct#6762)

* Store either "someexp" or "-someexp" in cookie, never both. This is to fix the duplicated experiment entries in cookie.

* Fixes a bug related to opt_transient . Adds a test for it.

* Added one more test for transient.

* Export a xforTesting function instead of the original function.
Lith pushed a commit to Lith/amphtml that referenced this pull request Dec 22, 2016
…ct#6762)

* Store either "someexp" or "-someexp" in cookie, never both. This is to fix the duplicated experiment entries in cookie.

* Fixes a bug related to opt_transient . Adds a test for it.

* Added one more test for transient.

* Export a xforTesting function instead of the original function.
torch2424 pushed a commit to torch2424/amphtml that referenced this pull request Jan 3, 2017
…ct#6762)

* Store either "someexp" or "-someexp" in cookie, never both. This is to fix the duplicated experiment entries in cookie.

* Fixes a bug related to opt_transient . Adds a test for it.

* Added one more test for transient.

* Export a xforTesting function instead of the original function.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants