Skip to content

User cannot belong to all experiments in an experiment group #11945

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 2 commits into from
May 21, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions news/2 Fixes/11943.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Ensure user cannot belong to all experiments in an experiment group.
12 changes: 10 additions & 2 deletions src/client/common/experiments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,8 @@ export class ExperimentsManager implements IExperimentsManager {
public populateUserExperiments(): void {
this.cleanUpExperimentsOptList();
if (Array.isArray(this.experimentStorage.value)) {
const remainingExpriments: ABExperiments = [];
// First process experiments in order of user preference (if they have opted out or opted in).
for (const experiment of this.experimentStorage.value) {
// User cannot belong to NotebookExperiment if they are not using Insiders.
if (
Expand All @@ -176,13 +178,19 @@ export class ExperimentsManager implements IExperimentsManager {
expNameOptedInto: experiment.name
});
this.userExperiments.push(experiment);
} else if (this.isUserInRange(experiment.min, experiment.max, experiment.salt)) {
this.userExperiments.push(experiment);
} else {
remainingExpriments.push(experiment);
}
} catch (ex) {
traceError(`Failed to populate experiment list for experiment '${experiment.name}'`, ex);
}
}

// Add users (based on algorithm) to experiments they haven't already opted out of or opted into.
remainingExpriments
.filter((experiment) => this.isUserInRange(experiment.min, experiment.max, experiment.salt))
.filter((experiment) => !this.userExperiments.some((existing) => existing.salt === experiment.salt))
.forEach((experiment) => this.userExperiments.push(experiment));
}
}

Expand Down
11 changes: 11 additions & 0 deletions src/test/common/experiments.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -841,6 +841,17 @@ suite('A/B experiments', () => {
experimentsOptedInto: ['experiment1'],
expectedResult: [{ name: 'experiment1', salt: 'salt', min: 79, max: 94 }]
},
{
testName:
'User experiments list contains the experiment user has opened into and not the control experiment even if user is in the control experiment range',
experimentStorageValue: [
{ name: 'control', salt: 'salt', min: 0, max: 100 },
{ name: 'experiment', salt: 'salt', min: 0, max: 0 }
],
hash: 8187,
experimentsOptedInto: ['experiment'],
expectedResult: [{ name: 'experiment', salt: 'salt', min: 0, max: 0 }]
},
{
testName:
'User experiments list does not contain the experiment if user has both opted in and out of an experiment',
Expand Down