Bug 1563180 - Prevent synchronization to be ran in parallel multiple times r=glasserc

Differential Revision: https://phabricator.services.mozilla.com/D36921

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Mathieu Leplatre 2019-07-06 16:05:12 +00:00
Родитель f711552789
Коммит 4039e268d2
2 изменённых файлов: 24 добавлений и 0 удалений

Просмотреть файл

@ -193,6 +193,7 @@ class RemoteSettingsClient extends EventEmitter {
this.localFields = localFields;
this._lastCheckTimePref = lastCheckTimePref;
this._verifier = null;
this._syncRunning = false;
// This attribute allows signature verification to be disabled, when running tests
// or when pulling data from a dev server.
@ -362,6 +363,14 @@ class RemoteSettingsClient extends EventEmitter {
async maybeSync(expectedTimestamp, options = {}) {
const { loadDump = true, trigger = "manual" } = options;
// Make sure we don't run several synchronizations in parallel, mainly
// in order to avoid race conditions in "sync" events listeners.
if (this._syncRunning) {
console.warn(`${this.identifier} sync already running`);
return;
}
this._syncRunning = true;
let importedFromDump = [];
const startedAt = new Date();
let reportStatus = null;
@ -588,6 +597,7 @@ class RemoteSettingsClient extends EventEmitter {
duration: durationMilliseconds,
});
console.debug(`${this.identifier} sync status is ${reportStatus}`);
this._syncRunning = false;
}
}

Просмотреть файл

@ -351,6 +351,20 @@ add_task(async function test_get_does_not_verify_signature_if_load_dump() {
});
add_task(clear_state);
add_task(async function test_sync_runs_once_only() {
const backup = Utils.log.warn;
const messages = [];
Utils.log.warn = (m) => {
messages.push(m);
};
await Promise.all([client.maybeSync(2000), client.maybeSync(2000)]);
ok(messages.includes("main/password-fields sync already running"), "warning is shown about sync already running");
Utils.log.warn = backup;
});
add_task(clear_state);
add_task(
async function test_sync_pulls_metadata_if_missing_with_dump_is_up_to_date() {
if (IS_ANDROID) {