зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1754527 - Nimbus should call the Glean Experiment API r=chutten,barret
Differential Revision: https://phabricator.services.mozilla.com/D145911
This commit is contained in:
Родитель
98817e34d7
Коммит
07ed5a1efc
|
@ -416,6 +416,8 @@ class _ExperimentManager {
|
|||
}
|
||||
|
||||
TelemetryEnvironment.setExperimentInactive(slug);
|
||||
// We also need to set the experiment inactive in the Glean Experiment API
|
||||
Services.fog.setExperimentInactive(slug);
|
||||
this.store.updateExperiment(slug, { active: false });
|
||||
|
||||
TelemetryEvents.sendEvent("unenroll", TELEMETRY_EVENT_OBJECT, slug, {
|
||||
|
@ -483,6 +485,12 @@ class _ExperimentManager {
|
|||
experiment.enrollmentId || TelemetryEvents.NO_ENROLLMENT_ID_MARKER,
|
||||
}
|
||||
);
|
||||
// Report the experiment to the Glean Experiment API
|
||||
Services.fog.setExperimentActive(experiment.slug, experiment.branch.slug, {
|
||||
type: `${TELEMETRY_EXPERIMENT_ACTIVE_PREFIX}${experiment.experimentType}`,
|
||||
enrollmentId:
|
||||
experiment.enrollmentId || TelemetryEvents.NO_ENROLLMENT_ID_MARKER,
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -209,6 +209,18 @@ add_task(async function test_remote_fetch_and_ready() {
|
|||
"should call setExperimentActive with `bar` feature"
|
||||
);
|
||||
|
||||
// Test Glean experiment API interaction
|
||||
Assert.equal(
|
||||
Services.fog.testGetExperimentData(REMOTE_CONFIGURATION_FOO.slug).branch,
|
||||
REMOTE_CONFIGURATION_FOO.branches[0].slug,
|
||||
"Glean.setExperimentActive called with `foo` feature"
|
||||
);
|
||||
Assert.equal(
|
||||
Services.fog.testGetExperimentData(REMOTE_CONFIGURATION_BAR.slug).branch,
|
||||
REMOTE_CONFIGURATION_BAR.branches[0].slug,
|
||||
"Glean.setExperimentActive called with `bar` feature"
|
||||
);
|
||||
|
||||
Assert.equal(fooInstance.getVariable("remoteValue"), 42, "Has rollout value");
|
||||
Assert.equal(barInstance.getVariable("remoteValue"), 3, "Has rollout value");
|
||||
|
||||
|
|
|
@ -32,6 +32,17 @@ registerCleanupFunction(() => {
|
|||
globalSandbox.restore();
|
||||
});
|
||||
|
||||
/**
|
||||
* FOG requires a little setup in order to test it
|
||||
*/
|
||||
add_setup(function test_setup() {
|
||||
// FOG needs a profile directory to put its data in.
|
||||
do_get_profile();
|
||||
|
||||
// FOG needs to be initialized in order for data to flow.
|
||||
Services.fog.initializeFOG();
|
||||
});
|
||||
|
||||
/**
|
||||
* The normal case: Enrollment of a new experiment
|
||||
*/
|
||||
|
@ -111,6 +122,13 @@ add_task(
|
|||
|
||||
await manager.onStartup();
|
||||
|
||||
// Ensure there is no experiment active with the id in FOG
|
||||
Assert.equal(
|
||||
undefined,
|
||||
Services.fog.testGetExperimentData("foo"),
|
||||
"no active experiment exists before enrollment"
|
||||
);
|
||||
|
||||
await manager.enroll(
|
||||
ExperimentFakes.recipe("foo"),
|
||||
"test_setExperimentActive_sendEnrollmentTelemetry_called"
|
||||
|
@ -130,6 +148,13 @@ add_task(
|
|||
"should call sendEnrollmentTelemetry after an enrollment"
|
||||
);
|
||||
|
||||
// Test Glean experiment API interaction
|
||||
Assert.notEqual(
|
||||
undefined,
|
||||
Services.fog.testGetExperimentData(experiment.slug),
|
||||
"Glean.setExperimentActive called with `foo` feature"
|
||||
);
|
||||
|
||||
manager.unenroll("foo", "test-cleanup");
|
||||
}
|
||||
);
|
||||
|
@ -153,6 +178,13 @@ add_task(async function test_setRolloutActive_sendEnrollmentTelemetry_called() {
|
|||
|
||||
await manager.onStartup();
|
||||
|
||||
// Test Glean experiment API interaction
|
||||
Assert.equal(
|
||||
undefined,
|
||||
Services.fog.testGetExperimentData("rollout"),
|
||||
"no rollout active before enrollment"
|
||||
);
|
||||
|
||||
let result = await manager.enroll(
|
||||
rolloutRecipe,
|
||||
"test_setRolloutActive_sendEnrollmentTelemetry_called"
|
||||
|
@ -201,6 +233,13 @@ add_task(async function test_setRolloutActive_sendEnrollmentTelemetry_called() {
|
|||
"Should send telemetry with expected values"
|
||||
);
|
||||
|
||||
// Test Glean experiment API interaction
|
||||
Assert.equal(
|
||||
enrollment.branch.slug,
|
||||
Services.fog.testGetExperimentData(enrollment.slug).branch,
|
||||
"Glean.setExperimentActive called with expected values"
|
||||
);
|
||||
|
||||
manager.unenroll("rollout", "test-cleanup");
|
||||
|
||||
globalSandbox.restore();
|
||||
|
|
|
@ -15,6 +15,17 @@ registerCleanupFunction(() => {
|
|||
globalSandbox.restore();
|
||||
});
|
||||
|
||||
/**
|
||||
* FOG requires a little setup in order to test it
|
||||
*/
|
||||
add_setup(function test_setup() {
|
||||
// FOG needs a profile directory to put its data in.
|
||||
do_get_profile();
|
||||
|
||||
// FOG needs to be initialized in order for data to flow.
|
||||
Services.fog.initializeFOG();
|
||||
});
|
||||
|
||||
/**
|
||||
* Normal unenrollment for experiments:
|
||||
* - set .active to false
|
||||
|
@ -114,12 +125,35 @@ add_task(async function test_setExperimentInactive_called() {
|
|||
await manager.onStartup();
|
||||
await manager.store.addEnrollment(experiment);
|
||||
|
||||
// Because `manager.store.addEnrollment()` sidesteps telemetry recording
|
||||
// we will also call on the Glean experiment API directly to test that
|
||||
// `manager.unenroll()` does in fact call `Glean.setExperimentActive()`
|
||||
Services.fog.setExperimentActive(
|
||||
experiment.slug,
|
||||
experiment.branch.slug,
|
||||
null
|
||||
);
|
||||
|
||||
// Test Glean experiment API interaction
|
||||
Assert.notEqual(
|
||||
undefined,
|
||||
Services.fog.testGetExperimentData(experiment.slug),
|
||||
"experiment should be active before unenroll"
|
||||
);
|
||||
|
||||
manager.unenroll("foo", "some-reason");
|
||||
|
||||
Assert.ok(
|
||||
TelemetryEnvironment.setExperimentInactive.calledWith("foo"),
|
||||
"should call TelemetryEnvironment.setExperimentInactive with slug"
|
||||
);
|
||||
|
||||
// Test Glean experiment API interaction
|
||||
Assert.equal(
|
||||
undefined,
|
||||
Services.fog.testGetExperimentData(experiment.slug),
|
||||
"experiment should be inactive after unenroll"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_send_unenroll_event() {
|
||||
|
@ -244,6 +278,12 @@ add_task(async function test_rollout_telemetry_events() {
|
|||
TelemetryEnvironment.setExperimentInactive.calledWith(rollout.slug),
|
||||
"Should set rollout to inactive."
|
||||
);
|
||||
// Test Glean experiment API interaction
|
||||
Assert.equal(
|
||||
undefined,
|
||||
Services.fog.testGetExperimentData(rollout.slug),
|
||||
"Should set rollout to inactive"
|
||||
);
|
||||
Assert.ok(
|
||||
TelemetryEvents.sendEvent.calledWith(
|
||||
"unenroll",
|
||||
|
|
Загрузка…
Ссылка в новой задаче