Bug 1947902 - Remove usages of ExperimentStore.addEnrollment from tests. r=nimbus-reviewers,beth,application-update-reviewers,omc-reviewers,bytesized,aminomancer

Differential Revision: https://phabricator.services.mozilla.com/D245466
This commit is contained in:
Daniel Thorn
2025-04-28 21:47:26 +00:00
parent 4df1de6e9f
commit 2fe5ce4704
11 changed files with 261 additions and 189 deletions

View File

@@ -6,10 +6,12 @@ https://creativecommons.org/publicdomain/zero/1.0/ */
const { NetUtil } = ChromeUtils.importESModule(
"resource://gre/modules/NetUtil.sys.mjs"
);
const { ExperimentFakes } = ChromeUtils.importESModule(
const { NimbusTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/NimbusTestUtils.sys.mjs"
);
NimbusTestUtils.init(this);
/**
* Tests that a visit to about:welcome results in an exposure recorded via
* Nimbus / Glean.
@@ -18,7 +20,7 @@ const { ExperimentFakes } = ChromeUtils.importESModule(
add_task(async function test_exposure() {
do_get_profile();
Services.fog.initializeFOG();
ExperimentFakes.cleanupStorePrefCache();
NimbusTestUtils.cleanupStorePrefCache();
// Simulate a visit by requesting the about:welcome nsIAboutModule, and
// requesting a channel for about:welcome.
@@ -33,13 +35,13 @@ add_task(async function test_exposure() {
"No exposure events recorded yet."
);
let store = ExperimentFakes.store();
let experiment = ExperimentFakes.experiment("foo", {
features: [{ featureId: "aboutwelcome", isEarlyStartup: true }],
});
await store.init();
store.addEnrollment(experiment);
const { manager, cleanup } = await NimbusTestUtils.setupTest();
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
featureId: "aboutwelcome",
}),
"test"
);
const ABOUT_WELCOME_URI = Services.io.newURI("about:welcome");
@@ -71,4 +73,7 @@ add_task(async function test_exposure() {
);
});
Assert.equal(result.length, 1, "Only a single exposure still.");
manager.unenroll("foo");
cleanup();
});

View File

@@ -17,10 +17,12 @@
const { ASRouterTargeting } = ChromeUtils.importESModule(
"resource:///modules/asrouter/ASRouterTargeting.sys.mjs"
);
const { ExperimentFakes } = ChromeUtils.importESModule(
const { NimbusTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/NimbusTestUtils.sys.mjs"
);
NimbusTestUtils.init(this);
// These randomization IDs were extracted by hand from Firefox instances.
// Randomization is sufficiently stable to hard-code these IDs rather than
// generating new ones at test time.
@@ -41,6 +43,7 @@ setupProfileService();
let taskProfile;
let manager;
let cleanup;
// Arrange a dummy Remote Settings server so that no non-local network
// connections are opened.
@@ -63,21 +66,47 @@ add_setup(async () => {
});
// Arrange fake experiment enrollment details.
manager = ExperimentFakes.manager();
({ manager, cleanup } = await NimbusTestUtils.setupTest());
await manager.onStartup();
await manager.store.addEnrollment(ExperimentFakes.experiment("foo"));
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
branchSlug: "treatment",
featureId: "testFeature",
}),
"test"
);
manager.unenroll("foo");
await manager.store.addEnrollment(
ExperimentFakes.experiment("bar", { active: false })
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("bar", {
branchSlug: "treatment",
featureId: "testFeature",
}),
"test"
);
await manager.store.addEnrollment(
ExperimentFakes.experiment("baz", { active: true })
manager.unenroll("bar");
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("baz", {
branchSlug: "treatment",
featureId: "testFeature",
}),
"test"
);
manager.store.addEnrollment(ExperimentFakes.rollout("rol1"));
await manager.enroll(
NimbusTestUtils.factories.recipe("rol1", { isRollout: true }),
"test"
);
manager.unenroll("rol1");
manager.store.addEnrollment(ExperimentFakes.rollout("rol2"));
await manager.enroll(
NimbusTestUtils.factories.recipe("rol2", { isRollout: true }),
"test"
);
});
registerCleanupFunction(async () => {
manager.unenroll("baz");
manager.unenroll("rol2");
cleanup();
});
function resetProfile(profile) {

View File

@@ -3,32 +3,52 @@
"use strict";
const { ExperimentFakes } = ChromeUtils.importESModule(
const { NimbusTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/NimbusTestUtils.sys.mjs"
);
NimbusTestUtils.init(this);
add_setup(() => {
Services.fog.initializeFOG();
});
add_task(async function test_SUBMIT_ONBOARDING_OPT_OUT_PING() {
// Arrange fake experiment enrollment details.
const manager = ExperimentFakes.manager();
const manager = NimbusTestUtils.stubs.manager();
sinon.stub(SpecialMessageActions, "_experimentManager").get(() => manager);
await manager.onStartup();
await manager.store.addEnrollment(ExperimentFakes.experiment("foo"));
manager.unenroll("foo");
await manager.store.addEnrollment(
ExperimentFakes.experiment("bar", { active: false })
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
featureId: "testFeature",
}),
"test"
);
await manager.store.addEnrollment(
ExperimentFakes.experiment("baz", { active: true })
manager.unenroll("foo");
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("bar", {
featureId: "testFeature",
}),
"test"
);
manager.unenroll("bar");
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("baz", {
featureId: "testFeature",
}),
"test"
);
manager.store.addEnrollment(ExperimentFakes.rollout("rol1"));
await manager.enroll(
NimbusTestUtils.factories.recipe("rol1", { isRollout: true }),
"test"
);
manager.unenroll("rol1");
manager.store.addEnrollment(ExperimentFakes.rollout("rol2"));
await manager.enroll(
NimbusTestUtils.factories.recipe("rol2", { isRollout: true }),
"test"
);
let { promise, resolve } = Promise.withResolvers();
@@ -43,11 +63,11 @@ add_task(async function test_SUBMIT_ONBOARDING_OPT_OUT_PING() {
// Map entry order is stable: we need not sort.
let expected = [
{ experimentSlug: "foo", branchSlug: "treatment" },
{ experimentSlug: "bar", branchSlug: "treatment" },
{ experimentSlug: "baz", branchSlug: "treatment" },
{ experimentSlug: "rol1", branchSlug: "treatment" },
{ experimentSlug: "rol2", branchSlug: "treatment" },
{ experimentSlug: "foo", branchSlug: "control" },
{ experimentSlug: "bar", branchSlug: "control" },
{ experimentSlug: "baz", branchSlug: "control" },
{ experimentSlug: "rol1", branchSlug: "control" },
{ experimentSlug: "rol2", branchSlug: "control" },
];
Assert.deepEqual(
@@ -71,4 +91,6 @@ add_task(async function test_SUBMIT_ONBOARDING_OPT_OUT_PING() {
});
ok(await promise, "`onboarding-opt-out` ping was submitted");
NimbusTestUtils.cleanupManager(["baz", "rol2"], { manager });
});

View File

@@ -15,10 +15,13 @@ add_setup(function () {
add_task(async function test_getExperimentMetaData() {
const { sandbox, manager, cleanup } = await NimbusTestUtils.setupTest();
const expected = ExperimentFakes.experiment("foo");
const expected = NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
featureId: "testFeature",
});
let exposureStub = sandbox.stub(NimbusTelemetry, "recordExposure");
manager.store.addEnrollment(expected);
await manager.enroll(expected, "test");
let metadata = ExperimentAPI.getExperimentMetaData({ slug: expected.slug });
@@ -29,7 +32,7 @@ add_task(async function test_getExperimentMetaData() {
);
Assert.equal(
metadata.branch.slug,
expected.branch.slug,
expected.branches[0].slug,
"Should have the slug prop"
);
@@ -42,10 +45,11 @@ add_task(async function test_getExperimentMetaData() {
add_task(async function test_getRolloutMetaData() {
const { sandbox, manager, cleanup } = await NimbusTestUtils.setupTest();
const expected = ExperimentFakes.rollout("foo");
const expected = NimbusTestUtils.factories.recipe("foo", { isRollout: true });
let exposureStub = sandbox.stub(NimbusTelemetry, "recordExposure");
manager.store.addEnrollment(expected);
await manager.enroll(expected, "test");
let metadata = ExperimentAPI.getExperimentMetaData({ slug: expected.slug });
@@ -56,7 +60,7 @@ add_task(async function test_getRolloutMetaData() {
);
Assert.equal(
metadata.branch.slug,
expected.branch.slug,
expected.branches[0].slug,
"Should have the slug prop"
);

View File

@@ -92,9 +92,10 @@ add_task(async function test_record_exposure_event() {
"no Glean exposure events before exposure"
);
await manager.store.addEnrollment(
ExperimentFakes.experiment("blah", {
branch: {
await manager.enroll(
NimbusTestUtils.factories.recipe("blah", {
branches: [
{
slug: "treatment",
ratio: 1,
features: [
@@ -104,7 +105,9 @@ add_task(async function test_record_exposure_event() {
},
],
},
})
],
}),
"test"
);
featureInstance.recordExposureEvent();
@@ -148,19 +151,13 @@ add_task(async function test_record_exposure_event_once() {
const featureInstance = new ExperimentFeature("foo", FAKE_FEATURE_MANIFEST);
const exposureSpy = sandbox.spy(NimbusTelemetry, "recordExposure");
await manager.store.addEnrollment(
ExperimentFakes.experiment("blah", {
branch: {
slug: "treatment",
ratio: 1,
features: [
{
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("blah", {
branchSlug: "treatment",
featureId: "foo",
value: { enabled: false },
},
],
},
})
}),
"test"
);
featureInstance.recordExposureEvent({ once: true });

View File

@@ -48,20 +48,16 @@ add_task(
add_task(
async function test_ExperimentFeature_getAllVariables_experimentOverPref() {
const { manager, cleanup } = await NimbusTestUtils.setupTest();
const recipe = ExperimentFakes.experiment("awexperiment", {
branch: {
slug: "treatment",
ratio: 1,
features: [
const recipe = NimbusTestUtils.factories.recipe.withFeatureConfig(
"awexperiment",
{
branchSlug: "treatment",
featureId: "aboutwelcome",
value: { screens: ["test-value"] },
},
],
},
});
}
);
await manager.store.addEnrollment(recipe);
await manager.enroll(recipe, "test");
const featureInstance = new ExperimentFeature(
FEATURE_ID,
@@ -109,32 +105,29 @@ add_task(
FEATURE_ID,
FAKE_FEATURE_MANIFEST
);
const recipe = ExperimentFakes.experiment("aw-experiment", {
branch: {
slug: "treatment",
ratio: 1,
features: [
const recipe = NimbusTestUtils.factories.recipe.withFeatureConfig(
"aw-experiment",
{
branchSlug: "treatment",
featureId: FEATURE_ID,
value: { screens: ["test-value"] },
}
);
const rollout = NimbusTestUtils.factories.recipe.withFeatureConfig(
"aw-rollout",
{
branchSlug: "treatment",
featureId: FEATURE_ID,
value: { screens: [], source: "rollout" },
},
],
},
});
const rollout = ExperimentFakes.rollout("aw-rollout", {
branch: {
slug: "treatment",
ratio: 1,
features: [
{ featureId: FEATURE_ID, value: { screens: [], source: "rollout" } },
],
},
});
{ isRollout: true }
);
// We're using the store in this test we need to wait for it to load
await manager.store.ready();
manager.store.addEnrollment(recipe);
manager.store.addEnrollment(rollout);
await manager.enroll(recipe, "test");
await manager.enroll(rollout, "test");
const allVariables = featureInstance.getAllVariables();
@@ -154,13 +147,15 @@ add_task(
FEATURE_ID,
FAKE_FEATURE_MANIFEST
);
const rollout = ExperimentFakes.rollout("foo-aw", {
branch: {
slug: "getAllVariables",
ratio: 1,
features: [{ featureId: FEATURE_ID, value: { screens: [] } }],
const rollout = NimbusTestUtils.factories.recipe.withFeatureConfig(
"foo-aw",
{
branchSlug: "getAllVariables",
featureId: FEATURE_ID,
value: { screens: [] },
},
});
{ isRollout: true }
);
Services.prefs.clearUserPref(TEST_FALLBACK_PREF);
@@ -170,7 +165,7 @@ add_task(
"Pref is not set"
);
manager.store.addEnrollment(rollout);
await manager.enroll(rollout, "test");
Assert.deepEqual(
featureInstance.getAllVariables().screens?.length,

View File

@@ -83,18 +83,15 @@ add_task(async function test_ExperimentFeature_getVariable_precedence() {
const { manager, cleanup } = await NimbusTestUtils.setupTest();
const prefName = TEST_FEATURE.manifest.variables.items.fallbackPref;
const rollout = ExperimentFakes.rollout(`${FEATURE_ID}-rollout`, {
branch: {
slug: "slug",
ratio: 1,
features: [
const rollout = NimbusTestUtils.factories.recipe.withFeatureConfig(
`${FEATURE_ID}-rollout`,
{
branchSlug: "slug",
featureId: FEATURE_ID,
value: { items: [4, 5, 6] },
},
],
},
});
{ isRollout: true }
);
Services.prefs.clearUserPref(prefName);
@@ -113,7 +110,7 @@ add_task(async function test_ExperimentFeature_getVariable_precedence() {
"should return the default pref value"
);
manager.store.addEnrollment(rollout);
await manager.enroll(rollout, "test");
Assert.deepEqual(
TEST_FEATURE.getVariable("items"),
@@ -146,18 +143,15 @@ add_task(async function test_ExperimentFeature_getVariable_precedence() {
add_task(async function test_ExperimentFeature_getVariable_partial_values() {
const { manager, cleanup } = await NimbusTestUtils.setupTest();
const rollout = ExperimentFakes.rollout(`${FEATURE_ID}-rollout`, {
branch: {
slug: "slug",
ratio: 1,
features: [
const rollout = NimbusTestUtils.factories.recipe.withFeatureConfig(
`${FEATURE_ID}-rollout`,
{
branchSlug: "slug",
featureId: FEATURE_ID,
value: { name: "abc" },
},
],
},
});
{ isRollout: true }
);
// Set up a pref value for .enabled,
// a remote value for .name,
@@ -166,7 +160,7 @@ add_task(async function test_ExperimentFeature_getVariable_partial_values() {
TEST_FEATURE.manifest.variables.enabled.fallbackPref,
true
);
manager.store.addEnrollment(rollout);
await manager.enroll(rollout, "test");
const doExperimentCleanup = await ExperimentFakes.enrollWithFeatureConfig(
{
featureId: FEATURE_ID,

View File

@@ -10,20 +10,6 @@ ChromeUtils.defineLazyGetter(this, "fetchSchema", () => {
}).then(rsp => rsp.json());
});
const NON_MATCHING_ROLLOUT = Object.freeze(
ExperimentFakes.rollout("non-matching-rollout", {
branch: {
slug: "slug",
ratio: 1,
features: [
{
featureId: "aboutwelcome",
value: { enabled: false },
},
],
},
})
);
const MATCHING_ROLLOUT = Object.freeze(
ExperimentFakes.rollout("matching-rollout", {
branch: {
@@ -38,6 +24,12 @@ const MATCHING_ROLLOUT = Object.freeze(
},
})
);
const MATCHING_ROLLOUT_RECIPE = Object.freeze(
NimbusTestUtils.factories.recipe(MATCHING_ROLLOUT.slug, {
branches: [MATCHING_ROLLOUT.branch],
isRollout: true,
})
);
const AW_FAKE_MANIFEST = {
description: "Different manifest with a special test variable",
@@ -77,10 +69,6 @@ add_task(async function validSchema() {
shortCircuit: false,
});
{
const result = validator.validate(NON_MATCHING_ROLLOUT);
Assert.ok(result.valid, JSON.stringify(result.errors, undefined, 2));
}
{
const result = validator.validate(MATCHING_ROLLOUT);
Assert.ok(result.valid, JSON.stringify(result.errors, undefined, 2));
@@ -93,7 +81,7 @@ add_task(async function readyCallAfterStore_with_remote_value() {
Assert.ok(feature.getVariable("enabled"), "Feature is true by default");
await manager.store.addEnrollment(MATCHING_ROLLOUT);
await manager.enroll(MATCHING_ROLLOUT_RECIPE, "test");
Assert.ok(!feature.getVariable("enabled"), "Loads value from store");
@@ -143,7 +131,7 @@ add_task(async function update_remote_defaults_onUpdate() {
feature.onUpdate(stub);
await manager.store.addEnrollment(MATCHING_ROLLOUT);
await manager.enroll(MATCHING_ROLLOUT_RECIPE, "test");
Assert.ok(stub.called, "update event called");
Assert.equal(stub.callCount, 1, "Called once for remote configs");
@@ -161,7 +149,7 @@ add_task(async function update_remote_defaults_readyPromise() {
feature.onUpdate(stub);
await manager.store.addEnrollment(MATCHING_ROLLOUT);
await manager.enroll(MATCHING_ROLLOUT_RECIPE, "test");
Assert.ok(stub.calledOnce, "Update called after enrollment processed.");
Assert.ok(
@@ -184,14 +172,14 @@ add_task(async function update_remote_defaults_enabled() {
"Feature is enabled by manifest.variables.enabled"
);
await manager.store.addEnrollment(NON_MATCHING_ROLLOUT);
await manager.enroll(MATCHING_ROLLOUT_RECIPE, "test");
Assert.ok(
!feature.getVariable("enabled"),
"Feature is disabled by remote configuration"
);
manager.unenroll(NON_MATCHING_ROLLOUT.slug);
manager.unenroll(MATCHING_ROLLOUT.slug);
cleanup();
});

View File

@@ -335,11 +335,15 @@ add_task(async function test_failure_name_conflict() {
"no Glean enroll_failed events before failure"
);
const experiment = NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
featureId: "testFeature",
});
// simulate adding a previouly enrolled experiment
await manager.store.addEnrollment(ExperimentFakes.experiment("foo"));
await manager.enroll(experiment, "test");
await Assert.rejects(
manager.enroll(ExperimentFakes.recipe("foo"), "test_failure_name_conflict"),
manager.enroll(experiment, "test_failure_name_conflict"),
/An experiment with the slug "foo" already exists/,
"should throw if a conflicting experiment exists"
);
@@ -361,6 +365,12 @@ add_task(async function test_failure_name_conflict() {
.testGetValue("events")
.map(ev => ev.extra),
[
{
slug: "foo",
status: "Enrolled",
reason: "Qualified",
branch: "control",
},
{
slug: "foo",
status: "NotEnrolled",
@@ -402,17 +412,18 @@ add_task(async function test_failure_group_conflict() {
};
// simulate adding an experiment with a conflicting group "pink"
await manager.store.addEnrollment(
ExperimentFakes.experiment("foo", {
branch: existingBranch,
})
await manager.enroll(
NimbusTestUtils.factories.recipe("foo", {
branches: [existingBranch],
}),
"test_failure_group_conflict"
);
// ensure .enroll chooses the special branch with the conflict
sandbox.stub(manager, "chooseBranch").returns(newBranch);
Assert.equal(
await manager.enroll(
ExperimentFakes.recipe("bar", { branches: [newBranch] }),
NimbusTestUtils.factories.recipe("bar", { branches: [newBranch] }),
"test_failure_group_conflict"
),
null,

View File

@@ -23,7 +23,7 @@ function setupTest({ ...args } = {}) {
add_task(async function test_set_inactive() {
const { manager, cleanup } = await setupTest();
await manager.store.addEnrollment(ExperimentFakes.experiment("foo"));
await manager.enroll(NimbusTestUtils.factories.recipe("foo"), "test");
manager.unenroll("foo");
Assert.equal(
@@ -39,8 +39,10 @@ add_task(async function test_unenroll_opt_out() {
Services.prefs.setBoolPref(STUDIES_OPT_OUT_PREF, true);
const { manager, cleanup } = await setupTest();
const experiment = ExperimentFakes.experiment("foo");
await manager.store.addEnrollment(experiment);
const experiment = NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
featureId: "testFeature",
});
await manager.enroll(experiment, "test");
// Check that there aren't any Glean normandy unenrollNimbusExperiment events yet
Assert.equal(
@@ -72,7 +74,7 @@ add_task(async function test_unenroll_opt_out() {
[
{
value: experiment.slug,
branch: experiment.branch.slug,
branch: experiment.branches[0].slug,
reason: "studies-opt-out",
},
]
@@ -84,7 +86,7 @@ add_task(async function test_unenroll_opt_out() {
[
{
experiment: experiment.slug,
branch: experiment.branch.slug,
branch: experiment.branches[0].slug,
reason: "studies-opt-out",
},
]
@@ -98,8 +100,8 @@ add_task(async function test_unenroll_rollout_opt_out() {
Services.prefs.setBoolPref(STUDIES_OPT_OUT_PREF, true);
const { manager, cleanup } = await setupTest();
const rollout = ExperimentFakes.rollout("foo");
manager.store.addEnrollment(rollout);
const rollout = NimbusTestUtils.factories.recipe("foo", { isRollout: true });
await manager.enroll(rollout, "test");
// Check that there aren't any Glean normandy unenrollNimbusExperiment events yet
Assert.equal(
@@ -131,7 +133,7 @@ add_task(async function test_unenroll_rollout_opt_out() {
[
{
value: rollout.slug,
branch: rollout.branch.slug,
branch: rollout.branches[0].slug,
reason: "studies-opt-out",
},
]
@@ -143,7 +145,7 @@ add_task(async function test_unenroll_rollout_opt_out() {
[
{
experiment: rollout.slug,
branch: rollout.branch.slug,
branch: rollout.branches[0].slug,
reason: "studies-opt-out",
},
]
@@ -217,9 +219,11 @@ add_task(async function test_setExperimentInactive_called() {
add_task(async function test_send_unenroll_event() {
const { manager, cleanup } = await setupTest();
const experiment = ExperimentFakes.experiment("foo");
const experiment = NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
featureId: "testFeature",
});
manager.store.addEnrollment(experiment);
await manager.enroll(experiment, "test");
// Check that there aren't any Glean normandy unenrollNimbusExperiment events yet
Assert.equal(
@@ -245,7 +249,7 @@ add_task(async function test_send_unenroll_event() {
[
{
value: experiment.slug,
branch: experiment.branch.slug,
branch: experiment.branches[0].slug,
reason: "some-reason",
},
]
@@ -257,7 +261,7 @@ add_task(async function test_send_unenroll_event() {
[
{
experiment: experiment.slug,
branch: experiment.branch.slug,
branch: experiment.branches[0].slug,
reason: "some-reason",
},
]
@@ -268,9 +272,9 @@ add_task(async function test_send_unenroll_event() {
add_task(async function test_undefined_reason() {
const { manager, cleanup } = await setupTest();
const experiment = ExperimentFakes.experiment("foo");
const experiment = NimbusTestUtils.factories.recipe("foo");
manager.store.addEnrollment(experiment);
await manager.enroll(experiment, "test");
manager.unenroll("foo");

View File

@@ -12,7 +12,7 @@ const { ASRouterTargeting } = ChromeUtils.importESModule(
const { BackgroundUpdate } = ChromeUtils.importESModule(
"resource://gre/modules/BackgroundUpdate.sys.mjs"
);
const { ExperimentFakes } = ChromeUtils.importESModule(
const { NimbusTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/NimbusTestUtils.sys.mjs"
);
@@ -20,6 +20,8 @@ const { maybeSubmitBackgroundUpdatePing } = ChromeUtils.importESModule(
"resource://gre/modules/backgroundtasks/BackgroundTask_backgroundupdate.sys.mjs"
);
NimbusTestUtils.init(this);
XPCOMUtils.defineLazyServiceGetter(
this,
"UpdateService",
@@ -173,21 +175,38 @@ add_task(async function test_targeting_exists() {
};
// Arrange fake experiment enrollment details.
const manager = ExperimentFakes.manager();
const { manager, cleanup } = await NimbusTestUtils.setupTest();
await manager.onStartup();
await manager.store.addEnrollment(ExperimentFakes.experiment("foo"));
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("foo", {
featureId: "testFeature",
}),
"test"
);
manager.unenroll("foo");
await manager.store.addEnrollment(
ExperimentFakes.experiment("bar", { active: false })
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("bar", {
featureId: "testFeature",
}),
"test"
);
await manager.store.addEnrollment(
ExperimentFakes.experiment("baz", { active: true })
manager.unenroll("bar");
await manager.enroll(
NimbusTestUtils.factories.recipe.withFeatureConfig("baz", {
featureId: "testFeature",
}),
"test"
);
manager.store.addEnrollment(ExperimentFakes.rollout("rol1"));
await manager.enroll(
NimbusTestUtils.factories.recipe("rol1", { isRollout: true }),
"test"
);
manager.unenroll("rol1");
manager.store.addEnrollment(ExperimentFakes.rollout("rol2"));
await manager.enroll(
NimbusTestUtils.factories.recipe("rol2", { isRollout: true }),
"test"
);
let targetSnapshot = await ASRouterTargeting.getEnvironmentSnapshot({
targets: [manager.createTargetingContext(), target],
@@ -246,7 +265,7 @@ add_task(async function test_targeting_exists() {
// Verify active experiments.
Assert.deepEqual(
{
branch: "treatment",
branch: "control",
extra: { source: "defaultProfile", type: "nimbus-nimbus" },
},
Services.fog.testGetExperimentData("baz"),
@@ -255,7 +274,7 @@ add_task(async function test_targeting_exists() {
Assert.deepEqual(
{
branch: "treatment",
branch: "control",
extra: { source: "defaultProfile", type: "nimbus-rollout" },
},
Services.fog.testGetExperimentData("rol2"),
@@ -272,4 +291,8 @@ add_task(async function test_targeting_exists() {
);
}
});
manager.unenroll("baz");
manager.unenroll("rol2");
cleanup();
});