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

feat(experiments): Add experiments support in fxa-shared #3183

Merged
merged 1 commit into from
Oct 30, 2019

Conversation

vbudhram
Copy link
Contributor

Connect with #3170

Unfortunately, I was not able to 100% move the base experiment in content-server over to our fxa-shared project. Please see the linked issue for the different things I tried.

To spare my sanity I opted to update the experiment file to typecript and pull over the same tests from content-server.

This should be enough for me to build out the experiment parts needed in the auth-server and finish #2595.

*/
public hash(key: string): number {
// md5 returns 32 hex bytes, we want 32 bits. 32bits = 8 hex bytes.
const hash = md5(`${this.name || ''}:${key}`).substr(0, 8);
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: since the name member has a default of empty string, || '' isn't necessary here.

describe('hash', () => {
it('returns a 32 bit hash', () => {
const hashes = new Array(ITERATIONS);
for (var i = 0; i < ITERATIONS; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: s/var/let/g ?

Comment on lines 101 to 104
const leeway = Math.floor(ITERATIONS * (LEEWAY_PERCENTAGE / 100));
const fiftyPercent = Math.round(ITERATIONS / 2);
const min = fiftyPercent - leeway;
const max = fiftyPercent + leeway;
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: These lines are repeated a few times.

Comment on lines +127 to +125
experiment.name = 'oldExperiment';
experiment.deprecated = true;
Copy link
Contributor

Choose a reason for hiding this comment

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

name and deprecated are private members. Can they be assigned this way?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've updated them to be public. Typescript didn't complain but don't think this will hurt?

Copy link
Contributor

Choose a reason for hiding this comment

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

Typescript didn't complain

I'm guessing it's a compile time check and the test files don't go through the compiler at all.


const GROUPS = ['control', 'treatment'];
return this.uniformChoice(GROUPS, subject.uuid);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: from looking at this impl, choose either returns false or a string? Could add that the method declaration in the base class.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

TIL that typescript has union types. Allows function to return boolean or string.

}
}

function checkExperimentDistribution(name, experiment) {
Copy link
Contributor

Choose a reason for hiding this comment

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

An arrow function would make this more consistent with the rest of the file.

@vbudhram
Copy link
Contributor Author

@chenba Thanks for taking a look at this, I've made the updates your recommended.

@vbudhram vbudhram added this to the Train 150: FxA milestone Oct 30, 2019
@vbudhram vbudhram merged commit cff35c3 into master Oct 30, 2019
@vbudhram vbudhram deleted the add-experiments-support branch November 20, 2019 16:06
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.

None yet

2 participants