Bug 1384818 - flush sync log files on sync reset. r=eoger
authorMark Hammond <mhammond@skippinet.com.au>
Thu, 27 Jul 2017 14:57:47 +1000
changeset 423284 8ae7fae10cb2d6918224e037e462cb063bd1be88
parent 423283 b402e104aafef7d1396f59b159eae342e467c454
child 423285 15a04f67656b4f3846e6e98db92ddb97b80daf96
push id1517
push userjlorenzo@mozilla.com
push dateThu, 14 Sep 2017 16:50:54 +0000
treeherdermozilla-release@3b41fd564418 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerseoger
bugs1384818
milestone56.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1384818 - flush sync log files on sync reset. r=eoger MozReview-Commit-ID: H6CkvHGxAmx
services/sync/modules/policies.js
services/sync/tests/unit/test_errorhandler_1.js
services/sync/tests/unit/test_errorhandler_2.js
--- a/services/sync/modules/policies.js
+++ b/services/sync/modules/policies.js
@@ -594,16 +594,17 @@ ErrorHandler.prototype = {
   didReportProlongedError: false,
 
   init: function init() {
     Svc.Obs.add("weave:engine:sync:applied", this);
     Svc.Obs.add("weave:engine:sync:error", this);
     Svc.Obs.add("weave:service:login:error", this);
     Svc.Obs.add("weave:service:sync:error", this);
     Svc.Obs.add("weave:service:sync:finish", this);
+    Svc.Obs.add("weave:service:start-over:finish", this);
 
     this.initLogs();
   },
 
   initLogs: function initLogs() {
     this._log = Log.repository.getLogger("Sync.ErrorHandler");
     this._log.level = Log.Level[Svc.Prefs.get("log.logger.service.main")];
 
@@ -711,16 +712,20 @@ ErrorHandler.prototype = {
             break;
           }
         } else {
           this.resetFileLog();
         }
         this.dontIgnoreErrors = false;
         this.notifyOnNextTick("weave:ui:sync:finish");
         break;
+      case "weave:service:start-over:finish":
+        // ensure we capture any logs between the last sync and the reset completing.
+        this.resetFileLog();
+        break;
     }
   },
 
   notifyOnNextTick: function notifyOnNextTick(topic) {
     Utils.nextTick(function() {
       this._log.trace("Notifying " + topic +
                       ". Status.login is " + Status.login +
                       ". Status.sync is " + Status.sync);
--- a/services/sync/tests/unit/test_errorhandler_1.js
+++ b/services/sync/tests/unit/test_errorhandler_1.js
@@ -50,17 +50,19 @@ add_task(async function setup() {
   Log.repository.getLogger("Sync.ErrorHandler").level = Log.Level.Trace;
 
   Service.engineManager.clear();
   await Service.engineManager.register(EHTestsCommon.CatapultEngine);
   engine = Service.engineManager.get("catapult");
 });
 
 async function clean() {
+  let promiseLogReset = promiseOneObserver("weave:service:reset-file-log");
   await Service.startOver();
+  await promiseLogReset;
   Status.resetSync();
   Status.resetBackoff();
   errorHandler.didReportProlongedError = false;
 }
 
 add_task(async function test_401_logout() {
   enableValidationPrefs();
 
--- a/services/sync/tests/unit/test_errorhandler_2.js
+++ b/services/sync/tests/unit/test_errorhandler_2.js
@@ -21,48 +21,86 @@ do_register_cleanup(function() {
     fakeServer.stop(resolve);
   });
 });
 
 var fakeServerUrl = "http://localhost:" + fakeServer.port;
 
 const logsdir = FileUtils.getDir("ProfD", ["weave", "logs"], true);
 
+function removeLogFiles() {
+  let entries = logsdir.directoryEntries;
+  while (entries.hasMoreElements()) {
+    let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
+    logfile.remove(false);
+  }
+}
+
+function getLogFiles() {
+  let result = [];
+  let entries = logsdir.directoryEntries;
+  while (entries.hasMoreElements()) {
+    result.push(entries.getNext().QueryInterface(Ci.nsILocalFile));
+  }
+  return result;
+}
+
 const PROLONGED_ERROR_DURATION =
   (Svc.Prefs.get("errorhandler.networkFailureReportTimeout") * 2) * 1000;
 
 const NON_PROLONGED_ERROR_DURATION =
   (Svc.Prefs.get("errorhandler.networkFailureReportTimeout") / 2) * 1000;
 
 function setLastSync(lastSyncValue) {
   Svc.Prefs.set("lastSync", (new Date(Date.now() - lastSyncValue)).toString());
 }
 
 // This relies on Service/ErrorHandler being a singleton. Fixing this will take
 // a lot of work.
 var errorHandler = Service.errorHandler;
 let engine;
 
+async function syncAndWait(topic) {
+  let promise1 = promiseOneObserver(topic);
+  // also wait for the log file to be written
+  let promise2 = promiseOneObserver("weave:service:reset-file-log");
+  await Service.sync();
+  await promise1;
+  await promise2;
+}
+
+async function syncAndReportErrorsAndWait(topic) {
+  let promise1 = promiseOneObserver(topic);
+  // also wait for the log file to be written
+  let promise2 = promiseOneObserver("weave:service:reset-file-log");
+  errorHandler.syncAndReportErrors();
+  await promise1;
+  await promise2;
+}
 add_task(async function setup() {
   initTestLogging("Trace");
 
   Log.repository.getLogger("Sync.Service").level = Log.Level.Trace;
   Log.repository.getLogger("Sync.SyncScheduler").level = Log.Level.Trace;
   Log.repository.getLogger("Sync.ErrorHandler").level = Log.Level.Trace;
+  Log.repository.getLogger("Sync.LogManager").level = Log.Level.Trace;
 
   Service.engineManager.clear();
   await Service.engineManager.register(EHTestsCommon.CatapultEngine);
   engine = Service.engineManager.get("catapult");
 });
 
 async function clean() {
+  let promiseLogReset = promiseOneObserver("weave:service:reset-file-log");
   await Service.startOver();
+  await promiseLogReset;
   Status.resetSync();
   Status.resetBackoff();
   errorHandler.didReportProlongedError = false;
+  removeLogFiles();
 }
 
 add_task(async function test_crypto_keys_login_server_maintenance_error() {
   enableValidationPrefs();
 
   Status.resetSync();
   // Test crypto/keys server maintenance errors are not reported.
   let server = await EHTestsCommon.sync_httpd_setup();
@@ -82,21 +120,18 @@ add_task(async function test_crypto_keys
   function onUIUpdate() {
     do_throw("Shouldn't get here!");
   }
   Svc.Obs.add("weave:ui:login:error", onUIUpdate);
 
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
-  let promiseObserved = promiseOneObserver("weave:ui:clear-error");
-
   setLastSync(NON_PROLONGED_ERROR_DURATION);
-  await Service.sync();
-  await promiseObserved;
+  await syncAndWait("weave:ui:clear-error");
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   do_check_false(errorHandler.didReportProlongedError);
 
   Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
@@ -145,24 +180,21 @@ add_task(async function test_info_collec
   await configureIdentity({username: "broken.info"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  await Service.sync();
-  await promiseObserved;
+  await syncAndWait("weave:ui:login:error");
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, SYNC_FAILED);
   do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
   do_check_true(errorHandler.didReportProlongedError);
 
   await clean();
@@ -179,24 +211,21 @@ add_task(async function test_meta_global
   await configureIdentity({username: "broken.meta"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  await Service.sync();
-  await promiseObserved;
+  await syncAndWait("weave:ui:login:error");
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, SYNC_FAILED);
   do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
   do_check_true(errorHandler.didReportProlongedError);
 
   await clean();
@@ -215,24 +244,21 @@ add_task(async function test_download_cr
   Service.collectionKeys.clear();
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  await Service.sync();
-  await promiseObserved;
+  await syncAndWait("weave:ui:login:error");
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, SYNC_FAILED);
   do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
   do_check_true(errorHandler.didReportProlongedError);
 
   await clean();
   await promiseStopServer(server);
@@ -248,24 +274,21 @@ add_task(async function test_upload_cryp
   await configureIdentity({username: "broken.keys"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  await Service.sync();
-  await promiseObserved;
+  await syncAndWait("weave:ui:login:error");
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, SYNC_FAILED);
   do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
   do_check_true(errorHandler.didReportProlongedError);
 
   await clean();
@@ -283,24 +306,21 @@ add_task(async function test_wipeServer_
   await configureIdentity({username: "broken.wipe"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  await Service.sync();
-  await promiseObserved;
+  await syncAndWait("weave:ui:login:error");
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, SYNC_FAILED);
   do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
   do_check_true(errorHandler.didReportProlongedError);
 
   await clean();
@@ -356,23 +376,20 @@ add_task(async function test_sync_syncAn
   let server = await EHTestsCommon.sync_httpd_setup();
   await EHTestsCommon.setUp(server);
 
   const BACKOFF = 42;
   engine.enabled = true;
   engine.exception = {status: 503,
                       headers: {"retry-after": BACKOFF}};
 
-  let promiseObserved = promiseOneObserver("weave:ui:sync:error");
-
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(NON_PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:sync:error")
 
   do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
   do_check_eq(Status.sync, SERVER_MAINTENANCE);
   do_check_false(errorHandler.didReportProlongedError);
 
   await clean();
   await promiseStopServer(server);
 });
@@ -388,24 +405,21 @@ add_task(async function test_info_collec
   await configureIdentity({username: "broken.info"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(NON_PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   do_check_false(errorHandler.didReportProlongedError);
 
   await clean();
@@ -423,24 +437,21 @@ add_task(async function test_meta_global
   await configureIdentity({username: "broken.meta"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(NON_PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   do_check_false(errorHandler.didReportProlongedError);
 
   await clean();
@@ -460,24 +471,21 @@ add_task(async function test_download_cr
   Service.collectionKeys.clear();
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(NON_PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   do_check_false(errorHandler.didReportProlongedError);
 
   await clean();
@@ -495,24 +503,21 @@ add_task(async function test_upload_cryp
   await configureIdentity({username: "broken.keys"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(NON_PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   do_check_false(errorHandler.didReportProlongedError);
 
   await clean();
@@ -530,24 +535,21 @@ add_task(async function test_wipeServer_
   await configureIdentity({username: "broken.wipe"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(NON_PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   do_check_false(errorHandler.didReportProlongedError);
 
   await clean();
@@ -568,25 +570,22 @@ add_task(async function test_wipeRemote_
   engine.enabled = true;
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:sync:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   Svc.Prefs.set("firstSync", "wipeRemote");
   setLastSync(NON_PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:sync:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, SYNC_FAILED);
   do_check_eq(Status.sync, SERVER_MAINTENANCE);
   do_check_eq(Svc.Prefs.get("firstSync"), "wipeRemote");
   do_check_false(errorHandler.didReportProlongedError);
 
@@ -602,23 +601,20 @@ add_task(async function test_sync_syncAn
   let server = await EHTestsCommon.sync_httpd_setup();
   await EHTestsCommon.setUp(server);
 
   const BACKOFF = 42;
   engine.enabled = true;
   engine.exception = {status: 503,
                       headers: {"retry-after": BACKOFF}};
 
-  let promiseObserved = promiseOneObserver("weave:ui:sync:error");
-
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:sync:error")
 
   do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
   do_check_eq(Status.sync, SERVER_MAINTENANCE);
   // syncAndReportErrors means dontIgnoreErrors, which means
   // didReportProlongedError not touched.
   do_check_false(errorHandler.didReportProlongedError);
 
   await clean();
@@ -636,24 +632,21 @@ add_task(async function test_info_collec
   await configureIdentity({username: "broken.info"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   // syncAndReportErrors means dontIgnoreErrors, which means
   // didReportProlongedError not touched.
   do_check_false(errorHandler.didReportProlongedError);
@@ -673,24 +666,21 @@ add_task(async function test_meta_global
   await configureIdentity({username: "broken.meta"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   // syncAndReportErrors means dontIgnoreErrors, which means
   // didReportProlongedError not touched.
   do_check_false(errorHandler.didReportProlongedError);
@@ -712,24 +702,21 @@ add_task(async function test_download_cr
   Service.collectionKeys.clear();
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   // syncAndReportErrors means dontIgnoreErrors, which means
   // didReportProlongedError not touched.
   do_check_false(errorHandler.didReportProlongedError);
@@ -749,24 +736,21 @@ add_task(async function test_upload_cryp
   await configureIdentity({username: "broken.keys"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   // syncAndReportErrors means dontIgnoreErrors, which means
   // didReportProlongedError not touched.
   do_check_false(errorHandler.didReportProlongedError);
@@ -786,40 +770,39 @@ add_task(async function test_wipeServer_
   await configureIdentity({username: "broken.wipe"}, server);
 
   let backoffInterval;
   Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
     Svc.Obs.remove("weave:service:backoff:interval", observe);
     backoffInterval = subject;
   });
 
-  let promiseObserved = promiseOneObserver("weave:ui:login:error");
-
   do_check_false(Status.enforceBackoff);
   do_check_eq(Status.service, STATUS_OK);
 
   setLastSync(PROLONGED_ERROR_DURATION);
-  errorHandler.syncAndReportErrors();
-  await promiseObserved;
+  await syncAndReportErrorsAndWait("weave:ui:login:error")
 
   do_check_true(Status.enforceBackoff);
   do_check_eq(backoffInterval, 42);
   do_check_eq(Status.service, LOGIN_FAILED);
   do_check_eq(Status.login, SERVER_MAINTENANCE);
   // syncAndReportErrors means dontIgnoreErrors, which means
   // didReportProlongedError not touched.
   do_check_false(errorHandler.didReportProlongedError);
 
   await clean();
   await promiseStopServer(server);
 });
 
 add_task(async function test_sync_engine_generic_fail() {
   enableValidationPrefs();
 
+  equal(getLogFiles().length, 0);
+
   let server = await EHTestsCommon.sync_httpd_setup();
   engine.enabled = true;
   engine.sync = async function sync() {
     Svc.Obs.notify("weave:engine:sync:error", ENGINE_UNKNOWN_FAIL, "catapult");
   };
 
   let log = Log.repository.getLogger("Sync.ErrorHandler");
   Svc.Prefs.set("log.appender.file.logOnError", true);
@@ -845,20 +828,19 @@ add_task(async function test_sync_engine
 
   await promiseObserved;
 
   _("Status.engines: " + JSON.stringify(Status.engines));
   do_check_eq(Status.engines["catapult"], ENGINE_UNKNOWN_FAIL);
   do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
 
   // Test Error log was written on SYNC_FAILED_PARTIAL.
-  let entries = logsdir.directoryEntries;
-  do_check_true(entries.hasMoreElements());
-  let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
-  do_check_true(logfile.leafName.startsWith("error-sync-"), logfile.leafName);
+  let logFiles = getLogFiles();
+  equal(logFiles.length, 1);
+  do_check_true(logFiles[0].leafName.startsWith("error-sync-"), logFiles[0].leafName);
 
   await clean();
 
   let syncErrors = sumHistogram("WEAVE_ENGINE_SYNC_ERRORS", { key: "catapult" });
   do_check_true(syncErrors, 1);
 
   await clean();
   await promiseStopServer(server);
@@ -878,20 +860,19 @@ add_task(async function test_logs_on_syn
   Status.login = MASTER_PASSWORD_LOCKED;
   do_check_false(errorHandler.shouldReportError());
 
   let promiseObserved = promiseOneObserver("weave:service:reset-file-log");
   Svc.Obs.notify("weave:service:sync:error", {});
   await promiseObserved;
 
   // Test that error log was written.
-  let entries = logsdir.directoryEntries;
-  do_check_true(entries.hasMoreElements());
-  let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
-  do_check_true(logfile.leafName.startsWith("error-sync-"), logfile.leafName);
+  let logFiles = getLogFiles();
+  equal(logFiles.length, 1);
+  do_check_true(logFiles[0].leafName.startsWith("error-sync-"), logFiles[0].leafName);
 
   await clean();
 });
 
 add_task(async function test_logs_on_login_error_despite_shouldReportError() {
   enableValidationPrefs();
 
   _("Ensure that an error is still logged when weave:service:login:error " +
@@ -905,20 +886,19 @@ add_task(async function test_logs_on_log
   Status.login = MASTER_PASSWORD_LOCKED;
   do_check_false(errorHandler.shouldReportError());
 
   let promiseObserved = promiseOneObserver("weave:service:reset-file-log");
   Svc.Obs.notify("weave:service:login:error", {});
   await promiseObserved;
 
   // Test that error log was written.
-  let entries = logsdir.directoryEntries;
-  do_check_true(entries.hasMoreElements());
-  let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
-  do_check_true(logfile.leafName.startsWith("error-sync-"), logfile.leafName);
+  let logFiles = getLogFiles();
+  equal(logFiles.length, 1);
+  do_check_true(logFiles[0].leafName.startsWith("error-sync-"), logFiles[0].leafName);
 
   await clean();
 });
 
 // This test should be the last one since it monkeypatches the engine object
 // and we should only have one engine object throughout the file (bug 629664).
 add_task(async function test_engine_applyFailed() {
   enableValidationPrefs();
@@ -939,16 +919,15 @@ add_task(async function test_engine_appl
   do_check_true(await EHTestsCommon.setUp(server));
   await Service.sync();
   await promiseObserved;
 
   do_check_eq(Status.engines["catapult"], ENGINE_APPLY_FAIL);
   do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
 
   // Test Error log was written on SYNC_FAILED_PARTIAL.
-  let entries = logsdir.directoryEntries;
-  do_check_true(entries.hasMoreElements());
-  let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
-  do_check_true(logfile.leafName.startsWith("error-sync-"), logfile.leafName);
+  let logFiles = getLogFiles();
+  equal(logFiles.length, 1);
+  do_check_true(logFiles[0].leafName.startsWith("error-sync-"), logFiles[0].leafName);
 
   await clean();
   await promiseStopServer(server);
 });