зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1715804 - Use enrollment branch information for startup onUpdate notifications r=k88hudson
Differential Revision: https://phabricator.services.mozilla.com/D117442
This commit is contained in:
Родитель
c45f796a16
Коммит
0ccfec97f9
|
@ -101,10 +101,13 @@ class ExperimentStore extends SharedDataMap {
|
|||
async init() {
|
||||
await super.init();
|
||||
|
||||
this.getAllActive().forEach(experiment => {
|
||||
experiment.featureIds?.forEach(feature =>
|
||||
this._emitFeatureUpdate(feature, "feature-experiment-loaded")
|
||||
);
|
||||
this.getAllActive().forEach(({ branch }) => {
|
||||
if (branch?.feature?.featureId) {
|
||||
this._emitFeatureUpdate(
|
||||
branch.feature.featureId,
|
||||
"feature-experiment-loaded"
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -6,6 +6,12 @@
|
|||
const { ExperimentStore } = ChromeUtils.import(
|
||||
"resource://nimbus/lib/ExperimentStore.jsm"
|
||||
);
|
||||
const { ExperimentFakes } = ChromeUtils.import(
|
||||
"resource://testing-common/NimbusTestUtils.jsm"
|
||||
);
|
||||
const { ExperimentFeatures } = ChromeUtils.import(
|
||||
"resource://nimbus/ExperimentAPI.jsm"
|
||||
);
|
||||
ChromeUtils.defineModuleGetter(
|
||||
this,
|
||||
"JSONFile",
|
||||
|
@ -38,3 +44,28 @@ add_task(async function test_loadFromFile() {
|
|||
"This should pass if the correct store path loaded successfully"
|
||||
);
|
||||
});
|
||||
|
||||
add_task(async function test_load_from_disk_event() {
|
||||
const experiment = ExperimentFakes.experiment("foo", {
|
||||
branch: {
|
||||
slug: "variant",
|
||||
feature: { featureId: "green", enabled: true },
|
||||
},
|
||||
});
|
||||
const stub = sinon.stub();
|
||||
const previousSession = new JSONFile({ path: getPath() });
|
||||
await previousSession.load();
|
||||
previousSession.data.foo = experiment;
|
||||
previousSession.saveSoon();
|
||||
await previousSession.finalize();
|
||||
|
||||
// Create a store and expect to load data from previous session
|
||||
const store = new ExperimentStore();
|
||||
|
||||
store._onFeatureUpdate("green", stub);
|
||||
|
||||
await store.init();
|
||||
await TestUtils.waitForCondition(() => stub.called, "Stub was called");
|
||||
|
||||
Assert.ok(stub.firstCall.args[1], "feature-experiment-loaded");
|
||||
});
|
||||
|
|
|
@ -335,7 +335,6 @@ add_task(async function test_record_exposure_event() {
|
|||
|
||||
manager.store.addExperiment(
|
||||
ExperimentFakes.experiment("blah", {
|
||||
featureIds: ["foo"],
|
||||
branch: {
|
||||
slug: "treatment",
|
||||
feature: {
|
||||
|
@ -365,7 +364,6 @@ add_task(async function test_record_exposure_event_once() {
|
|||
|
||||
manager.store.addExperiment(
|
||||
ExperimentFakes.experiment("blah", {
|
||||
featureIds: ["foo"],
|
||||
branch: {
|
||||
slug: "treatment",
|
||||
feature: {
|
||||
|
@ -394,7 +392,6 @@ add_task(async function test_prevent_double_exposure_getValue() {
|
|||
|
||||
manager.store.addExperiment(
|
||||
ExperimentFakes.experiment("blah", {
|
||||
featureIds: ["foo"],
|
||||
branch: {
|
||||
slug: "treatment",
|
||||
feature: {
|
||||
|
@ -426,7 +423,6 @@ add_task(async function test_prevent_double_exposure_isEnabled() {
|
|||
|
||||
manager.store.addExperiment(
|
||||
ExperimentFakes.experiment("blah", {
|
||||
featureIds: ["foo"],
|
||||
branch: {
|
||||
slug: "treatment",
|
||||
feature: {
|
||||
|
@ -504,7 +500,6 @@ add_task(async function test_isEnabled_backwards_compatible() {
|
|||
|
||||
manager.store.addExperiment(
|
||||
ExperimentFakes.experiment("blah", {
|
||||
featureIds: ["foo"],
|
||||
branch: {
|
||||
slug: "treatment",
|
||||
feature: {
|
||||
|
@ -532,7 +527,6 @@ add_task(async function test_onUpdate_before_store_ready() {
|
|||
sandbox.stub(ExperimentAPI, "_store").get(() => manager.store);
|
||||
sandbox.stub(manager.store, "getAllActive").returns([
|
||||
ExperimentFakes.experiment("foo-experiment", {
|
||||
featureIds: ["foo"],
|
||||
branch: { slug: "control", feature: { featureId: "foo", value: null } },
|
||||
}),
|
||||
]);
|
||||
|
|
Загрузка…
Ссылка в новой задаче