Bug 1405833 - Ensure SyncEngine uses CommonUtils.namedTimer properly. r=kitcambridge

MozReview-Commit-ID: 6YnhcSjKW9U

--HG--
extra : rebase_source : 3e0e520516f06efa50aa8e3fccb77214daca419a
This commit is contained in:
Thom Chiovoloni 2017-10-04 17:26:20 -04:00
parent 50959cb695
commit 0c48a189bc
2 changed files with 42 additions and 4 deletions

View File

@ -890,10 +890,12 @@ SyncEngine.prototype = {
this._toFetch = val;
CommonUtils.namedTimer(function() {
try {
Async.promiseSpinningly(Utils.jsonSave("toFetch/" + this.name, this, val));
Async.promiseSpinningly(Utils.jsonSave("toFetch/" + this.name, this, this._toFetch));
} catch (error) {
this._log.error("Failed to read JSON records to fetch", error);
}
// Notify our tests that we finished writing the file.
Observers.notify("sync-testing:file-saved:toFetch", null, this.name);
}, 0, this, "_toFetchDelay");
},
@ -916,11 +918,15 @@ SyncEngine.prototype = {
}
this._previousFailed = val;
CommonUtils.namedTimer(function() {
Utils.jsonSave("failed/" + this.name, this, val).then(() => {
Utils.jsonSave("failed/" + this.name, this, this._previousFailed).then(() => {
this._log.debug("Successfully wrote previousFailed.");
})
.catch((error) => {
this._log.error("Failed to set previousFailed", error);
})
.then(() => {
// Notify our tests that we finished writing the file.
Observers.notify("sync-testing:file-saved:previousFailed", null, this.name);
});
}, 0, this, "_previousFailedDelay");
},

View File

@ -93,13 +93,29 @@ add_task(async function test_toFetch() {
// Write file to disk
let toFetch = [Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID()];
let wrotePromise = promiseOneObserver("sync-testing:file-saved:toFetch");
engine.toFetch = toFetch;
do_check_eq(engine.toFetch, toFetch);
// toFetch is written asynchronously
await Async.promiseYield();
await wrotePromise;
let fakefile = syncTesting.fakeFilesystem.fakeContents[filename];
do_check_eq(fakefile, JSON.stringify(toFetch));
// Make sure it work for consecutive writes before the callback is executed.
toFetch = [Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID()];
let toFetch2 = [Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID()];
wrotePromise = promiseOneObserver("sync-testing:file-saved:toFetch");
engine.toFetch = toFetch;
do_check_eq(engine.toFetch, toFetch);
engine.toFetch = toFetch2;
do_check_eq(engine.toFetch, toFetch2);
// Note that do to the way CommonUtils.namedTimer works, we won't get a 2nd callback.
await wrotePromise;
fakefile = syncTesting.fakeFilesystem.fakeContents[filename];
do_check_eq(fakefile, JSON.stringify(toFetch2));
// Read file from disk
toFetch = [Utils.makeGUID(), Utils.makeGUID()];
syncTesting.fakeFilesystem.fakeContents[filename] = JSON.stringify(toFetch);
@ -123,13 +139,29 @@ add_task(async function test_previousFailed() {
// Write file to disk
let previousFailed = [Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID()];
let wrotePromise = promiseOneObserver("sync-testing:file-saved:previousFailed");
engine.previousFailed = previousFailed;
do_check_eq(engine.previousFailed, previousFailed);
// previousFailed is written asynchronously
await Async.promiseYield();
await wrotePromise;
let fakefile = syncTesting.fakeFilesystem.fakeContents[filename];
do_check_eq(fakefile, JSON.stringify(previousFailed));
// Make sure it work for consecutive writes before the callback is executed.
previousFailed = [Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID()];
let previousFailed2 = [Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID(), Utils.makeGUID()];
wrotePromise = promiseOneObserver("sync-testing:file-saved:previousFailed");
engine.previousFailed = previousFailed;
do_check_eq(engine.previousFailed, previousFailed);
engine.previousFailed = previousFailed2;
do_check_eq(engine.previousFailed, previousFailed2);
// Note that do to the way CommonUtils.namedTimer works, we're only notified once.
await wrotePromise;
fakefile = syncTesting.fakeFilesystem.fakeContents[filename];
do_check_eq(fakefile, JSON.stringify(previousFailed2));
// Read file from disk
previousFailed = [Utils.makeGUID(), Utils.makeGUID()];
syncTesting.fakeFilesystem.fakeContents[filename] = JSON.stringify(previousFailed);