mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-20 00:35:44 +00:00
Bug 1553125 - Force a recipes sync when Normandy is in dev mode r=leplatrem
Differential Revision: https://phabricator.services.mozilla.com/D32900 --HG-- extra : moz-landing-system : lando
This commit is contained in:
parent
2e7b8a7ab6
commit
78657c1506
@ -58,6 +58,10 @@ XPCOMUtils.defineLazyGetter(this, "gRemoteSettingsClient", () => {
|
||||
});
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyGetter(this, "gRemoteSettingsGate", () => {
|
||||
return FeatureGate.fromId("normandy-remote-settings");
|
||||
});
|
||||
|
||||
/**
|
||||
* cacheProxy returns an object Proxy that will memoize properties of the target.
|
||||
*/
|
||||
@ -83,13 +87,31 @@ var RecipeRunner = {
|
||||
this.watchPrefs();
|
||||
await this.setUpRemoteSettings();
|
||||
|
||||
// Run if enabled immediately on first run, or if dev mode is enabled.
|
||||
// Here "first run" means the first run this profile has ever done. This
|
||||
// preference is set to true at the end of this function, and never reset to
|
||||
// false.
|
||||
const firstRun = Services.prefs.getBoolPref(FIRST_RUN_PREF, true);
|
||||
|
||||
// Dev mode is a mode used for development and QA that bypasses the normal
|
||||
// timer function of Normandy, to make testing more convenient.
|
||||
const devMode = Services.prefs.getBoolPref(DEV_MODE_PREF, false);
|
||||
|
||||
if (this.enabled && (devMode || firstRun)) {
|
||||
// In dev mode, if remote settings is enabled, force an immediate sync
|
||||
// before running. This ensures that the latest data is used for testing.
|
||||
// This is not needed for the first run case, because remote settings
|
||||
// already handles empty collections well.
|
||||
if (devMode) {
|
||||
let remoteSettingsGate = await gRemoteSettingsGate;
|
||||
if (await remoteSettingsGate.isEnabled()) {
|
||||
await gRemoteSettingsClient.sync();
|
||||
}
|
||||
}
|
||||
await this.run();
|
||||
}
|
||||
|
||||
// Update the firstRun pref, to indicate that Normandy has run at least once
|
||||
// on this profile.
|
||||
if (firstRun) {
|
||||
Services.prefs.setBoolPref(FIRST_RUN_PREF, false);
|
||||
}
|
||||
@ -199,17 +221,16 @@ var RecipeRunner = {
|
||||
},
|
||||
|
||||
async setUpRemoteSettings() {
|
||||
const feature = "normandy-remote-settings";
|
||||
|
||||
if (await FeatureGate.isEnabled(feature)) {
|
||||
const remoteSettingsGate = await gRemoteSettingsGate;
|
||||
if (await remoteSettingsGate.isEnabled()) {
|
||||
this.attachRemoteSettings();
|
||||
}
|
||||
const observer = {
|
||||
onEnable: this.attachRemoteSettings.bind(this),
|
||||
onDisable: this.detachRemoteSettings.bind(this),
|
||||
};
|
||||
await FeatureGate.addObserver(feature, observer);
|
||||
CleanupManager.addCleanupHandler(() => FeatureGate.removeObserver(feature, observer));
|
||||
remoteSettingsGate.addObserver(observer);
|
||||
CleanupManager.addCleanupHandler(() => remoteSettingsGate.removeObserver(observer));
|
||||
},
|
||||
|
||||
attachRemoteSettings() {
|
||||
|
@ -326,10 +326,12 @@ decorate_task(
|
||||
}),
|
||||
withStub(RecipeRunner, "run"),
|
||||
withStub(RecipeRunner, "registerTimer"),
|
||||
async function testInitDevMode(runStub, registerTimerStub, updateRunIntervalStub) {
|
||||
withStub(RecipeRunner._remoteSettingsClientForTesting, "sync"),
|
||||
async function testInitDevMode(runStub, registerTimerStub, syncStub) {
|
||||
await RecipeRunner.init();
|
||||
ok(runStub.called, "RecipeRunner.run is called immediately when in dev mode");
|
||||
ok(registerTimerStub.called, "RecipeRunner.init registers a timer");
|
||||
ok(runStub.called, "RecipeRunner.run should be called immediately when in dev mode");
|
||||
ok(registerTimerStub.called, "RecipeRunner.init should register a timer");
|
||||
ok(syncStub.called, "RecipeRunner.init should sync remote settings in dev mode");
|
||||
}
|
||||
);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user