Skip to content

Commit

Permalink
Call the correct API to determine if a user is in treatment or contro…
Browse files Browse the repository at this point in the history
…l group (#20690)

Closes #20183
  • Loading branch information
Kartik Raj committed Feb 13, 2023
1 parent b0ab10d commit 2202fbe
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
9 changes: 0 additions & 9 deletions .github/workflows/pr-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,6 @@ jobs:
working-directory: ${{ env.special-working-directory }}
if: matrix.test-suite == 'single-workspace'

- name: Run multi-workspace tests
env:
CI_PYTHON_VERSION: ${{ matrix.python }}
uses: GabrielBB/[email protected]
with:
run: npm run testMultiWorkspace
working-directory: ${{ env.special-working-directory }}
if: matrix.test-suite == 'multi-workspace'

- name: Run debugger tests
env:
CI_PYTHON_VERSION: ${{ matrix.python }}
Expand Down
2 changes: 1 addition & 1 deletion src/client/common/experiments/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ export class ExperimentService implements IExperimentService {
// it means that the value for this experiment was not found on the server.
const treatmentVariable = this.experimentationService.getTreatmentVariable(EXP_CONFIG_ID, experiment);

return treatmentVariable !== undefined;
return treatmentVariable === true;
}

public async getExperimentValue<T extends boolean | number | string>(experiment: string): Promise<T | undefined> {
Expand Down
33 changes: 32 additions & 1 deletion src/test/common/experiments/service.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ suite('Experimentation service', () => {
telemetryEvents.push(telemetry);
});

getTreatmentVariable = sinon.stub().returns(Promise.resolve(true));
getTreatmentVariable = sinon.stub().returns(true);
sinon.stub(tasClient, 'getExperimentationService').returns(({
getTreatmentVariable,
} as unknown) as tasClient.IExperimentationService);
Expand Down Expand Up @@ -205,6 +205,37 @@ suite('Experimentation service', () => {
sinon.assert.calledOnce(getTreatmentVariable);
});

test('If in control group, return false', async () => {
sinon.restore();
sendTelemetryEventStub = sinon
.stub(Telemetry, 'sendTelemetryEvent')
.callsFake((eventName: string, _, properties: unknown) => {
const telemetry = { eventName, properties };
telemetryEvents.push(telemetry);
});

// Control group returns false.
getTreatmentVariable = sinon.stub().returns(false);
sinon.stub(tasClient, 'getExperimentationService').returns(({
getTreatmentVariable,
} as unknown) as tasClient.IExperimentationService);

configureApplicationEnvironment('stable', extensionVersion);

configureSettings(true, [], []);

const experimentService = new ExperimentService(
instance(workspaceService),
instance(appEnvironment),
instance(stateFactory),
);
const result = experimentService.inExperimentSync(experiment);

assert.isFalse(result);
sinon.assert.notCalled(sendTelemetryEventStub);
sinon.assert.calledOnce(getTreatmentVariable);
});

test('If the experiment setting is disabled, inExperiment should return false', async () => {
configureSettings(false, [], []);

Expand Down

0 comments on commit 2202fbe

Please sign in to comment.