зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1797899 - Rename getAllActive and getAllRollouts functions. r=barret
Differential Revision: https://phabricator.services.mozilla.com/D164326
This commit is contained in:
Родитель
997b2298da
Коммит
5580274df8
|
@ -110,13 +110,13 @@ class _ExperimentManager {
|
|||
Object.defineProperty(context, "activeExperiments", {
|
||||
get: async () => {
|
||||
await this.store.ready();
|
||||
return this.store.getAllActive().map(exp => exp.slug);
|
||||
return this.store.getAllActiveExperiments().map(exp => exp.slug);
|
||||
},
|
||||
});
|
||||
Object.defineProperty(context, "activeRollouts", {
|
||||
get: async () => {
|
||||
await this.store.ready();
|
||||
return this.store.getAllRollouts().map(rollout => rollout.slug);
|
||||
return this.store.getAllActiveRollouts().map(rollout => rollout.slug);
|
||||
},
|
||||
});
|
||||
return context;
|
||||
|
@ -132,8 +132,8 @@ class _ExperimentManager {
|
|||
await this.store.init();
|
||||
this.extraContext = extraContext;
|
||||
|
||||
const restoredExperiments = this.store.getAllActive();
|
||||
const restoredRollouts = this.store.getAllRollouts();
|
||||
const restoredExperiments = this.store.getAllActiveExperiments();
|
||||
const restoredRollouts = this.store.getAllActiveRollouts();
|
||||
|
||||
for (const experiment of restoredExperiments) {
|
||||
this.setExperimentActive(experiment);
|
||||
|
@ -241,8 +241,8 @@ class _ExperimentManager {
|
|||
if (!sourceToCheck) {
|
||||
throw new Error("When calling onFinalize, you must specify a source.");
|
||||
}
|
||||
const activeExperiments = this.store.getAllActive();
|
||||
const activeRollouts = this.store.getAllRollouts();
|
||||
const activeExperiments = this.store.getAllActiveExperiments();
|
||||
const activeRollouts = this.store.getAllActiveRollouts();
|
||||
this._checkUnseenEnrollments(
|
||||
activeExperiments,
|
||||
sourceToCheck,
|
||||
|
@ -570,10 +570,10 @@ class _ExperimentManager {
|
|||
*/
|
||||
observe(aSubject, aTopic, aPrefName) {
|
||||
if (!this.studiesEnabled) {
|
||||
for (const { slug } of this.store.getAllActive()) {
|
||||
for (const { slug } of this.store.getAllActiveExperiments()) {
|
||||
this.unenroll(slug, "studies-opt-out");
|
||||
}
|
||||
for (const { slug } of this.store.getAllRollouts()) {
|
||||
for (const { slug } of this.store.getAllActiveRollouts()) {
|
||||
this.unenroll(slug, "studies-opt-out");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -244,12 +244,12 @@ class ExperimentStore extends SharedDataMap {
|
|||
async init() {
|
||||
await super.init();
|
||||
|
||||
this.getAllActive().forEach(({ branch, featureIds }) => {
|
||||
this.getAllActiveExperiments().forEach(({ branch, featureIds }) => {
|
||||
(featureIds || getAllBranchFeatureIds(branch)).forEach(featureId =>
|
||||
this._emitFeatureUpdate(featureId, "feature-experiment-loaded")
|
||||
);
|
||||
});
|
||||
this.getAllRollouts().forEach(({ featureIds }) => {
|
||||
this.getAllActiveRollouts().forEach(({ featureIds }) => {
|
||||
featureIds.forEach(featureId =>
|
||||
this._emitFeatureUpdate(featureId, "feature-rollout-loaded")
|
||||
);
|
||||
|
@ -269,7 +269,7 @@ class ExperimentStore extends SharedDataMap {
|
|||
*/
|
||||
getExperimentForFeature(featureId) {
|
||||
return (
|
||||
this.getAllActive().find(
|
||||
this.getAllActiveExperiments().find(
|
||||
experiment =>
|
||||
experiment.featureIds?.includes(featureId) ||
|
||||
// Supports <v1.3.0, which was when .featureIds was added
|
||||
|
@ -309,9 +309,10 @@ class ExperimentStore extends SharedDataMap {
|
|||
}
|
||||
|
||||
/**
|
||||
* Returns all active experiments
|
||||
* @returns {Enrollment[]}
|
||||
*/
|
||||
getAllActive() {
|
||||
getAllActiveExperiments() {
|
||||
return this.getAll().filter(
|
||||
enrollment => enrollment.active && !enrollment.isRollout
|
||||
);
|
||||
|
@ -319,9 +320,9 @@ class ExperimentStore extends SharedDataMap {
|
|||
|
||||
/**
|
||||
* Returns all active rollouts
|
||||
* @returns {array}
|
||||
* @returns {Enrollment[]}
|
||||
*/
|
||||
getAllRollouts() {
|
||||
getAllActiveRollouts() {
|
||||
return this.getAll().filter(
|
||||
enrollment => enrollment.active && enrollment.isRollout
|
||||
);
|
||||
|
@ -334,7 +335,7 @@ class ExperimentStore extends SharedDataMap {
|
|||
*/
|
||||
getRolloutForFeature(featureId) {
|
||||
return (
|
||||
this.getAllRollouts().find(r => r.featureIds.includes(featureId)) ||
|
||||
this.getAllActiveRollouts().find(r => r.featureIds.includes(featureId)) ||
|
||||
lazy.syncDataStore.getDefault(featureId)
|
||||
);
|
||||
}
|
||||
|
|
|
@ -331,7 +331,7 @@ const ExperimentFakes = {
|
|||
await promise;
|
||||
}
|
||||
|
||||
if (manager.store.getAllActive().length) {
|
||||
if (manager.store.getAllActiveExperiments().length) {
|
||||
throw new Error("Cleanup failed");
|
||||
}
|
||||
},
|
||||
|
|
|
@ -35,7 +35,10 @@ add_task(async function test_double_feature_enrollment() {
|
|||
);
|
||||
await ExperimentAPI.ready();
|
||||
|
||||
Assert.ok(ExperimentManager.store.getAllActive().length === 0, "Clean state");
|
||||
Assert.ok(
|
||||
ExperimentManager.store.getAllActiveExperiments().length === 0,
|
||||
"Clean state"
|
||||
);
|
||||
|
||||
let recipe1 = getRecipe("foo" + Math.random());
|
||||
let recipe2 = getRecipe("foo" + Math.random());
|
||||
|
@ -49,7 +52,7 @@ add_task(async function test_double_feature_enrollment() {
|
|||
ExperimentManager.enroll(recipe2, "test_double_feature_enrollment");
|
||||
|
||||
Assert.equal(
|
||||
ExperimentManager.store.getAllActive().length,
|
||||
ExperimentManager.store.getAllActiveExperiments().length,
|
||||
1,
|
||||
"1 active experiment"
|
||||
);
|
||||
|
|
|
@ -513,7 +513,7 @@ add_task(async function test_getActiveBranch() {
|
|||
|
||||
add_task(async function test_getActiveBranch_safe() {
|
||||
const sandbox = sinon.createSandbox();
|
||||
sandbox.stub(ExperimentAPI._store, "getAllActive").throws();
|
||||
sandbox.stub(ExperimentAPI._store, "getAllActiveExperiments").throws();
|
||||
|
||||
try {
|
||||
Assert.equal(
|
||||
|
@ -544,7 +544,7 @@ add_task(async function test_getActiveBranch_storeFailure() {
|
|||
// Adding stub later because `addEnrollment` emits update events
|
||||
const stub = sandbox.stub(store, "emit");
|
||||
// Call getActiveBranch to trigger an activation event
|
||||
sandbox.stub(store, "getAllActive").throws();
|
||||
sandbox.stub(store, "getAllActiveExperiments").throws();
|
||||
try {
|
||||
ExperimentAPI.getActiveBranch({ featureId: "green" });
|
||||
} catch (e) {
|
||||
|
|
|
@ -238,7 +238,7 @@ add_task(async function test_onUpdate_before_store_ready() {
|
|||
const stub = sandbox.stub();
|
||||
const manager = ExperimentFakes.manager();
|
||||
sandbox.stub(ExperimentAPI, "_store").get(() => manager.store);
|
||||
sandbox.stub(manager.store, "getAllActive").returns([
|
||||
sandbox.stub(manager.store, "getAllActiveExperiments").returns([
|
||||
ExperimentFakes.experiment("foo-experiment", {
|
||||
branch: {
|
||||
slug: "control",
|
||||
|
@ -293,7 +293,7 @@ add_task(async function test_ExperimentFeature_test_ready_late() {
|
|||
},
|
||||
});
|
||||
|
||||
sandbox.stub(manager.store, "getAllRollouts").returns([rollout]);
|
||||
sandbox.stub(manager.store, "getAllActiveRollouts").returns([rollout]);
|
||||
|
||||
await manager.onStartup();
|
||||
|
||||
|
|
|
@ -14,8 +14,8 @@ add_task(async function test_createTargetingContext() {
|
|||
const recipe = ExperimentFakes.recipe("foo");
|
||||
const rollout = ExperimentFakes.rollout("bar");
|
||||
sandbox.stub(manager.store, "ready").resolves();
|
||||
sandbox.stub(manager.store, "getAllActive").returns([recipe]);
|
||||
sandbox.stub(manager.store, "getAllRollouts").returns([rollout]);
|
||||
sandbox.stub(manager.store, "getAllActiveExperiments").returns([recipe]);
|
||||
sandbox.stub(manager.store, "getAllActiveRollouts").returns([rollout]);
|
||||
|
||||
let context = manager.createTargetingContext();
|
||||
const activeSlugs = await context.activeExperiments;
|
||||
|
|
|
@ -192,13 +192,13 @@ function assertExpectedPrefValues(pref, branch, expected, visible, msg) {
|
|||
*/
|
||||
function assertEmptyStore(store) {
|
||||
Assert.deepEqual(
|
||||
store.getAllActive(),
|
||||
store.getAllActiveExperiments(),
|
||||
[],
|
||||
"There should be no experiments active."
|
||||
);
|
||||
|
||||
Assert.deepEqual(
|
||||
store.getAllRollouts(),
|
||||
store.getAllActiveRollouts(),
|
||||
[],
|
||||
"There should be no rollouts active"
|
||||
);
|
||||
|
@ -1766,8 +1766,8 @@ add_task(async function test_prefChange() {
|
|||
);
|
||||
|
||||
const enrollments = isRollout
|
||||
? store.getAllRollouts()
|
||||
: store.getAllActive();
|
||||
? store.getAllActiveRollouts()
|
||||
: store.getAllActiveExperiments();
|
||||
|
||||
Assert.equal(
|
||||
enrollments.length,
|
||||
|
@ -2374,8 +2374,8 @@ add_task(async function test_clearUserPref() {
|
|||
);
|
||||
|
||||
const enrollments = isRollout
|
||||
? store.getAllRollouts()
|
||||
: store.getAllActive();
|
||||
? store.getAllActiveRollouts()
|
||||
: store.getAllActiveExperiments();
|
||||
|
||||
Assert.equal(
|
||||
enrollments.length,
|
||||
|
@ -2823,8 +2823,8 @@ add_task(async function test_restorePrefs_manifestChanged() {
|
|||
});
|
||||
|
||||
const enrollments = isRollout
|
||||
? store.getAllRollouts()
|
||||
: store.getAllActive();
|
||||
? store.getAllActiveRollouts()
|
||||
: store.getAllActiveExperiments();
|
||||
|
||||
Assert.equal(
|
||||
enrollments.length,
|
||||
|
|
|
@ -394,7 +394,7 @@ add_task(async function test_remove_rollout_onFinalize() {
|
|||
const manager = ExperimentFakes.manager(store);
|
||||
const rollout = ExperimentFakes.rollout("foo");
|
||||
|
||||
sinon.stub(store, "getAllRollouts").returns([rollout]);
|
||||
sinon.stub(store, "getAllActiveRollouts").returns([rollout]);
|
||||
sinon.stub(store, "get").returns(rollout);
|
||||
sinon.spy(manager, "unenroll");
|
||||
sinon.spy(manager, "sendFailureTelemetry");
|
||||
|
@ -427,7 +427,7 @@ add_task(async function test_rollout_telemetry_events() {
|
|||
globalSandbox.spy(TelemetryEnvironment, "setExperimentInactive");
|
||||
globalSandbox.spy(TelemetryEvents, "sendEvent");
|
||||
|
||||
sinon.stub(store, "getAllRollouts").returns([rollout]);
|
||||
sinon.stub(store, "getAllActiveRollouts").returns([rollout]);
|
||||
sinon.stub(store, "get").returns(rollout);
|
||||
sinon.spy(manager, "sendFailureTelemetry");
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ add_task(async function test_hasExperimentForFeature() {
|
|||
);
|
||||
});
|
||||
|
||||
add_task(async function test_getAll_getAllActive() {
|
||||
add_task(async function test_getAll_getAllActiveExperiments() {
|
||||
const store = ExperimentFakes.store();
|
||||
|
||||
await store.init();
|
||||
|
@ -183,13 +183,13 @@ add_task(async function test_getAll_getAllActive() {
|
|||
".getAll() should return all experiments"
|
||||
);
|
||||
Assert.deepEqual(
|
||||
store.getAllActive().map(e => e.slug),
|
||||
store.getAllActiveExperiments().map(e => e.slug),
|
||||
["qux"],
|
||||
".getAllActive() should return all experiments that are active"
|
||||
".getAllActiveExperiments() should return all experiments that are active"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_getAll_getAllActive_no_rollouts() {
|
||||
add_task(async function test_getAll_getAllActiveExperiments() {
|
||||
const store = ExperimentFakes.store();
|
||||
|
||||
await store.init();
|
||||
|
@ -205,13 +205,13 @@ add_task(async function test_getAll_getAllActive_no_rollouts() {
|
|||
".getAll() should return all experiments and rollouts"
|
||||
);
|
||||
Assert.deepEqual(
|
||||
store.getAllActive().map(e => e.slug),
|
||||
store.getAllActiveExperiments().map(e => e.slug),
|
||||
["qux"],
|
||||
".getAllActive() should return all experiments that are active and no rollouts"
|
||||
".getAllActiveExperiments() should return all experiments that are active and no rollouts"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_getAllRollouts() {
|
||||
add_task(async function test_getAllActiveRollouts() {
|
||||
const store = ExperimentFakes.store();
|
||||
|
||||
await store.init();
|
||||
|
@ -226,9 +226,9 @@ add_task(async function test_getAllRollouts() {
|
|||
".getAll() should return all experiments and rollouts"
|
||||
);
|
||||
Assert.deepEqual(
|
||||
store.getAllRollouts().map(e => e.slug),
|
||||
store.getAllActiveRollouts().map(e => e.slug),
|
||||
["foo", "bar", "baz"],
|
||||
".getAllRollouts() should return all rollouts"
|
||||
".getAllActiveRollouts() should return all rollouts"
|
||||
);
|
||||
});
|
||||
|
||||
|
|
|
@ -39,9 +39,9 @@ add_task(async function test_enrollmentHelper() {
|
|||
|
||||
await enrollmentPromise;
|
||||
|
||||
Assert.ok(manager.store.getAllActive().length === 1, "Enrolled");
|
||||
Assert.ok(manager.store.getAllActiveExperiments().length === 1, "Enrolled");
|
||||
Assert.equal(
|
||||
manager.store.getAllActive()[0].slug,
|
||||
manager.store.getAllActiveExperiments()[0].slug,
|
||||
recipe.slug,
|
||||
"Has expected slug"
|
||||
);
|
||||
|
|
|
@ -36,7 +36,7 @@ add_task(async function test_updateRecipes_activeExperiments() {
|
|||
const onRecipe = sandbox.stub(manager, "onRecipe");
|
||||
sinon.stub(loader.remoteSettingsClient, "get").resolves([PASS_FILTER_RECIPE]);
|
||||
sandbox.stub(manager.store, "ready").resolves();
|
||||
sandbox.stub(manager.store, "getAllActive").returns([recipe]);
|
||||
sandbox.stub(manager.store, "getAllActiveExperiments").returns([recipe]);
|
||||
|
||||
await loader.init();
|
||||
|
||||
|
@ -53,7 +53,7 @@ add_task(async function test_updateRecipes_isFirstRun() {
|
|||
const onRecipe = sandbox.stub(manager, "onRecipe");
|
||||
sinon.stub(loader.remoteSettingsClient, "get").resolves([PASS_FILTER_RECIPE]);
|
||||
sandbox.stub(manager.store, "ready").resolves();
|
||||
sandbox.stub(manager.store, "getAllActive").returns([recipe]);
|
||||
sandbox.stub(manager.store, "getAllActiveExperiments").returns([recipe]);
|
||||
|
||||
// Pretend to be in the first startup
|
||||
FirstStartup._state = FirstStartup.IN_PROGRESS;
|
||||
|
@ -96,7 +96,7 @@ add_task(async function test_updateRecipes_invalidFeatureId() {
|
|||
const onRecipe = sandbox.stub(manager, "onRecipe");
|
||||
sinon.stub(loader.remoteSettingsClient, "get").resolves([badRecipe]);
|
||||
sandbox.stub(manager.store, "ready").resolves();
|
||||
sandbox.stub(manager.store, "getAllActive").returns([]);
|
||||
sandbox.stub(manager.store, "getAllActiveExperiments").returns([]);
|
||||
|
||||
await loader.init();
|
||||
ok(onRecipe.notCalled, "No recipes");
|
||||
|
@ -140,7 +140,7 @@ add_task(async function test_updateRecipes_invalidFeatureValue() {
|
|||
const onRecipe = sandbox.stub(manager, "onRecipe");
|
||||
sinon.stub(loader.remoteSettingsClient, "get").resolves([badRecipe]);
|
||||
sandbox.stub(manager.store, "ready").resolves();
|
||||
sandbox.stub(manager.store, "getAllActive").returns([]);
|
||||
sandbox.stub(manager.store, "getAllActiveExperiments").returns([]);
|
||||
|
||||
await loader.init();
|
||||
ok(onRecipe.notCalled, "No recipes");
|
||||
|
@ -158,7 +158,7 @@ add_task(async function test_updateRecipes_invalidRecipe() {
|
|||
const onRecipe = sandbox.stub(manager, "onRecipe");
|
||||
sinon.stub(loader.remoteSettingsClient, "get").resolves([badRecipe]);
|
||||
sandbox.stub(manager.store, "ready").resolves();
|
||||
sandbox.stub(manager.store, "getAllActive").returns([]);
|
||||
sandbox.stub(manager.store, "getAllActiveExperiments").returns([]);
|
||||
|
||||
await loader.init();
|
||||
ok(onRecipe.notCalled, "No recipes");
|
||||
|
@ -525,8 +525,8 @@ add_task(async function test_updateRecipes_validationTelemetry() {
|
|||
|
||||
sinon.stub(manager, "onRecipe");
|
||||
sinon.stub(manager.store, "ready").resolves();
|
||||
sinon.stub(manager.store, "getAllActive").returns([]);
|
||||
sinon.stub(manager.store, "getAllRollouts").returns([]);
|
||||
sinon.stub(manager.store, "getAllActiveExperiments").returns([]);
|
||||
sinon.stub(manager.store, "getAllActiveRollouts").returns([]);
|
||||
|
||||
const telemetrySpy = sinon.spy(manager, "sendValidationFailedTelemetry");
|
||||
|
||||
|
@ -619,8 +619,8 @@ add_task(async function test_updateRecipes_validationDisabled() {
|
|||
|
||||
sinon.stub(manager, "onRecipe");
|
||||
sinon.stub(manager.store, "ready").resolves();
|
||||
sinon.stub(manager.store, "getAllActive").returns([]);
|
||||
sinon.stub(manager.store, "getAllRollouts").returns([]);
|
||||
sinon.stub(manager.store, "getAllActiveExperiments").returns([]);
|
||||
sinon.stub(manager.store, "getAllActiveRollouts").returns([]);
|
||||
|
||||
const finalizeStub = sinon.stub(manager, "onFinalize");
|
||||
const telemetrySpy = sinon.spy(manager, "sendValidationFailedTelemetry");
|
||||
|
@ -857,8 +857,8 @@ add_task(async function test_updateRecipes_featureValidationOptOut() {
|
|||
sinon.stub(manager, "onRecipe");
|
||||
sinon.stub(manager, "onFinalize");
|
||||
sinon.stub(manager.store, "ready").resolves();
|
||||
sinon.stub(manager.store, "getAllActive").returns([]);
|
||||
sinon.stub(manager.store, "getAllRollouts").returns([]);
|
||||
sinon.stub(manager.store, "getAllActiveExperiments").returns([]);
|
||||
sinon.stub(manager.store, "getAllActiveRollouts").returns([]);
|
||||
|
||||
await loader.init();
|
||||
ok(
|
||||
|
@ -909,8 +909,8 @@ add_task(async function test_updateRecipes_invalidFeature_mismatch() {
|
|||
sinon.stub(manager, "onRecipe");
|
||||
sinon.stub(manager, "onFinalize");
|
||||
sinon.stub(manager.store, "ready").resolves();
|
||||
sinon.stub(manager.store, "getAllActive").returns([]);
|
||||
sinon.stub(manager.store, "getAllRollouts").returns([]);
|
||||
sinon.stub(manager.store, "getAllActiveExperiments").returns([]);
|
||||
sinon.stub(manager.store, "getAllActiveRollouts").returns([]);
|
||||
|
||||
const telemetrySpy = sinon.stub(manager, "sendValidationFailedTelemetry");
|
||||
const targetingSpy = sinon.spy(loader, "checkTargeting");
|
||||
|
|
|
@ -906,15 +906,15 @@ var dataProviders = {
|
|||
nimbusRollouts,
|
||||
] = await Promise.all(
|
||||
[
|
||||
NormandyAddonStudies.getAllActive(),
|
||||
NormandyPreferenceRollouts.getAllActive(),
|
||||
NormandyPreferenceStudies.getAllActive(),
|
||||
NormandyAddonStudies.getAllActiveExperiments(),
|
||||
NormandyPreferenceRollouts.getAllActiveExperiments(),
|
||||
NormandyPreferenceStudies.getAllActiveExperiments(),
|
||||
ExperimentManager.store
|
||||
.ready()
|
||||
.then(() => ExperimentManager.store.getAllActive()),
|
||||
.then(() => ExperimentManager.store.getAllActiveExperiments()),
|
||||
ExperimentManager.store
|
||||
.ready()
|
||||
.then(() => ExperimentManager.store.getAllRollouts()),
|
||||
.then(() => ExperimentManager.store.getAllActiveRollouts()),
|
||||
].map(promise =>
|
||||
promise
|
||||
.catch(error => {
|
||||
|
|
|
@ -249,15 +249,23 @@ var tests = [
|
|||
|
||||
function normandyErrorHandling(done) {
|
||||
NormandyTestUtils.decorate(
|
||||
NormandyTestUtils.withStub(PreferenceExperiments, "getAllActive", {
|
||||
returnValue: Promise.reject("Expected error - PreferenceExperiments"),
|
||||
}),
|
||||
NormandyTestUtils.withStub(AddonStudies, "getAllActive", {
|
||||
NormandyTestUtils.withStub(
|
||||
PreferenceExperiments,
|
||||
"getAllActiveExperiments",
|
||||
{
|
||||
returnValue: Promise.reject("Expected error - PreferenceExperiments"),
|
||||
}
|
||||
),
|
||||
NormandyTestUtils.withStub(AddonStudies, "getAllActiveExperiments", {
|
||||
returnValue: Promise.reject("Expected error - AddonStudies"),
|
||||
}),
|
||||
NormandyTestUtils.withStub(PreferenceRollouts, "getAllActive", {
|
||||
returnValue: Promise.reject("Expected error - PreferenceRollouts"),
|
||||
}),
|
||||
NormandyTestUtils.withStub(
|
||||
PreferenceRollouts,
|
||||
"getAllActiveExperiments",
|
||||
{
|
||||
returnValue: Promise.reject("Expected error - PreferenceRollouts"),
|
||||
}
|
||||
),
|
||||
NormandyTestUtils.withConsoleSpy(),
|
||||
async function testNormandyErrorHandling({ consoleSpy }) {
|
||||
await new Promise(resolve => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче