commit bc783c59bedef094ea6c581e65ddeff84f72d210
parent c5441bf8cef4e442ba382eab5a94c4021d79ff29
Author: Beth Rennie <beth@brennie.ca>
Date: Tue, 2 Dec 2025 18:17:46 +0000
Bug 2003365 - Remove NimbusTestUtils.waitForInactiveEnrollment r=nimbus-reviewers,relud
Differential Revision: https://phabricator.services.mozilla.com/D274646
Diffstat:
5 files changed, 33 insertions(+), 40 deletions(-)
diff --git a/toolkit/components/nimbus/test/NimbusTestUtils.sys.mjs b/toolkit/components/nimbus/test/NimbusTestUtils.sys.mjs
@@ -268,6 +268,8 @@ export const NimbusTestUtils = {
slug,
{ active: expectedActive, profileId = ExperimentAPI.profileId } = {}
) {
+ await NimbusTestUtils.flushStore();
+
const conn = await lazy.ProfilesDatastoreService.getConnection();
const result = await conn.execute(
@@ -1394,28 +1396,6 @@ export const NimbusTestUtils = {
}, `Waiting for enrollments of ${expectedSlugs} to sync to database`);
},
- async waitForInactiveEnrollment(slug) {
- const profileId = ExperimentAPI.profileId;
-
- await this.flushStore();
- await lazy.TestUtils.waitForCondition(async () => {
- const conn = await lazy.ProfilesDatastoreService.getConnection();
- const result = await conn.execute(
- `
- SELECT
- active
- FROM NimbusEnrollments
- WHERE
- slug = :slug AND
- profileId = :profileId;
- `,
- { profileId, slug }
- );
-
- return result.length === 1 && !result[0].getResultByName("active");
- }, `Waiting for ${slug} enrollment to exist and be inactive`);
- },
-
async waitForAllUnenrollments() {
const profileId = ExperimentAPI.profileId;
diff --git a/toolkit/components/nimbus/test/unit/test_ExperimentManager_prefs.js b/toolkit/components/nimbus/test/unit/test_ExperimentManager_prefs.js
@@ -1796,8 +1796,7 @@ add_task(async function test_prefChange() {
if (!expectedEnrollments.includes(enrollmentKind)) {
const slug = slugs[enrollmentKind];
- await NimbusTestUtils.flushStore();
- await NimbusTestUtils.waitForInactiveEnrollment(slug);
+ await NimbusTestUtils.assert.enrollmentExists(slug, { active: false });
const enrollment = manager.store.get(slug);
@@ -2424,7 +2423,7 @@ add_task(async function test_clearUserPref() {
if (!expectedEnrolled) {
await NimbusTestUtils.flushStore();
- await NimbusTestUtils.waitForInactiveEnrollment(slug);
+ await NimbusTestUtils.assert.enrollmentExists(slug, { active: false });
}
const enrollment = manager.store.get(slug);
diff --git a/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js b/toolkit/components/nimbus/test/unit/test_ExperimentManager_unenroll.js
@@ -60,7 +60,9 @@ add_task(async function test_unenroll_opt_out() {
Services.prefs.setBoolPref(STUDIES_OPT_OUT_PREF, false);
- await NimbusTestUtils.waitForInactiveEnrollment(experiment.slug);
+ await NimbusTestUtils.assert.enrollmentExists(experiment.slug, {
+ active: false,
+ });
Assert.equal(
manager.store.get(experiment.slug).active,
@@ -121,7 +123,9 @@ add_task(async function test_unenroll_rollout_opt_out() {
Services.prefs.setBoolPref(STUDIES_OPT_OUT_PREF, false);
- await NimbusTestUtils.waitForInactiveEnrollment(rollout.slug);
+ await NimbusTestUtils.assert.enrollmentExists(rollout.slug, {
+ active: false,
+ });
Assert.equal(
manager.store.get(rollout.slug).active,
@@ -175,7 +179,7 @@ add_task(async function test_unenroll_uploadPref() {
Services.prefs.setBoolPref(UPLOAD_ENABLED_PREF, false);
- await NimbusTestUtils.waitForInactiveEnrollment(recipe.slug);
+ await NimbusTestUtils.assert.enrollmentExists(recipe.slug, { active: false });
Assert.equal(
manager.store.get(recipe.slug).active,
diff --git a/toolkit/components/nimbus/test/unit/test_localization.js b/toolkit/components/nimbus/test/unit/test_localization.js
@@ -244,7 +244,9 @@ add_task(async function test_getLocalizedValue_unenroll_missingEntry() {
"_getLocalizedValue() with a bogus localization"
);
- await NimbusTestUtils.waitForInactiveEnrollment(enrollment.slug);
+ await NimbusTestUtils.assert.enrollmentExists(enrollment.slug, {
+ active: false,
+ });
Assert.equal(
manager.store.getExperimentForFeature(FEATURE_ID),
@@ -315,7 +317,9 @@ add_task(async function test_getLocalizedValue_unenroll_missingEntry() {
"_getLocalizedValue() with a bogus localization"
);
- await NimbusTestUtils.waitForInactiveEnrollment(enrollment.slug);
+ await NimbusTestUtils.assert.enrollmentExists(enrollment.slug, {
+ active: false,
+ });
Assert.equal(
manager.store.getExperimentForFeature(FEATURE_ID),
@@ -646,8 +650,10 @@ add_task(async function test_getVariables_fallback_unenroll() {
waldo: ["fallback-waldo-pref-value"],
});
- await NimbusTestUtils.waitForInactiveEnrollment("experiment");
- await NimbusTestUtils.waitForInactiveEnrollment("rollout");
+ await NimbusTestUtils.assert.enrollmentExists("experiment", {
+ active: false,
+ });
+ await NimbusTestUtils.assert.enrollmentExists("rollout", { active: false });
Assert.equal(
manager.store.getExperimentForFeature(FEATURE_ID),
diff --git a/toolkit/components/nimbus/test/unit/test_prefFlips.js b/toolkit/components/nimbus/test/unit/test_prefFlips.js
@@ -2456,7 +2456,7 @@ add_task(async function test_prefFlips_failed() {
// That callback triggers an async unenroll() without awaiting (because it
// wouldn't block the ExperimentStore anyway) so we have to wait for the
// unenroll to be propagated to the database first.
- await NimbusTestUtils.waitForInactiveEnrollment(recipe.slug);
+ await NimbusTestUtils.assert.enrollmentExists(recipe.slug, { active: false });
const enrollment = manager.store.get(recipe.slug);
Assert.ok(!enrollment.active, "Experiment should not be active");
@@ -2534,7 +2534,7 @@ add_task(async function test_prefFlips_failed_multiple_prefs() {
// That callback triggers an async unenroll() without awaiting (because it
// wouldn't block the ExperimentStore anyway) so we have to wait for the
// unenroll to be propagated to the database first.
- await NimbusTestUtils.waitForInactiveEnrollment(recipe.slug);
+ await NimbusTestUtils.assert.enrollmentExists(recipe.slug, { active: false });
const enrollment = manager.store.get(recipe.slug);
Assert.ok(!enrollment.active, "Experiment should not be active");
@@ -2669,7 +2669,7 @@ add_task(async function test_prefFlips_failed_experiment_and_rollout_1() {
info("Checking expected unenrollments...");
for (const slug of expectedUnenrollments) {
- await NimbusTestUtils.waitForInactiveEnrollment(slug);
+ await NimbusTestUtils.assert.enrollmentExists(slug, { active: false });
const enrollment = manager.store.get(slug);
Assert.ok(!enrollment.active, "The enrollment is no longer active.");
}
@@ -2785,7 +2785,7 @@ add_task(async function test_prefFlips_failed_experiment_and_rollout_2() {
info("Checking expected unenrollments...");
for (const slug of expectedUnenrollments) {
- await NimbusTestUtils.waitForInactiveEnrollment(slug);
+ await NimbusTestUtils.assert.enrollmentExists(slug, { active: false });
const enrollment = manager.store.get(slug);
Assert.ok(!enrollment.active, "The enrollment is no longer active.");
}
@@ -3111,7 +3111,7 @@ async function test_prefFlips_restore_failure_conflict() {
});
await NimbusTestUtils.waitForActiveEnrollments(["rollout-1"]);
- await NimbusTestUtils.waitForInactiveEnrollment("rollout-2");
+ await NimbusTestUtils.assert.enrollmentExists("rollout-2", { active: false });
Assert.ok(manager.store.get("rollout-1").active, "rollout-1 is active");
Assert.ok(!manager.store.get("rollout-2").active, "rollout-2 is not active");
@@ -3206,7 +3206,7 @@ async function test_prefFlips_restore_failure_wrong_type() {
});
await NimbusTestUtils.flushStore(manager.store);
- await NimbusTestUtils.waitForInactiveEnrollment(recipe.slug);
+ await NimbusTestUtils.assert.enrollmentExists(recipe.slug, { active: false });
const enrollment = manager.store.get(recipe.slug);
@@ -3264,7 +3264,9 @@ add_task(
PrefUtils.setPref(PREF, "default-value", { branch: DEFAULT });
await manager.enroll(recipe, "rs-loader");
- await NimbusTestUtils.waitForInactiveEnrollment(recipe.slug);
+ await NimbusTestUtils.assert.enrollmentExists(recipe.slug, {
+ active: false,
+ });
let enrollment = manager.store.get(recipe.slug);
@@ -3272,7 +3274,9 @@ add_task(
Assert.equal(enrollment.unenrollReason, "prefFlips-failed");
await manager.enroll(recipe, "rs-loader", { reenroll: true });
- await NimbusTestUtils.waitForInactiveEnrollment(recipe.slug);
+ await NimbusTestUtils.assert.enrollmentExists(recipe.slug, {
+ active: false,
+ });
enrollment = manager.store.get(recipe.slug);