services/sync/tests/unit/test_errorhandler.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 Cu.import("resource://services-sync/engines/clients.js");
michael@0 5 Cu.import("resource://services-sync/constants.js");
michael@0 6 Cu.import("resource://services-sync/engines.js");
michael@0 7 Cu.import("resource://services-sync/keys.js");
michael@0 8 Cu.import("resource://services-sync/policies.js");
michael@0 9 Cu.import("resource://services-sync/service.js");
michael@0 10 Cu.import("resource://services-sync/status.js");
michael@0 11 Cu.import("resource://services-sync/util.js");
michael@0 12 Cu.import("resource://testing-common/services/sync/utils.js");
michael@0 13 Cu.import("resource://gre/modules/FileUtils.jsm");
michael@0 14
michael@0 15 const FAKE_SERVER_URL = "http://dummy:9000/";
michael@0 16 const logsdir = FileUtils.getDir("ProfD", ["weave", "logs"], true);
michael@0 17 const LOG_PREFIX_SUCCESS = "success-";
michael@0 18 const LOG_PREFIX_ERROR = "error-";
michael@0 19
michael@0 20 const PROLONGED_ERROR_DURATION =
michael@0 21 (Svc.Prefs.get('errorhandler.networkFailureReportTimeout') * 2) * 1000;
michael@0 22
michael@0 23 const NON_PROLONGED_ERROR_DURATION =
michael@0 24 (Svc.Prefs.get('errorhandler.networkFailureReportTimeout') / 2) * 1000;
michael@0 25
michael@0 26 Service.engineManager.clear();
michael@0 27
michael@0 28 function setLastSync(lastSyncValue) {
michael@0 29 Svc.Prefs.set("lastSync", (new Date(Date.now() - lastSyncValue)).toString());
michael@0 30 }
michael@0 31
michael@0 32 function CatapultEngine() {
michael@0 33 SyncEngine.call(this, "Catapult", Service);
michael@0 34 }
michael@0 35 CatapultEngine.prototype = {
michael@0 36 __proto__: SyncEngine.prototype,
michael@0 37 exception: null, // tests fill this in
michael@0 38 _sync: function _sync() {
michael@0 39 if (this.exception) {
michael@0 40 throw this.exception;
michael@0 41 }
michael@0 42 }
michael@0 43 };
michael@0 44
michael@0 45 let engineManager = Service.engineManager;
michael@0 46 engineManager.register(CatapultEngine);
michael@0 47
michael@0 48 // This relies on Service/ErrorHandler being a singleton. Fixing this will take
michael@0 49 // a lot of work.
michael@0 50 let errorHandler = Service.errorHandler;
michael@0 51
michael@0 52 function run_test() {
michael@0 53 initTestLogging("Trace");
michael@0 54
michael@0 55 Log.repository.getLogger("Sync.Service").level = Log.Level.Trace;
michael@0 56 Log.repository.getLogger("Sync.SyncScheduler").level = Log.Level.Trace;
michael@0 57 Log.repository.getLogger("Sync.ErrorHandler").level = Log.Level.Trace;
michael@0 58
michael@0 59 ensureLegacyIdentityManager();
michael@0 60
michael@0 61 run_next_test();
michael@0 62 }
michael@0 63
michael@0 64 function generateCredentialsChangedFailure() {
michael@0 65 // Make sync fail due to changed credentials. We simply re-encrypt
michael@0 66 // the keys with a different Sync Key, without changing the local one.
michael@0 67 let newSyncKeyBundle = new SyncKeyBundle("johndoe", "23456234562345623456234562");
michael@0 68 let keys = Service.collectionKeys.asWBO();
michael@0 69 keys.encrypt(newSyncKeyBundle);
michael@0 70 keys.upload(Service.resource(Service.cryptoKeysURL));
michael@0 71 }
michael@0 72
michael@0 73 function service_unavailable(request, response) {
michael@0 74 let body = "Service Unavailable";
michael@0 75 response.setStatusLine(request.httpVersion, 503, "Service Unavailable");
michael@0 76 response.setHeader("Retry-After", "42");
michael@0 77 response.bodyOutputStream.write(body, body.length);
michael@0 78 }
michael@0 79
michael@0 80 function sync_httpd_setup() {
michael@0 81 let global = new ServerWBO("global", {
michael@0 82 syncID: Service.syncID,
michael@0 83 storageVersion: STORAGE_VERSION,
michael@0 84 engines: {clients: {version: Service.clientsEngine.version,
michael@0 85 syncID: Service.clientsEngine.syncID},
michael@0 86 catapult: {version: engineManager.get("catapult").version,
michael@0 87 syncID: engineManager.get("catapult").syncID}}
michael@0 88 });
michael@0 89 let clientsColl = new ServerCollection({}, true);
michael@0 90
michael@0 91 // Tracking info/collections.
michael@0 92 let collectionsHelper = track_collections_helper();
michael@0 93 let upd = collectionsHelper.with_updated_collection;
michael@0 94
michael@0 95 let handler_401 = httpd_handler(401, "Unauthorized");
michael@0 96 return httpd_setup({
michael@0 97 // Normal server behaviour.
michael@0 98 "/1.1/johndoe/storage/meta/global": upd("meta", global.handler()),
michael@0 99 "/1.1/johndoe/info/collections": collectionsHelper.handler,
michael@0 100 "/1.1/johndoe/storage/crypto/keys":
michael@0 101 upd("crypto", (new ServerWBO("keys")).handler()),
michael@0 102 "/1.1/johndoe/storage/clients": upd("clients", clientsColl.handler()),
michael@0 103
michael@0 104 // Credentials are wrong or node reallocated.
michael@0 105 "/1.1/janedoe/storage/meta/global": handler_401,
michael@0 106 "/1.1/janedoe/info/collections": handler_401,
michael@0 107
michael@0 108 // Maintenance or overloaded (503 + Retry-After) at info/collections.
michael@0 109 "/maintenance/1.1/broken.info/info/collections": service_unavailable,
michael@0 110
michael@0 111 // Maintenance or overloaded (503 + Retry-After) at meta/global.
michael@0 112 "/maintenance/1.1/broken.meta/storage/meta/global": service_unavailable,
michael@0 113 "/maintenance/1.1/broken.meta/info/collections": collectionsHelper.handler,
michael@0 114
michael@0 115 // Maintenance or overloaded (503 + Retry-After) at crypto/keys.
michael@0 116 "/maintenance/1.1/broken.keys/storage/meta/global": upd("meta", global.handler()),
michael@0 117 "/maintenance/1.1/broken.keys/info/collections": collectionsHelper.handler,
michael@0 118 "/maintenance/1.1/broken.keys/storage/crypto/keys": service_unavailable,
michael@0 119
michael@0 120 // Maintenance or overloaded (503 + Retry-After) at wiping collection.
michael@0 121 "/maintenance/1.1/broken.wipe/info/collections": collectionsHelper.handler,
michael@0 122 "/maintenance/1.1/broken.wipe/storage/meta/global": upd("meta", global.handler()),
michael@0 123 "/maintenance/1.1/broken.wipe/storage/crypto/keys":
michael@0 124 upd("crypto", (new ServerWBO("keys")).handler()),
michael@0 125 "/maintenance/1.1/broken.wipe/storage": service_unavailable,
michael@0 126 "/maintenance/1.1/broken.wipe/storage/clients": upd("clients", clientsColl.handler()),
michael@0 127 "/maintenance/1.1/broken.wipe/storage/catapult": service_unavailable
michael@0 128 });
michael@0 129 }
michael@0 130
michael@0 131 function setUp(server) {
michael@0 132 return configureIdentity({username: "johndoe"}).then(
michael@0 133 () => {
michael@0 134 Service.serverURL = server.baseURI + "/";
michael@0 135 Service.clusterURL = server.baseURI + "/";
michael@0 136 }
michael@0 137 ).then(
michael@0 138 () => generateAndUploadKeys()
michael@0 139 );
michael@0 140 }
michael@0 141
michael@0 142 function generateAndUploadKeys() {
michael@0 143 generateNewKeys(Service.collectionKeys);
michael@0 144 let serverKeys = Service.collectionKeys.asWBO("crypto", "keys");
michael@0 145 serverKeys.encrypt(Service.identity.syncKeyBundle);
michael@0 146 return serverKeys.upload(Service.resource(Service.cryptoKeysURL)).success;
michael@0 147 }
michael@0 148
michael@0 149 function clean() {
michael@0 150 Service.startOver();
michael@0 151 Status.resetSync();
michael@0 152 Status.resetBackoff();
michael@0 153 errorHandler.didReportProlongedError = false;
michael@0 154 }
michael@0 155
michael@0 156 add_identity_test(this, function test_401_logout() {
michael@0 157 let server = sync_httpd_setup();
michael@0 158 yield setUp(server);
michael@0 159
michael@0 160 // By calling sync, we ensure we're logged in.
michael@0 161 Service.sync();
michael@0 162 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 163 do_check_true(Service.isLoggedIn);
michael@0 164
michael@0 165 let deferred = Promise.defer();
michael@0 166 Svc.Obs.add("weave:service:sync:error", onSyncError);
michael@0 167 function onSyncError() {
michael@0 168 _("Got weave:service:sync:error in first sync.");
michael@0 169 Svc.Obs.remove("weave:service:sync:error", onSyncError);
michael@0 170
michael@0 171 // Wait for the automatic next sync.
michael@0 172 function onLoginError() {
michael@0 173 _("Got weave:service:login:error in second sync.");
michael@0 174 Svc.Obs.remove("weave:service:login:error", onLoginError);
michael@0 175
michael@0 176 do_check_eq(Status.login, LOGIN_FAILED_LOGIN_REJECTED);
michael@0 177 do_check_false(Service.isLoggedIn);
michael@0 178
michael@0 179 // Clean up.
michael@0 180 Utils.nextTick(function () {
michael@0 181 Service.startOver();
michael@0 182 server.stop(deferred.resolve);
michael@0 183 });
michael@0 184 }
michael@0 185 Svc.Obs.add("weave:service:login:error", onLoginError);
michael@0 186 }
michael@0 187
michael@0 188 // Make sync fail due to login rejected.
michael@0 189 yield configureIdentity({username: "janedoe"});
michael@0 190 Service._updateCachedURLs();
michael@0 191
michael@0 192 _("Starting first sync.");
michael@0 193 Service.sync();
michael@0 194 _("First sync done.");
michael@0 195 yield deferred.promise;
michael@0 196 });
michael@0 197
michael@0 198 add_identity_test(this, function test_credentials_changed_logout() {
michael@0 199 let server = sync_httpd_setup();
michael@0 200 yield setUp(server);
michael@0 201
michael@0 202 // By calling sync, we ensure we're logged in.
michael@0 203 Service.sync();
michael@0 204 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 205 do_check_true(Service.isLoggedIn);
michael@0 206
michael@0 207 generateCredentialsChangedFailure();
michael@0 208 Service.sync();
michael@0 209
michael@0 210 do_check_eq(Status.sync, CREDENTIALS_CHANGED);
michael@0 211 do_check_false(Service.isLoggedIn);
michael@0 212
michael@0 213 // Clean up.
michael@0 214 Service.startOver();
michael@0 215 let deferred = Promise.defer();
michael@0 216 server.stop(deferred.resolve);
michael@0 217 yield deferred.promise;
michael@0 218 });
michael@0 219
michael@0 220 add_identity_test(this, function test_no_lastSync_pref() {
michael@0 221 // Test reported error.
michael@0 222 Status.resetSync();
michael@0 223 errorHandler.dontIgnoreErrors = true;
michael@0 224 Status.sync = CREDENTIALS_CHANGED;
michael@0 225 do_check_true(errorHandler.shouldReportError());
michael@0 226
michael@0 227 // Test unreported error.
michael@0 228 Status.resetSync();
michael@0 229 errorHandler.dontIgnoreErrors = true;
michael@0 230 Status.login = LOGIN_FAILED_NETWORK_ERROR;
michael@0 231 do_check_true(errorHandler.shouldReportError());
michael@0 232
michael@0 233 });
michael@0 234
michael@0 235 add_identity_test(this, function test_shouldReportError() {
michael@0 236 Status.login = MASTER_PASSWORD_LOCKED;
michael@0 237 do_check_false(errorHandler.shouldReportError());
michael@0 238
michael@0 239 // Give ourselves a clusterURL so that the temporary 401 no-error situation
michael@0 240 // doesn't come into play.
michael@0 241 Service.serverURL = FAKE_SERVER_URL;
michael@0 242 Service.clusterURL = FAKE_SERVER_URL;
michael@0 243
michael@0 244 // Test dontIgnoreErrors, non-network, non-prolonged, login error reported
michael@0 245 Status.resetSync();
michael@0 246 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 247 errorHandler.dontIgnoreErrors = true;
michael@0 248 Status.login = LOGIN_FAILED_NO_PASSWORD;
michael@0 249 do_check_true(errorHandler.shouldReportError());
michael@0 250
michael@0 251 // Test dontIgnoreErrors, non-network, non-prolonged, sync error reported
michael@0 252 Status.resetSync();
michael@0 253 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 254 errorHandler.dontIgnoreErrors = true;
michael@0 255 Status.sync = CREDENTIALS_CHANGED;
michael@0 256 do_check_true(errorHandler.shouldReportError());
michael@0 257
michael@0 258 // Test dontIgnoreErrors, non-network, prolonged, login error reported
michael@0 259 Status.resetSync();
michael@0 260 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 261 errorHandler.dontIgnoreErrors = true;
michael@0 262 Status.login = LOGIN_FAILED_NO_PASSWORD;
michael@0 263 do_check_true(errorHandler.shouldReportError());
michael@0 264
michael@0 265 // Test dontIgnoreErrors, non-network, prolonged, sync error reported
michael@0 266 Status.resetSync();
michael@0 267 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 268 errorHandler.dontIgnoreErrors = true;
michael@0 269 Status.sync = CREDENTIALS_CHANGED;
michael@0 270 do_check_true(errorHandler.shouldReportError());
michael@0 271
michael@0 272 // Test dontIgnoreErrors, network, non-prolonged, login error reported
michael@0 273 Status.resetSync();
michael@0 274 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 275 errorHandler.dontIgnoreErrors = true;
michael@0 276 Status.login = LOGIN_FAILED_NETWORK_ERROR;
michael@0 277 do_check_true(errorHandler.shouldReportError());
michael@0 278
michael@0 279 // Test dontIgnoreErrors, network, non-prolonged, sync error reported
michael@0 280 Status.resetSync();
michael@0 281 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 282 errorHandler.dontIgnoreErrors = true;
michael@0 283 Status.sync = LOGIN_FAILED_NETWORK_ERROR;
michael@0 284 do_check_true(errorHandler.shouldReportError());
michael@0 285
michael@0 286 // Test dontIgnoreErrors, network, prolonged, login error reported
michael@0 287 Status.resetSync();
michael@0 288 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 289 errorHandler.dontIgnoreErrors = true;
michael@0 290 Status.login = LOGIN_FAILED_NETWORK_ERROR;
michael@0 291 do_check_true(errorHandler.shouldReportError());
michael@0 292
michael@0 293 // Test dontIgnoreErrors, network, prolonged, sync error reported
michael@0 294 Status.resetSync();
michael@0 295 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 296 errorHandler.dontIgnoreErrors = true;
michael@0 297 Status.sync = LOGIN_FAILED_NETWORK_ERROR;
michael@0 298 do_check_true(errorHandler.shouldReportError());
michael@0 299
michael@0 300 // Test non-network, prolonged, login error reported
michael@0 301 do_check_false(errorHandler.didReportProlongedError);
michael@0 302 Status.resetSync();
michael@0 303 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 304 errorHandler.dontIgnoreErrors = false;
michael@0 305 Status.login = LOGIN_FAILED_NO_PASSWORD;
michael@0 306 do_check_true(errorHandler.shouldReportError());
michael@0 307 do_check_true(errorHandler.didReportProlongedError);
michael@0 308
michael@0 309 // Second time with prolonged error and without resetting
michael@0 310 // didReportProlongedError, sync error should not be reported.
michael@0 311 Status.resetSync();
michael@0 312 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 313 errorHandler.dontIgnoreErrors = false;
michael@0 314 Status.login = LOGIN_FAILED_NO_PASSWORD;
michael@0 315 do_check_false(errorHandler.shouldReportError());
michael@0 316 do_check_true(errorHandler.didReportProlongedError);
michael@0 317
michael@0 318 // Test non-network, prolonged, sync error reported
michael@0 319 Status.resetSync();
michael@0 320 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 321 errorHandler.dontIgnoreErrors = false;
michael@0 322 errorHandler.didReportProlongedError = false;
michael@0 323 Status.sync = CREDENTIALS_CHANGED;
michael@0 324 do_check_true(errorHandler.shouldReportError());
michael@0 325 do_check_true(errorHandler.didReportProlongedError);
michael@0 326 errorHandler.didReportProlongedError = false;
michael@0 327
michael@0 328 // Test network, prolonged, login error reported
michael@0 329 Status.resetSync();
michael@0 330 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 331 errorHandler.dontIgnoreErrors = false;
michael@0 332 Status.login = LOGIN_FAILED_NETWORK_ERROR;
michael@0 333 do_check_true(errorHandler.shouldReportError());
michael@0 334 do_check_true(errorHandler.didReportProlongedError);
michael@0 335 errorHandler.didReportProlongedError = false;
michael@0 336
michael@0 337 // Test network, prolonged, sync error reported
michael@0 338 Status.resetSync();
michael@0 339 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 340 errorHandler.dontIgnoreErrors = false;
michael@0 341 Status.sync = LOGIN_FAILED_NETWORK_ERROR;
michael@0 342 do_check_true(errorHandler.shouldReportError());
michael@0 343 do_check_true(errorHandler.didReportProlongedError);
michael@0 344 errorHandler.didReportProlongedError = false;
michael@0 345
michael@0 346 // Test non-network, non-prolonged, login error reported
michael@0 347 Status.resetSync();
michael@0 348 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 349 errorHandler.dontIgnoreErrors = false;
michael@0 350 Status.login = LOGIN_FAILED_NO_PASSWORD;
michael@0 351 do_check_true(errorHandler.shouldReportError());
michael@0 352 do_check_false(errorHandler.didReportProlongedError);
michael@0 353
michael@0 354 // Test non-network, non-prolonged, sync error reported
michael@0 355 Status.resetSync();
michael@0 356 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 357 errorHandler.dontIgnoreErrors = false;
michael@0 358 Status.sync = CREDENTIALS_CHANGED;
michael@0 359 do_check_true(errorHandler.shouldReportError());
michael@0 360 do_check_false(errorHandler.didReportProlongedError);
michael@0 361
michael@0 362 // Test network, non-prolonged, login error reported
michael@0 363 Status.resetSync();
michael@0 364 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 365 errorHandler.dontIgnoreErrors = false;
michael@0 366 Status.login = LOGIN_FAILED_NETWORK_ERROR;
michael@0 367 do_check_false(errorHandler.shouldReportError());
michael@0 368 do_check_false(errorHandler.didReportProlongedError);
michael@0 369
michael@0 370 // Test network, non-prolonged, sync error reported
michael@0 371 Status.resetSync();
michael@0 372 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 373 errorHandler.dontIgnoreErrors = false;
michael@0 374 Status.sync = LOGIN_FAILED_NETWORK_ERROR;
michael@0 375 do_check_false(errorHandler.shouldReportError());
michael@0 376 do_check_false(errorHandler.didReportProlongedError);
michael@0 377
michael@0 378 // Test server maintenance, sync errors are not reported
michael@0 379 Status.resetSync();
michael@0 380 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 381 errorHandler.dontIgnoreErrors = false;
michael@0 382 Status.sync = SERVER_MAINTENANCE;
michael@0 383 do_check_false(errorHandler.shouldReportError());
michael@0 384 do_check_false(errorHandler.didReportProlongedError);
michael@0 385
michael@0 386 // Test server maintenance, login errors are not reported
michael@0 387 Status.resetSync();
michael@0 388 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 389 errorHandler.dontIgnoreErrors = false;
michael@0 390 Status.login = SERVER_MAINTENANCE;
michael@0 391 do_check_false(errorHandler.shouldReportError());
michael@0 392 do_check_false(errorHandler.didReportProlongedError);
michael@0 393
michael@0 394 // Test prolonged, server maintenance, sync errors are reported
michael@0 395 Status.resetSync();
michael@0 396 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 397 errorHandler.dontIgnoreErrors = false;
michael@0 398 Status.sync = SERVER_MAINTENANCE;
michael@0 399 do_check_true(errorHandler.shouldReportError());
michael@0 400 do_check_true(errorHandler.didReportProlongedError);
michael@0 401 errorHandler.didReportProlongedError = false;
michael@0 402
michael@0 403 // Test prolonged, server maintenance, login errors are reported
michael@0 404 Status.resetSync();
michael@0 405 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 406 errorHandler.dontIgnoreErrors = false;
michael@0 407 Status.login = SERVER_MAINTENANCE;
michael@0 408 do_check_true(errorHandler.shouldReportError());
michael@0 409 do_check_true(errorHandler.didReportProlongedError);
michael@0 410 errorHandler.didReportProlongedError = false;
michael@0 411
michael@0 412 // Test dontIgnoreErrors, server maintenance, sync errors are reported
michael@0 413 Status.resetSync();
michael@0 414 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 415 errorHandler.dontIgnoreErrors = true;
michael@0 416 Status.sync = SERVER_MAINTENANCE;
michael@0 417 do_check_true(errorHandler.shouldReportError());
michael@0 418 // dontIgnoreErrors means we don't set didReportProlongedError
michael@0 419 do_check_false(errorHandler.didReportProlongedError);
michael@0 420
michael@0 421 // Test dontIgnoreErrors, server maintenance, login errors are reported
michael@0 422 Status.resetSync();
michael@0 423 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 424 errorHandler.dontIgnoreErrors = true;
michael@0 425 Status.login = SERVER_MAINTENANCE;
michael@0 426 do_check_true(errorHandler.shouldReportError());
michael@0 427 do_check_false(errorHandler.didReportProlongedError);
michael@0 428
michael@0 429 // Test dontIgnoreErrors, prolonged, server maintenance,
michael@0 430 // sync errors are reported
michael@0 431 Status.resetSync();
michael@0 432 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 433 errorHandler.dontIgnoreErrors = true;
michael@0 434 Status.sync = SERVER_MAINTENANCE;
michael@0 435 do_check_true(errorHandler.shouldReportError());
michael@0 436 do_check_false(errorHandler.didReportProlongedError);
michael@0 437
michael@0 438 // Test dontIgnoreErrors, prolonged, server maintenance,
michael@0 439 // login errors are reported
michael@0 440 Status.resetSync();
michael@0 441 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 442 errorHandler.dontIgnoreErrors = true;
michael@0 443 Status.login = SERVER_MAINTENANCE;
michael@0 444 do_check_true(errorHandler.shouldReportError());
michael@0 445 do_check_false(errorHandler.didReportProlongedError);
michael@0 446 });
michael@0 447
michael@0 448 add_identity_test(this, function test_shouldReportError_master_password() {
michael@0 449 _("Test error ignored due to locked master password");
michael@0 450 let server = sync_httpd_setup();
michael@0 451 yield setUp(server);
michael@0 452
michael@0 453 // Monkey patch Service.verifyLogin to imitate
michael@0 454 // master password being locked.
michael@0 455 Service._verifyLogin = Service.verifyLogin;
michael@0 456 Service.verifyLogin = function () {
michael@0 457 Status.login = MASTER_PASSWORD_LOCKED;
michael@0 458 return false;
michael@0 459 };
michael@0 460
michael@0 461 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 462 Service.sync();
michael@0 463 do_check_false(errorHandler.shouldReportError());
michael@0 464
michael@0 465 // Clean up.
michael@0 466 Service.verifyLogin = Service._verifyLogin;
michael@0 467 clean();
michael@0 468 let deferred = Promise.defer();
michael@0 469 server.stop(deferred.resolve);
michael@0 470 yield deferred.promise;
michael@0 471 });
michael@0 472
michael@0 473 // XXX - how to arrange for 'Service.identity.basicPassword = null;' in
michael@0 474 // an fxaccounts environment?
michael@0 475 add_task(function test_login_syncAndReportErrors_non_network_error() {
michael@0 476 // Test non-network errors are reported
michael@0 477 // when calling syncAndReportErrors
michael@0 478 let server = sync_httpd_setup();
michael@0 479 yield setUp(server);
michael@0 480 Service.identity.basicPassword = null;
michael@0 481
michael@0 482 let deferred = Promise.defer();
michael@0 483 Svc.Obs.add("weave:ui:login:error", function onSyncError() {
michael@0 484 Svc.Obs.remove("weave:ui:login:error", onSyncError);
michael@0 485 do_check_eq(Status.login, LOGIN_FAILED_NO_PASSWORD);
michael@0 486
michael@0 487 clean();
michael@0 488 server.stop(deferred.resolve);
michael@0 489 });
michael@0 490
michael@0 491 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 492 errorHandler.syncAndReportErrors();
michael@0 493 yield deferred.promise;
michael@0 494 });
michael@0 495
michael@0 496 add_identity_test(this, function test_sync_syncAndReportErrors_non_network_error() {
michael@0 497 // Test non-network errors are reported
michael@0 498 // when calling syncAndReportErrors
michael@0 499 let server = sync_httpd_setup();
michael@0 500 yield setUp(server);
michael@0 501
michael@0 502 // By calling sync, we ensure we're logged in.
michael@0 503 Service.sync();
michael@0 504 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 505 do_check_true(Service.isLoggedIn);
michael@0 506
michael@0 507 generateCredentialsChangedFailure();
michael@0 508
michael@0 509 let deferred = Promise.defer();
michael@0 510 Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
michael@0 511 Svc.Obs.remove("weave:ui:sync:error", onSyncError);
michael@0 512 do_check_eq(Status.sync, CREDENTIALS_CHANGED);
michael@0 513
michael@0 514 clean();
michael@0 515 server.stop(deferred.resolve);
michael@0 516 });
michael@0 517
michael@0 518 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 519 errorHandler.syncAndReportErrors();
michael@0 520 yield deferred.promise;
michael@0 521 });
michael@0 522
michael@0 523 // XXX - how to arrange for 'Service.identity.basicPassword = null;' in
michael@0 524 // an fxaccounts environment?
michael@0 525 add_task(function test_login_syncAndReportErrors_prolonged_non_network_error() {
michael@0 526 // Test prolonged, non-network errors are
michael@0 527 // reported when calling syncAndReportErrors.
michael@0 528 let server = sync_httpd_setup();
michael@0 529 yield setUp(server);
michael@0 530 Service.identity.basicPassword = null;
michael@0 531
michael@0 532 let deferred = Promise.defer();
michael@0 533 Svc.Obs.add("weave:ui:login:error", function onSyncError() {
michael@0 534 Svc.Obs.remove("weave:ui:login:error", onSyncError);
michael@0 535 do_check_eq(Status.login, LOGIN_FAILED_NO_PASSWORD);
michael@0 536
michael@0 537 clean();
michael@0 538 server.stop(deferred.resolve);
michael@0 539 });
michael@0 540
michael@0 541 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 542 errorHandler.syncAndReportErrors();
michael@0 543 yield deferred.promise;
michael@0 544 });
michael@0 545
michael@0 546 add_identity_test(this, function test_sync_syncAndReportErrors_prolonged_non_network_error() {
michael@0 547 // Test prolonged, non-network errors are
michael@0 548 // reported when calling syncAndReportErrors.
michael@0 549 let server = sync_httpd_setup();
michael@0 550 yield setUp(server);
michael@0 551
michael@0 552 // By calling sync, we ensure we're logged in.
michael@0 553 Service.sync();
michael@0 554 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 555 do_check_true(Service.isLoggedIn);
michael@0 556
michael@0 557 generateCredentialsChangedFailure();
michael@0 558
michael@0 559 let deferred = Promise.defer();
michael@0 560 Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
michael@0 561 Svc.Obs.remove("weave:ui:sync:error", onSyncError);
michael@0 562 do_check_eq(Status.sync, CREDENTIALS_CHANGED);
michael@0 563
michael@0 564 clean();
michael@0 565 server.stop(deferred.resolve);
michael@0 566 });
michael@0 567
michael@0 568 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 569 errorHandler.syncAndReportErrors();
michael@0 570 yield deferred.promise;
michael@0 571 });
michael@0 572
michael@0 573 add_identity_test(this, function test_login_syncAndReportErrors_network_error() {
michael@0 574 // Test network errors are reported when calling syncAndReportErrors.
michael@0 575 yield configureIdentity({username: "broken.wipe"});
michael@0 576 Service.serverURL = FAKE_SERVER_URL;
michael@0 577 Service.clusterURL = FAKE_SERVER_URL;
michael@0 578
michael@0 579 let deferred = Promise.defer();
michael@0 580 Svc.Obs.add("weave:ui:login:error", function onSyncError() {
michael@0 581 Svc.Obs.remove("weave:ui:login:error", onSyncError);
michael@0 582 do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
michael@0 583
michael@0 584 clean();
michael@0 585 deferred.resolve();
michael@0 586 });
michael@0 587
michael@0 588 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 589 errorHandler.syncAndReportErrors();
michael@0 590 yield deferred.promise;
michael@0 591 });
michael@0 592
michael@0 593
michael@0 594 add_test(function test_sync_syncAndReportErrors_network_error() {
michael@0 595 // Test network errors are reported when calling syncAndReportErrors.
michael@0 596 Services.io.offline = true;
michael@0 597
michael@0 598 Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
michael@0 599 Svc.Obs.remove("weave:ui:sync:error", onSyncError);
michael@0 600 do_check_eq(Status.sync, LOGIN_FAILED_NETWORK_ERROR);
michael@0 601
michael@0 602 Services.io.offline = false;
michael@0 603 clean();
michael@0 604 run_next_test();
michael@0 605 });
michael@0 606
michael@0 607 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 608 errorHandler.syncAndReportErrors();
michael@0 609 });
michael@0 610
michael@0 611 add_identity_test(this, function test_login_syncAndReportErrors_prolonged_network_error() {
michael@0 612 // Test prolonged, network errors are reported
michael@0 613 // when calling syncAndReportErrors.
michael@0 614 yield configureIdentity({username: "johndoe"});
michael@0 615
michael@0 616 Service.serverURL = FAKE_SERVER_URL;
michael@0 617 Service.clusterURL = FAKE_SERVER_URL;
michael@0 618
michael@0 619 let deferred = Promise.defer();
michael@0 620 Svc.Obs.add("weave:ui:login:error", function onSyncError() {
michael@0 621 Svc.Obs.remove("weave:ui:login:error", onSyncError);
michael@0 622 do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
michael@0 623
michael@0 624 clean();
michael@0 625 deferred.resolve();
michael@0 626 });
michael@0 627
michael@0 628 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 629 errorHandler.syncAndReportErrors();
michael@0 630 yield deferred.promise;
michael@0 631 });
michael@0 632
michael@0 633 add_test(function test_sync_syncAndReportErrors_prolonged_network_error() {
michael@0 634 // Test prolonged, network errors are reported
michael@0 635 // when calling syncAndReportErrors.
michael@0 636 Services.io.offline = true;
michael@0 637
michael@0 638 Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
michael@0 639 Svc.Obs.remove("weave:ui:sync:error", onSyncError);
michael@0 640 do_check_eq(Status.sync, LOGIN_FAILED_NETWORK_ERROR);
michael@0 641
michael@0 642 Services.io.offline = false;
michael@0 643 clean();
michael@0 644 run_next_test();
michael@0 645 });
michael@0 646
michael@0 647 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 648 errorHandler.syncAndReportErrors();
michael@0 649 });
michael@0 650
michael@0 651 add_task(function test_login_prolonged_non_network_error() {
michael@0 652 // Test prolonged, non-network errors are reported
michael@0 653 let server = sync_httpd_setup();
michael@0 654 yield setUp(server);
michael@0 655 Service.identity.basicPassword = null;
michael@0 656
michael@0 657 let deferred = Promise.defer();
michael@0 658 Svc.Obs.add("weave:ui:login:error", function onSyncError() {
michael@0 659 Svc.Obs.remove("weave:ui:login:error", onSyncError);
michael@0 660 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 661 do_check_true(errorHandler.didReportProlongedError);
michael@0 662
michael@0 663 clean();
michael@0 664 server.stop(deferred.resolve);
michael@0 665 });
michael@0 666
michael@0 667 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 668 Service.sync();
michael@0 669 yield deferred.promise;
michael@0 670 });
michael@0 671
michael@0 672 add_task(function test_sync_prolonged_non_network_error() {
michael@0 673 // Test prolonged, non-network errors are reported
michael@0 674 let server = sync_httpd_setup();
michael@0 675 yield setUp(server);
michael@0 676
michael@0 677 // By calling sync, we ensure we're logged in.
michael@0 678 Service.sync();
michael@0 679 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 680 do_check_true(Service.isLoggedIn);
michael@0 681
michael@0 682 generateCredentialsChangedFailure();
michael@0 683
michael@0 684 let deferred = Promise.defer();
michael@0 685 Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
michael@0 686 Svc.Obs.remove("weave:ui:sync:error", onSyncError);
michael@0 687 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 688 do_check_true(errorHandler.didReportProlongedError);
michael@0 689
michael@0 690 clean();
michael@0 691 server.stop(deferred.resolve);
michael@0 692 });
michael@0 693
michael@0 694 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 695 Service.sync();
michael@0 696 yield deferred.promise;
michael@0 697 });
michael@0 698
michael@0 699 add_identity_test(this, function test_login_prolonged_network_error() {
michael@0 700 // Test prolonged, network errors are reported
michael@0 701 yield configureIdentity({username: "johndoe"});
michael@0 702 Service.serverURL = FAKE_SERVER_URL;
michael@0 703 Service.clusterURL = FAKE_SERVER_URL;
michael@0 704
michael@0 705 let deferred = Promise.defer();
michael@0 706 Svc.Obs.add("weave:ui:login:error", function onSyncError() {
michael@0 707 Svc.Obs.remove("weave:ui:login:error", onSyncError);
michael@0 708 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 709 do_check_true(errorHandler.didReportProlongedError);
michael@0 710
michael@0 711 clean();
michael@0 712 deferred.resolve();
michael@0 713 });
michael@0 714
michael@0 715 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 716 Service.sync();
michael@0 717 yield deferred.promise;
michael@0 718 });
michael@0 719
michael@0 720 add_test(function test_sync_prolonged_network_error() {
michael@0 721 // Test prolonged, network errors are reported
michael@0 722 Services.io.offline = true;
michael@0 723
michael@0 724 Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
michael@0 725 Svc.Obs.remove("weave:ui:sync:error", onSyncError);
michael@0 726 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 727 do_check_true(errorHandler.didReportProlongedError);
michael@0 728
michael@0 729 Services.io.offline = false;
michael@0 730 clean();
michael@0 731 run_next_test();
michael@0 732 });
michael@0 733
michael@0 734 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 735 Service.sync();
michael@0 736 });
michael@0 737
michael@0 738 add_task(function test_login_non_network_error() {
michael@0 739 // Test non-network errors are reported
michael@0 740 let server = sync_httpd_setup();
michael@0 741 yield setUp(server);
michael@0 742 Service.identity.basicPassword = null;
michael@0 743
michael@0 744 let deferred = Promise.defer();
michael@0 745 Svc.Obs.add("weave:ui:login:error", function onSyncError() {
michael@0 746 Svc.Obs.remove("weave:ui:login:error", onSyncError);
michael@0 747 do_check_eq(Status.login, LOGIN_FAILED_NO_PASSWORD);
michael@0 748 do_check_false(errorHandler.didReportProlongedError);
michael@0 749
michael@0 750 clean();
michael@0 751 server.stop(deferred.resolve);
michael@0 752 });
michael@0 753
michael@0 754 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 755 Service.sync();
michael@0 756 yield deferred.promise;
michael@0 757 });
michael@0 758
michael@0 759 add_task(function test_sync_non_network_error() {
michael@0 760 // Test non-network errors are reported
michael@0 761 let server = sync_httpd_setup();
michael@0 762 yield setUp(server);
michael@0 763
michael@0 764 // By calling sync, we ensure we're logged in.
michael@0 765 Service.sync();
michael@0 766 do_check_eq(Status.sync, SYNC_SUCCEEDED);
michael@0 767 do_check_true(Service.isLoggedIn);
michael@0 768
michael@0 769 generateCredentialsChangedFailure();
michael@0 770
michael@0 771 let deferred = Promise.defer();
michael@0 772 Svc.Obs.add("weave:ui:sync:error", function onSyncError() {
michael@0 773 Svc.Obs.remove("weave:ui:sync:error", onSyncError);
michael@0 774 do_check_eq(Status.sync, CREDENTIALS_CHANGED);
michael@0 775 do_check_false(errorHandler.didReportProlongedError);
michael@0 776
michael@0 777 clean();
michael@0 778 server.stop(deferred.resolve);
michael@0 779 });
michael@0 780
michael@0 781 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 782 Service.sync();
michael@0 783 yield deferred.promise;
michael@0 784 });
michael@0 785
michael@0 786 add_identity_test(this, function test_login_network_error() {
michael@0 787 yield configureIdentity({username: "johndoe"});
michael@0 788 Service.serverURL = FAKE_SERVER_URL;
michael@0 789 Service.clusterURL = FAKE_SERVER_URL;
michael@0 790
michael@0 791 let deferred = Promise.defer();
michael@0 792 // Test network errors are not reported.
michael@0 793 Svc.Obs.add("weave:ui:clear-error", function onClearError() {
michael@0 794 Svc.Obs.remove("weave:ui:clear-error", onClearError);
michael@0 795
michael@0 796 do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
michael@0 797 do_check_false(errorHandler.didReportProlongedError);
michael@0 798
michael@0 799 Services.io.offline = false;
michael@0 800 clean();
michael@0 801 deferred.resolve()
michael@0 802 });
michael@0 803
michael@0 804 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 805 Service.sync();
michael@0 806 yield deferred.promise;
michael@0 807 });
michael@0 808
michael@0 809 add_test(function test_sync_network_error() {
michael@0 810 // Test network errors are not reported.
michael@0 811 Services.io.offline = true;
michael@0 812
michael@0 813 Svc.Obs.add("weave:ui:sync:finish", function onUIUpdate() {
michael@0 814 Svc.Obs.remove("weave:ui:sync:finish", onUIUpdate);
michael@0 815 do_check_eq(Status.sync, LOGIN_FAILED_NETWORK_ERROR);
michael@0 816 do_check_false(errorHandler.didReportProlongedError);
michael@0 817
michael@0 818 Services.io.offline = false;
michael@0 819 clean();
michael@0 820 run_next_test();
michael@0 821 });
michael@0 822
michael@0 823 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 824 Service.sync();
michael@0 825 });
michael@0 826
michael@0 827 add_identity_test(this, function test_sync_server_maintenance_error() {
michael@0 828 // Test server maintenance errors are not reported.
michael@0 829 let server = sync_httpd_setup();
michael@0 830 yield setUp(server);
michael@0 831
michael@0 832 const BACKOFF = 42;
michael@0 833 let engine = engineManager.get("catapult");
michael@0 834 engine.enabled = true;
michael@0 835 engine.exception = {status: 503,
michael@0 836 headers: {"retry-after": BACKOFF}};
michael@0 837
michael@0 838 function onSyncError() {
michael@0 839 do_throw("Shouldn't get here!");
michael@0 840 }
michael@0 841 Svc.Obs.add("weave:ui:sync:error", onSyncError);
michael@0 842
michael@0 843 do_check_eq(Status.service, STATUS_OK);
michael@0 844
michael@0 845 let deferred = Promise.defer();
michael@0 846 Svc.Obs.add("weave:ui:sync:finish", function onSyncFinish() {
michael@0 847 Svc.Obs.remove("weave:ui:sync:finish", onSyncFinish);
michael@0 848
michael@0 849 do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
michael@0 850 do_check_eq(Status.sync, SERVER_MAINTENANCE);
michael@0 851 do_check_false(errorHandler.didReportProlongedError);
michael@0 852
michael@0 853 Svc.Obs.remove("weave:ui:sync:error", onSyncError);
michael@0 854 clean();
michael@0 855 server.stop(deferred.resolve);
michael@0 856 });
michael@0 857
michael@0 858 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 859 Service.sync();
michael@0 860 yield deferred.promise;
michael@0 861 });
michael@0 862
michael@0 863 add_identity_test(this, function test_info_collections_login_server_maintenance_error() {
michael@0 864 // Test info/collections server maintenance errors are not reported.
michael@0 865 let server = sync_httpd_setup();
michael@0 866 yield setUp(server);
michael@0 867
michael@0 868 Service.username = "broken.info";
michael@0 869 yield configureIdentity({username: "broken.info"});
michael@0 870 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 871 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 872
michael@0 873 let backoffInterval;
michael@0 874 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 875 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 876 backoffInterval = subject;
michael@0 877 });
michael@0 878
michael@0 879 function onUIUpdate() {
michael@0 880 do_throw("Shouldn't experience UI update!");
michael@0 881 }
michael@0 882 Svc.Obs.add("weave:ui:login:error", onUIUpdate);
michael@0 883
michael@0 884 do_check_false(Status.enforceBackoff);
michael@0 885 do_check_eq(Status.service, STATUS_OK);
michael@0 886
michael@0 887 let deferred = Promise.defer();
michael@0 888 Svc.Obs.add("weave:ui:clear-error", function onLoginFinish() {
michael@0 889 Svc.Obs.remove("weave:ui:clear-error", onLoginFinish);
michael@0 890
michael@0 891 do_check_true(Status.enforceBackoff);
michael@0 892 do_check_eq(backoffInterval, 42);
michael@0 893 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 894 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 895 do_check_false(errorHandler.didReportProlongedError);
michael@0 896
michael@0 897 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 898 clean();
michael@0 899 server.stop(deferred.resolve);
michael@0 900 });
michael@0 901
michael@0 902 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 903 Service.sync();
michael@0 904 yield deferred.promise;
michael@0 905 });
michael@0 906
michael@0 907 add_identity_test(this, function test_meta_global_login_server_maintenance_error() {
michael@0 908 // Test meta/global server maintenance errors are not reported.
michael@0 909 let server = sync_httpd_setup();
michael@0 910 yield setUp(server);
michael@0 911
michael@0 912 yield configureIdentity({username: "broken.meta"});
michael@0 913 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 914 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 915
michael@0 916 let backoffInterval;
michael@0 917 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 918 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 919 backoffInterval = subject;
michael@0 920 });
michael@0 921
michael@0 922 function onUIUpdate() {
michael@0 923 do_throw("Shouldn't get here!");
michael@0 924 }
michael@0 925 Svc.Obs.add("weave:ui:login:error", onUIUpdate);
michael@0 926
michael@0 927 do_check_false(Status.enforceBackoff);
michael@0 928 do_check_eq(Status.service, STATUS_OK);
michael@0 929
michael@0 930 let deferred = Promise.defer();
michael@0 931 Svc.Obs.add("weave:ui:clear-error", function onLoginFinish() {
michael@0 932 Svc.Obs.remove("weave:ui:clear-error", onLoginFinish);
michael@0 933
michael@0 934 do_check_true(Status.enforceBackoff);
michael@0 935 do_check_eq(backoffInterval, 42);
michael@0 936 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 937 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 938 do_check_false(errorHandler.didReportProlongedError);
michael@0 939
michael@0 940 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 941 clean();
michael@0 942 server.stop(deferred.resolve);
michael@0 943 });
michael@0 944
michael@0 945 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 946 Service.sync();
michael@0 947 yield deferred.promise;
michael@0 948 });
michael@0 949
michael@0 950 add_identity_test(this, function test_crypto_keys_login_server_maintenance_error() {
michael@0 951 // Test crypto/keys server maintenance errors are not reported.
michael@0 952 let server = sync_httpd_setup();
michael@0 953 yield setUp(server);
michael@0 954
michael@0 955 yield configureIdentity({username: "broken.keys"});
michael@0 956 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 957 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 958
michael@0 959 // Force re-download of keys
michael@0 960 Service.collectionKeys.clear();
michael@0 961
michael@0 962 let backoffInterval;
michael@0 963 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 964 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 965 backoffInterval = subject;
michael@0 966 });
michael@0 967
michael@0 968 function onUIUpdate() {
michael@0 969 do_throw("Shouldn't get here!");
michael@0 970 }
michael@0 971 Svc.Obs.add("weave:ui:login:error", onUIUpdate);
michael@0 972
michael@0 973 do_check_false(Status.enforceBackoff);
michael@0 974 do_check_eq(Status.service, STATUS_OK);
michael@0 975
michael@0 976 let deferred = Promise.defer();
michael@0 977 Svc.Obs.add("weave:ui:clear-error", function onLoginFinish() {
michael@0 978 Svc.Obs.remove("weave:ui:clear-error", onLoginFinish);
michael@0 979
michael@0 980 do_check_true(Status.enforceBackoff);
michael@0 981 do_check_eq(backoffInterval, 42);
michael@0 982 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 983 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 984 do_check_false(errorHandler.didReportProlongedError);
michael@0 985
michael@0 986 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 987 clean();
michael@0 988 server.stop(deferred.resolve);
michael@0 989 });
michael@0 990
michael@0 991 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 992 Service.sync();
michael@0 993 yield deferred.promise;
michael@0 994 });
michael@0 995
michael@0 996 add_task(function test_sync_prolonged_server_maintenance_error() {
michael@0 997 // Test prolonged server maintenance errors are reported.
michael@0 998 let server = sync_httpd_setup();
michael@0 999 yield setUp(server);
michael@0 1000
michael@0 1001 const BACKOFF = 42;
michael@0 1002 let engine = engineManager.get("catapult");
michael@0 1003 engine.enabled = true;
michael@0 1004 engine.exception = {status: 503,
michael@0 1005 headers: {"retry-after": BACKOFF}};
michael@0 1006
michael@0 1007 let deferred = Promise.defer();
michael@0 1008 Svc.Obs.add("weave:ui:sync:error", function onUIUpdate() {
michael@0 1009 Svc.Obs.remove("weave:ui:sync:error", onUIUpdate);
michael@0 1010 do_check_eq(Status.service, SYNC_FAILED);
michael@0 1011 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 1012 do_check_true(errorHandler.didReportProlongedError);
michael@0 1013
michael@0 1014 clean();
michael@0 1015 server.stop(deferred.resolve);
michael@0 1016 });
michael@0 1017
michael@0 1018 do_check_eq(Status.service, STATUS_OK);
michael@0 1019
michael@0 1020 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1021 Service.sync();
michael@0 1022 yield deferred.promise;
michael@0 1023 });
michael@0 1024
michael@0 1025 add_identity_test(this, function test_info_collections_login_prolonged_server_maintenance_error(){
michael@0 1026 // Test info/collections prolonged server maintenance errors are reported.
michael@0 1027 let server = sync_httpd_setup();
michael@0 1028 yield setUp(server);
michael@0 1029
michael@0 1030 yield configureIdentity({username: "broken.info"});
michael@0 1031 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1032 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1033
michael@0 1034 let backoffInterval;
michael@0 1035 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1036 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1037 backoffInterval = subject;
michael@0 1038 });
michael@0 1039
michael@0 1040 let deferred = Promise.defer();
michael@0 1041 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1042 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1043 do_check_true(Status.enforceBackoff);
michael@0 1044 do_check_eq(backoffInterval, 42);
michael@0 1045 do_check_eq(Status.service, SYNC_FAILED);
michael@0 1046 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 1047 do_check_true(errorHandler.didReportProlongedError);
michael@0 1048
michael@0 1049 clean();
michael@0 1050 server.stop(deferred.resolve);
michael@0 1051 });
michael@0 1052
michael@0 1053 do_check_false(Status.enforceBackoff);
michael@0 1054 do_check_eq(Status.service, STATUS_OK);
michael@0 1055
michael@0 1056 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1057 Service.sync();
michael@0 1058 yield deferred.promise;
michael@0 1059 });
michael@0 1060
michael@0 1061 add_identity_test(this, function test_meta_global_login_prolonged_server_maintenance_error(){
michael@0 1062 // Test meta/global prolonged server maintenance errors are reported.
michael@0 1063 let server = sync_httpd_setup();
michael@0 1064 yield setUp(server);
michael@0 1065
michael@0 1066 yield configureIdentity({username: "broken.meta"});
michael@0 1067 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1068 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1069
michael@0 1070 let backoffInterval;
michael@0 1071 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1072 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1073 backoffInterval = subject;
michael@0 1074 });
michael@0 1075
michael@0 1076 let deferred = Promise.defer();
michael@0 1077 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1078 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1079 do_check_true(Status.enforceBackoff);
michael@0 1080 do_check_eq(backoffInterval, 42);
michael@0 1081 do_check_eq(Status.service, SYNC_FAILED);
michael@0 1082 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 1083 do_check_true(errorHandler.didReportProlongedError);
michael@0 1084
michael@0 1085 clean();
michael@0 1086 server.stop(deferred.resolve);
michael@0 1087 });
michael@0 1088
michael@0 1089 do_check_false(Status.enforceBackoff);
michael@0 1090 do_check_eq(Status.service, STATUS_OK);
michael@0 1091
michael@0 1092 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1093 Service.sync();
michael@0 1094 yield deferred.promise;
michael@0 1095 });
michael@0 1096
michael@0 1097 add_identity_test(this, function test_download_crypto_keys_login_prolonged_server_maintenance_error(){
michael@0 1098 // Test crypto/keys prolonged server maintenance errors are reported.
michael@0 1099 let server = sync_httpd_setup();
michael@0 1100 yield setUp(server);
michael@0 1101
michael@0 1102 yield configureIdentity({username: "broken.keys"});
michael@0 1103 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1104 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1105 // Force re-download of keys
michael@0 1106 Service.collectionKeys.clear();
michael@0 1107
michael@0 1108 let backoffInterval;
michael@0 1109 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1110 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1111 backoffInterval = subject;
michael@0 1112 });
michael@0 1113
michael@0 1114 let deferred = Promise.defer();
michael@0 1115 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1116 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1117 do_check_true(Status.enforceBackoff);
michael@0 1118 do_check_eq(backoffInterval, 42);
michael@0 1119 do_check_eq(Status.service, SYNC_FAILED);
michael@0 1120 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 1121 do_check_true(errorHandler.didReportProlongedError);
michael@0 1122
michael@0 1123 clean();
michael@0 1124 server.stop(deferred.resolve);
michael@0 1125 });
michael@0 1126
michael@0 1127 do_check_false(Status.enforceBackoff);
michael@0 1128 do_check_eq(Status.service, STATUS_OK);
michael@0 1129
michael@0 1130 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1131 Service.sync();
michael@0 1132 yield deferred.promise;
michael@0 1133 });
michael@0 1134
michael@0 1135 add_identity_test(this, function test_upload_crypto_keys_login_prolonged_server_maintenance_error(){
michael@0 1136 // Test crypto/keys prolonged server maintenance errors are reported.
michael@0 1137 let server = sync_httpd_setup();
michael@0 1138
michael@0 1139 // Start off with an empty account, do not upload a key.
michael@0 1140 yield configureIdentity({username: "broken.keys"});
michael@0 1141 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1142 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1143
michael@0 1144 let backoffInterval;
michael@0 1145 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1146 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1147 backoffInterval = subject;
michael@0 1148 });
michael@0 1149
michael@0 1150 let deferred = Promise.defer();
michael@0 1151 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1152 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1153 do_check_true(Status.enforceBackoff);
michael@0 1154 do_check_eq(backoffInterval, 42);
michael@0 1155 do_check_eq(Status.service, SYNC_FAILED);
michael@0 1156 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 1157 do_check_true(errorHandler.didReportProlongedError);
michael@0 1158
michael@0 1159 clean();
michael@0 1160 server.stop(deferred.resolve);
michael@0 1161 });
michael@0 1162
michael@0 1163 do_check_false(Status.enforceBackoff);
michael@0 1164 do_check_eq(Status.service, STATUS_OK);
michael@0 1165
michael@0 1166 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1167 Service.sync();
michael@0 1168 yield deferred.promise;
michael@0 1169 });
michael@0 1170
michael@0 1171 add_identity_test(this, function test_wipeServer_login_prolonged_server_maintenance_error(){
michael@0 1172 // Test that we report prolonged server maintenance errors that occur whilst
michael@0 1173 // wiping the server.
michael@0 1174 let server = sync_httpd_setup();
michael@0 1175
michael@0 1176 // Start off with an empty account, do not upload a key.
michael@0 1177 yield configureIdentity({username: "broken.wipe"});
michael@0 1178 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1179 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1180
michael@0 1181 let backoffInterval;
michael@0 1182 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1183 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1184 backoffInterval = subject;
michael@0 1185 });
michael@0 1186
michael@0 1187 let deferred = Promise.defer();
michael@0 1188 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1189 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1190 do_check_true(Status.enforceBackoff);
michael@0 1191 do_check_eq(backoffInterval, 42);
michael@0 1192 do_check_eq(Status.service, SYNC_FAILED);
michael@0 1193 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 1194 do_check_true(errorHandler.didReportProlongedError);
michael@0 1195
michael@0 1196 clean();
michael@0 1197 server.stop(deferred.resolve);
michael@0 1198 });
michael@0 1199
michael@0 1200 do_check_false(Status.enforceBackoff);
michael@0 1201 do_check_eq(Status.service, STATUS_OK);
michael@0 1202
michael@0 1203 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1204 Service.sync();
michael@0 1205 yield deferred.promise;
michael@0 1206 });
michael@0 1207
michael@0 1208 add_identity_test(this, function test_wipeRemote_prolonged_server_maintenance_error(){
michael@0 1209 // Test that we report prolonged server maintenance errors that occur whilst
michael@0 1210 // wiping all remote devices.
michael@0 1211 let server = sync_httpd_setup();
michael@0 1212
michael@0 1213 server.registerPathHandler("/1.1/broken.wipe/storage/catapult", service_unavailable);
michael@0 1214 yield configureIdentity({username: "broken.wipe"});
michael@0 1215 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1216 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1217 generateAndUploadKeys();
michael@0 1218
michael@0 1219 let engine = engineManager.get("catapult");
michael@0 1220 engine.exception = null;
michael@0 1221 engine.enabled = true;
michael@0 1222
michael@0 1223 let backoffInterval;
michael@0 1224 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1225 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1226 backoffInterval = subject;
michael@0 1227 });
michael@0 1228
michael@0 1229 let deferred = Promise.defer();
michael@0 1230 Svc.Obs.add("weave:ui:sync:error", function onUIUpdate() {
michael@0 1231 Svc.Obs.remove("weave:ui:sync:error", onUIUpdate);
michael@0 1232 do_check_true(Status.enforceBackoff);
michael@0 1233 do_check_eq(backoffInterval, 42);
michael@0 1234 do_check_eq(Status.service, SYNC_FAILED);
michael@0 1235 do_check_eq(Status.sync, PROLONGED_SYNC_FAILURE);
michael@0 1236 do_check_eq(Svc.Prefs.get("firstSync"), "wipeRemote");
michael@0 1237 do_check_true(errorHandler.didReportProlongedError);
michael@0 1238
michael@0 1239 clean();
michael@0 1240 server.stop(deferred.resolve);
michael@0 1241 });
michael@0 1242
michael@0 1243 do_check_false(Status.enforceBackoff);
michael@0 1244 do_check_eq(Status.service, STATUS_OK);
michael@0 1245
michael@0 1246 Svc.Prefs.set("firstSync", "wipeRemote");
michael@0 1247 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1248 Service.sync();
michael@0 1249 yield deferred.promise;
michael@0 1250 });
michael@0 1251
michael@0 1252 add_task(function test_sync_syncAndReportErrors_server_maintenance_error() {
michael@0 1253 // Test server maintenance errors are reported
michael@0 1254 // when calling syncAndReportErrors.
michael@0 1255 let server = sync_httpd_setup();
michael@0 1256 yield setUp(server);
michael@0 1257
michael@0 1258 const BACKOFF = 42;
michael@0 1259 let engine = engineManager.get("catapult");
michael@0 1260 engine.enabled = true;
michael@0 1261 engine.exception = {status: 503,
michael@0 1262 headers: {"retry-after": BACKOFF}};
michael@0 1263
michael@0 1264 let deferred = Promise.defer();
michael@0 1265 Svc.Obs.add("weave:ui:sync:error", function onUIUpdate() {
michael@0 1266 Svc.Obs.remove("weave:ui:sync:error", onUIUpdate);
michael@0 1267 do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
michael@0 1268 do_check_eq(Status.sync, SERVER_MAINTENANCE);
michael@0 1269 do_check_false(errorHandler.didReportProlongedError);
michael@0 1270
michael@0 1271 clean();
michael@0 1272 server.stop(deferred.resolve);
michael@0 1273 });
michael@0 1274
michael@0 1275 do_check_eq(Status.service, STATUS_OK);
michael@0 1276
michael@0 1277 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 1278 errorHandler.syncAndReportErrors();
michael@0 1279 yield deferred.promise;
michael@0 1280 });
michael@0 1281
michael@0 1282 add_identity_test(this, function test_info_collections_login_syncAndReportErrors_server_maintenance_error() {
michael@0 1283 // Test info/collections server maintenance errors are reported
michael@0 1284 // when calling syncAndReportErrors.
michael@0 1285 let server = sync_httpd_setup();
michael@0 1286 yield setUp(server);
michael@0 1287
michael@0 1288 yield configureIdentity({username: "broken.info"});
michael@0 1289 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1290 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1291
michael@0 1292 let backoffInterval;
michael@0 1293 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1294 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1295 backoffInterval = subject;
michael@0 1296 });
michael@0 1297
michael@0 1298 let deferred = Promise.defer();
michael@0 1299 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1300 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1301 do_check_true(Status.enforceBackoff);
michael@0 1302 do_check_eq(backoffInterval, 42);
michael@0 1303 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1304 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1305 do_check_false(errorHandler.didReportProlongedError);
michael@0 1306
michael@0 1307 clean();
michael@0 1308 server.stop(deferred.resolve);
michael@0 1309 });
michael@0 1310
michael@0 1311 do_check_false(Status.enforceBackoff);
michael@0 1312 do_check_eq(Status.service, STATUS_OK);
michael@0 1313
michael@0 1314 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 1315 errorHandler.syncAndReportErrors();
michael@0 1316 yield deferred.promise;
michael@0 1317 });
michael@0 1318
michael@0 1319 add_identity_test(this, function test_meta_global_login_syncAndReportErrors_server_maintenance_error() {
michael@0 1320 // Test meta/global server maintenance errors are reported
michael@0 1321 // when calling syncAndReportErrors.
michael@0 1322 let server = sync_httpd_setup();
michael@0 1323 yield setUp(server);
michael@0 1324
michael@0 1325 yield configureIdentity({username: "broken.meta"});
michael@0 1326 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1327 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1328
michael@0 1329 let backoffInterval;
michael@0 1330 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1331 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1332 backoffInterval = subject;
michael@0 1333 });
michael@0 1334
michael@0 1335 let deferred = Promise.defer();
michael@0 1336 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1337 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1338 do_check_true(Status.enforceBackoff);
michael@0 1339 do_check_eq(backoffInterval, 42);
michael@0 1340 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1341 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1342 do_check_false(errorHandler.didReportProlongedError);
michael@0 1343
michael@0 1344 clean();
michael@0 1345 server.stop(deferred.resolve);
michael@0 1346 });
michael@0 1347
michael@0 1348 do_check_false(Status.enforceBackoff);
michael@0 1349 do_check_eq(Status.service, STATUS_OK);
michael@0 1350
michael@0 1351 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 1352 errorHandler.syncAndReportErrors();
michael@0 1353 yield deferred.promise;
michael@0 1354 });
michael@0 1355
michael@0 1356 add_identity_test(this, function test_download_crypto_keys_login_syncAndReportErrors_server_maintenance_error() {
michael@0 1357 // Test crypto/keys server maintenance errors are reported
michael@0 1358 // when calling syncAndReportErrors.
michael@0 1359 let server = sync_httpd_setup();
michael@0 1360 yield setUp(server);
michael@0 1361
michael@0 1362 yield configureIdentity({username: "broken.keys"});
michael@0 1363 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1364 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1365 // Force re-download of keys
michael@0 1366 Service.collectionKeys.clear();
michael@0 1367
michael@0 1368 let backoffInterval;
michael@0 1369 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1370 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1371 backoffInterval = subject;
michael@0 1372 });
michael@0 1373
michael@0 1374 let deferred = Promise.defer();
michael@0 1375 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1376 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1377 do_check_true(Status.enforceBackoff);
michael@0 1378 do_check_eq(backoffInterval, 42);
michael@0 1379 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1380 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1381 do_check_false(errorHandler.didReportProlongedError);
michael@0 1382
michael@0 1383 clean();
michael@0 1384 server.stop(deferred.resolve);
michael@0 1385 });
michael@0 1386
michael@0 1387 do_check_false(Status.enforceBackoff);
michael@0 1388 do_check_eq(Status.service, STATUS_OK);
michael@0 1389
michael@0 1390 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 1391 errorHandler.syncAndReportErrors();
michael@0 1392 yield deferred.promise;
michael@0 1393 });
michael@0 1394
michael@0 1395 add_identity_test(this, function test_upload_crypto_keys_login_syncAndReportErrors_server_maintenance_error() {
michael@0 1396 // Test crypto/keys server maintenance errors are reported
michael@0 1397 // when calling syncAndReportErrors.
michael@0 1398 let server = sync_httpd_setup();
michael@0 1399
michael@0 1400 // Start off with an empty account, do not upload a key.
michael@0 1401 yield configureIdentity({username: "broken.keys"});
michael@0 1402 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1403 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1404
michael@0 1405 let backoffInterval;
michael@0 1406 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1407 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1408 backoffInterval = subject;
michael@0 1409 });
michael@0 1410
michael@0 1411 let deferred = Promise.defer();
michael@0 1412 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1413 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1414 do_check_true(Status.enforceBackoff);
michael@0 1415 do_check_eq(backoffInterval, 42);
michael@0 1416 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1417 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1418 do_check_false(errorHandler.didReportProlongedError);
michael@0 1419
michael@0 1420 clean();
michael@0 1421 server.stop(deferred.resolve);
michael@0 1422 });
michael@0 1423
michael@0 1424 do_check_false(Status.enforceBackoff);
michael@0 1425 do_check_eq(Status.service, STATUS_OK);
michael@0 1426
michael@0 1427 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 1428 errorHandler.syncAndReportErrors();
michael@0 1429 yield deferred.promise;
michael@0 1430 });
michael@0 1431
michael@0 1432 add_identity_test(this, function test_wipeServer_login_syncAndReportErrors_server_maintenance_error() {
michael@0 1433 // Test crypto/keys server maintenance errors are reported
michael@0 1434 // when calling syncAndReportErrors.
michael@0 1435 let server = sync_httpd_setup();
michael@0 1436
michael@0 1437 // Start off with an empty account, do not upload a key.
michael@0 1438 yield configureIdentity({username: "broken.wipe"});
michael@0 1439 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1440 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1441
michael@0 1442 let backoffInterval;
michael@0 1443 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1444 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1445 backoffInterval = subject;
michael@0 1446 });
michael@0 1447
michael@0 1448 let deferred = Promise.defer();
michael@0 1449 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1450 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1451 do_check_true(Status.enforceBackoff);
michael@0 1452 do_check_eq(backoffInterval, 42);
michael@0 1453 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1454 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1455 do_check_false(errorHandler.didReportProlongedError);
michael@0 1456
michael@0 1457 clean();
michael@0 1458 server.stop(deferred.resolve);
michael@0 1459 });
michael@0 1460
michael@0 1461 do_check_false(Status.enforceBackoff);
michael@0 1462 do_check_eq(Status.service, STATUS_OK);
michael@0 1463
michael@0 1464 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 1465 errorHandler.syncAndReportErrors();
michael@0 1466 yield deferred.promise;
michael@0 1467 });
michael@0 1468
michael@0 1469 add_identity_test(this, function test_wipeRemote_syncAndReportErrors_server_maintenance_error(){
michael@0 1470 // Test that we report prolonged server maintenance errors that occur whilst
michael@0 1471 // wiping all remote devices.
michael@0 1472 let server = sync_httpd_setup();
michael@0 1473
michael@0 1474 yield configureIdentity({username: "broken.wipe"});
michael@0 1475 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1476 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1477 generateAndUploadKeys();
michael@0 1478
michael@0 1479 let engine = engineManager.get("catapult");
michael@0 1480 engine.exception = null;
michael@0 1481 engine.enabled = true;
michael@0 1482
michael@0 1483 let backoffInterval;
michael@0 1484 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1485 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1486 backoffInterval = subject;
michael@0 1487 });
michael@0 1488
michael@0 1489 let deferred = Promise.defer();
michael@0 1490 Svc.Obs.add("weave:ui:sync:error", function onUIUpdate() {
michael@0 1491 Svc.Obs.remove("weave:ui:sync:error", onUIUpdate);
michael@0 1492 do_check_true(Status.enforceBackoff);
michael@0 1493 do_check_eq(backoffInterval, 42);
michael@0 1494 do_check_eq(Status.service, SYNC_FAILED);
michael@0 1495 do_check_eq(Status.sync, SERVER_MAINTENANCE);
michael@0 1496 do_check_eq(Svc.Prefs.get("firstSync"), "wipeRemote");
michael@0 1497 do_check_false(errorHandler.didReportProlongedError);
michael@0 1498
michael@0 1499 clean();
michael@0 1500 server.stop(deferred.resolve);
michael@0 1501 });
michael@0 1502
michael@0 1503 do_check_false(Status.enforceBackoff);
michael@0 1504 do_check_eq(Status.service, STATUS_OK);
michael@0 1505
michael@0 1506 Svc.Prefs.set("firstSync", "wipeRemote");
michael@0 1507 setLastSync(NON_PROLONGED_ERROR_DURATION);
michael@0 1508 errorHandler.syncAndReportErrors();
michael@0 1509 yield deferred.promise;
michael@0 1510 });
michael@0 1511
michael@0 1512 add_task(function test_sync_syncAndReportErrors_prolonged_server_maintenance_error() {
michael@0 1513 // Test prolonged server maintenance errors are
michael@0 1514 // reported when calling syncAndReportErrors.
michael@0 1515 let server = sync_httpd_setup();
michael@0 1516 yield setUp(server);
michael@0 1517
michael@0 1518 const BACKOFF = 42;
michael@0 1519 let engine = engineManager.get("catapult");
michael@0 1520 engine.enabled = true;
michael@0 1521 engine.exception = {status: 503,
michael@0 1522 headers: {"retry-after": BACKOFF}};
michael@0 1523
michael@0 1524 let deferred = Promise.defer();
michael@0 1525 Svc.Obs.add("weave:ui:sync:error", function onUIUpdate() {
michael@0 1526 Svc.Obs.remove("weave:ui:sync:error", onUIUpdate);
michael@0 1527 do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
michael@0 1528 do_check_eq(Status.sync, SERVER_MAINTENANCE);
michael@0 1529 // syncAndReportErrors means dontIgnoreErrors, which means
michael@0 1530 // didReportProlongedError not touched.
michael@0 1531 do_check_false(errorHandler.didReportProlongedError);
michael@0 1532
michael@0 1533 clean();
michael@0 1534 server.stop(deferred.resolve);
michael@0 1535 });
michael@0 1536
michael@0 1537 do_check_eq(Status.service, STATUS_OK);
michael@0 1538
michael@0 1539 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1540 errorHandler.syncAndReportErrors();
michael@0 1541 yield deferred.promise;
michael@0 1542 });
michael@0 1543
michael@0 1544 add_identity_test(this, function test_info_collections_login_syncAndReportErrors_prolonged_server_maintenance_error() {
michael@0 1545 // Test info/collections server maintenance errors are reported
michael@0 1546 // when calling syncAndReportErrors.
michael@0 1547 let server = sync_httpd_setup();
michael@0 1548 yield setUp(server);
michael@0 1549
michael@0 1550 yield configureIdentity({username: "broken.info"});
michael@0 1551 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1552 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1553
michael@0 1554 let backoffInterval;
michael@0 1555 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1556 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1557 backoffInterval = subject;
michael@0 1558 });
michael@0 1559
michael@0 1560 let deferred = Promise.defer();
michael@0 1561 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1562 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1563 do_check_true(Status.enforceBackoff);
michael@0 1564 do_check_eq(backoffInterval, 42);
michael@0 1565 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1566 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1567 // syncAndReportErrors means dontIgnoreErrors, which means
michael@0 1568 // didReportProlongedError not touched.
michael@0 1569 do_check_false(errorHandler.didReportProlongedError);
michael@0 1570
michael@0 1571 clean();
michael@0 1572 server.stop(deferred.resolve);
michael@0 1573 });
michael@0 1574
michael@0 1575 do_check_false(Status.enforceBackoff);
michael@0 1576 do_check_eq(Status.service, STATUS_OK);
michael@0 1577
michael@0 1578 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1579 errorHandler.syncAndReportErrors();
michael@0 1580 yield deferred.promise;
michael@0 1581 });
michael@0 1582
michael@0 1583 add_identity_test(this, function test_meta_global_login_syncAndReportErrors_prolonged_server_maintenance_error() {
michael@0 1584 // Test meta/global server maintenance errors are reported
michael@0 1585 // when calling syncAndReportErrors.
michael@0 1586 let server = sync_httpd_setup();
michael@0 1587 yield setUp(server);
michael@0 1588
michael@0 1589 yield configureIdentity({username: "broken.meta"});
michael@0 1590 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1591 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1592
michael@0 1593 let backoffInterval;
michael@0 1594 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1595 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1596 backoffInterval = subject;
michael@0 1597 });
michael@0 1598
michael@0 1599 let deferred = Promise.defer();
michael@0 1600 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1601 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1602 do_check_true(Status.enforceBackoff);
michael@0 1603 do_check_eq(backoffInterval, 42);
michael@0 1604 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1605 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1606 // syncAndReportErrors means dontIgnoreErrors, which means
michael@0 1607 // didReportProlongedError not touched.
michael@0 1608 do_check_false(errorHandler.didReportProlongedError);
michael@0 1609
michael@0 1610 clean();
michael@0 1611 server.stop(deferred.resolve);
michael@0 1612 });
michael@0 1613
michael@0 1614 do_check_false(Status.enforceBackoff);
michael@0 1615 do_check_eq(Status.service, STATUS_OK);
michael@0 1616
michael@0 1617 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1618 errorHandler.syncAndReportErrors();
michael@0 1619 yield deferred.promise;
michael@0 1620 });
michael@0 1621
michael@0 1622 add_identity_test(this, function test_download_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() {
michael@0 1623 // Test crypto/keys server maintenance errors are reported
michael@0 1624 // when calling syncAndReportErrors.
michael@0 1625 let server = sync_httpd_setup();
michael@0 1626 yield setUp(server);
michael@0 1627
michael@0 1628 yield configureIdentity({username: "broken.keys"});
michael@0 1629 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1630 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1631 // Force re-download of keys
michael@0 1632 Service.collectionKeys.clear();
michael@0 1633
michael@0 1634 let backoffInterval;
michael@0 1635 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1636 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1637 backoffInterval = subject;
michael@0 1638 });
michael@0 1639
michael@0 1640 let deferred = Promise.defer();
michael@0 1641 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1642 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1643 do_check_true(Status.enforceBackoff);
michael@0 1644 do_check_eq(backoffInterval, 42);
michael@0 1645 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1646 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1647 // syncAndReportErrors means dontIgnoreErrors, which means
michael@0 1648 // didReportProlongedError not touched.
michael@0 1649 do_check_false(errorHandler.didReportProlongedError);
michael@0 1650
michael@0 1651 clean();
michael@0 1652 server.stop(deferred.resolve);
michael@0 1653 });
michael@0 1654
michael@0 1655 do_check_false(Status.enforceBackoff);
michael@0 1656 do_check_eq(Status.service, STATUS_OK);
michael@0 1657
michael@0 1658 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1659 errorHandler.syncAndReportErrors();
michael@0 1660 yield deferred.promise;
michael@0 1661 });
michael@0 1662
michael@0 1663 add_identity_test(this, function test_upload_crypto_keys_login_syncAndReportErrors_prolonged_server_maintenance_error() {
michael@0 1664 // Test crypto/keys server maintenance errors are reported
michael@0 1665 // when calling syncAndReportErrors.
michael@0 1666 let server = sync_httpd_setup();
michael@0 1667
michael@0 1668 // Start off with an empty account, do not upload a key.
michael@0 1669 yield configureIdentity({username: "broken.keys"});
michael@0 1670 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1671 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1672
michael@0 1673 let backoffInterval;
michael@0 1674 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1675 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1676 backoffInterval = subject;
michael@0 1677 });
michael@0 1678
michael@0 1679 let deferred = Promise.defer();
michael@0 1680 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1681 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1682 do_check_true(Status.enforceBackoff);
michael@0 1683 do_check_eq(backoffInterval, 42);
michael@0 1684 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1685 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1686 // syncAndReportErrors means dontIgnoreErrors, which means
michael@0 1687 // didReportProlongedError not touched.
michael@0 1688 do_check_false(errorHandler.didReportProlongedError);
michael@0 1689
michael@0 1690 clean();
michael@0 1691 server.stop(deferred.resolve);
michael@0 1692 });
michael@0 1693
michael@0 1694 do_check_false(Status.enforceBackoff);
michael@0 1695 do_check_eq(Status.service, STATUS_OK);
michael@0 1696
michael@0 1697 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1698 errorHandler.syncAndReportErrors();
michael@0 1699 yield deferred.promise;
michael@0 1700 });
michael@0 1701
michael@0 1702 add_identity_test(this, function test_wipeServer_login_syncAndReportErrors_prolonged_server_maintenance_error() {
michael@0 1703 // Test crypto/keys server maintenance errors are reported
michael@0 1704 // when calling syncAndReportErrors.
michael@0 1705 let server = sync_httpd_setup();
michael@0 1706
michael@0 1707 // Start off with an empty account, do not upload a key.
michael@0 1708 yield configureIdentity({username: "broken.wipe"});
michael@0 1709 Service.serverURL = server.baseURI + "/maintenance/";
michael@0 1710 Service.clusterURL = server.baseURI + "/maintenance/";
michael@0 1711
michael@0 1712 let backoffInterval;
michael@0 1713 Svc.Obs.add("weave:service:backoff:interval", function observe(subject, data) {
michael@0 1714 Svc.Obs.remove("weave:service:backoff:interval", observe);
michael@0 1715 backoffInterval = subject;
michael@0 1716 });
michael@0 1717
michael@0 1718 let deferred = Promise.defer();
michael@0 1719 Svc.Obs.add("weave:ui:login:error", function onUIUpdate() {
michael@0 1720 Svc.Obs.remove("weave:ui:login:error", onUIUpdate);
michael@0 1721 do_check_true(Status.enforceBackoff);
michael@0 1722 do_check_eq(backoffInterval, 42);
michael@0 1723 do_check_eq(Status.service, LOGIN_FAILED);
michael@0 1724 do_check_eq(Status.login, SERVER_MAINTENANCE);
michael@0 1725 // syncAndReportErrors means dontIgnoreErrors, which means
michael@0 1726 // didReportProlongedError not touched.
michael@0 1727 do_check_false(errorHandler.didReportProlongedError);
michael@0 1728
michael@0 1729 clean();
michael@0 1730 server.stop(deferred.resolve);
michael@0 1731 });
michael@0 1732
michael@0 1733 do_check_false(Status.enforceBackoff);
michael@0 1734 do_check_eq(Status.service, STATUS_OK);
michael@0 1735
michael@0 1736 setLastSync(PROLONGED_ERROR_DURATION);
michael@0 1737 errorHandler.syncAndReportErrors();
michael@0 1738 yield deferred.promise;
michael@0 1739 });
michael@0 1740
michael@0 1741 add_task(function test_sync_engine_generic_fail() {
michael@0 1742 let server = sync_httpd_setup();
michael@0 1743
michael@0 1744 let engine = engineManager.get("catapult");
michael@0 1745 engine.enabled = true;
michael@0 1746 engine.sync = function sync() {
michael@0 1747 Svc.Obs.notify("weave:engine:sync:error", "", "catapult");
michael@0 1748 };
michael@0 1749
michael@0 1750 let log = Log.repository.getLogger("Sync.ErrorHandler");
michael@0 1751 Svc.Prefs.set("log.appender.file.logOnError", true);
michael@0 1752
michael@0 1753 do_check_eq(Status.engines["catapult"], undefined);
michael@0 1754
michael@0 1755 let deferred = Promise.defer();
michael@0 1756 // Don't wait for reset-file-log until the sync is underway.
michael@0 1757 // This avoids us catching a delayed notification from an earlier test.
michael@0 1758 Svc.Obs.add("weave:engine:sync:finish", function onEngineFinish() {
michael@0 1759 Svc.Obs.remove("weave:engine:sync:finish", onEngineFinish);
michael@0 1760
michael@0 1761 log.info("Adding reset-file-log observer.");
michael@0 1762 Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
michael@0 1763 Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);
michael@0 1764
michael@0 1765 // Put these checks here, not after sync(), so that we aren't racing the
michael@0 1766 // log handler... which resets everything just a few lines below!
michael@0 1767 _("Status.engines: " + JSON.stringify(Status.engines));
michael@0 1768 do_check_eq(Status.engines["catapult"], ENGINE_UNKNOWN_FAIL);
michael@0 1769 do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
michael@0 1770
michael@0 1771 // Test Error log was written on SYNC_FAILED_PARTIAL.
michael@0 1772 let entries = logsdir.directoryEntries;
michael@0 1773 do_check_true(entries.hasMoreElements());
michael@0 1774 let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
michael@0 1775 do_check_eq(logfile.leafName.slice(0, LOG_PREFIX_ERROR.length),
michael@0 1776 LOG_PREFIX_ERROR);
michael@0 1777
michael@0 1778 clean();
michael@0 1779 server.stop(deferred.resolve);
michael@0 1780 });
michael@0 1781 });
michael@0 1782
michael@0 1783 do_check_true(yield setUp(server));
michael@0 1784 Service.sync();
michael@0 1785 yield deferred.promise;
michael@0 1786 });
michael@0 1787
michael@0 1788 add_test(function test_logs_on_sync_error_despite_shouldReportError() {
michael@0 1789 _("Ensure that an error is still logged when weave:service:sync:error " +
michael@0 1790 "is notified, despite shouldReportError returning false.");
michael@0 1791
michael@0 1792 let log = Log.repository.getLogger("Sync.ErrorHandler");
michael@0 1793 Svc.Prefs.set("log.appender.file.logOnError", true);
michael@0 1794 log.info("TESTING");
michael@0 1795
michael@0 1796 // Ensure that we report no error.
michael@0 1797 Status.login = MASTER_PASSWORD_LOCKED;
michael@0 1798 do_check_false(errorHandler.shouldReportError());
michael@0 1799
michael@0 1800 Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
michael@0 1801 Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);
michael@0 1802
michael@0 1803 // Test that error log was written.
michael@0 1804 let entries = logsdir.directoryEntries;
michael@0 1805 do_check_true(entries.hasMoreElements());
michael@0 1806 let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
michael@0 1807 do_check_eq(logfile.leafName.slice(0, LOG_PREFIX_ERROR.length),
michael@0 1808 LOG_PREFIX_ERROR);
michael@0 1809
michael@0 1810 clean();
michael@0 1811 run_next_test();
michael@0 1812 });
michael@0 1813 Svc.Obs.notify("weave:service:sync:error", {});
michael@0 1814 });
michael@0 1815
michael@0 1816 add_test(function test_logs_on_login_error_despite_shouldReportError() {
michael@0 1817 _("Ensure that an error is still logged when weave:service:login:error " +
michael@0 1818 "is notified, despite shouldReportError returning false.");
michael@0 1819
michael@0 1820 let log = Log.repository.getLogger("Sync.ErrorHandler");
michael@0 1821 Svc.Prefs.set("log.appender.file.logOnError", true);
michael@0 1822 log.info("TESTING");
michael@0 1823
michael@0 1824 // Ensure that we report no error.
michael@0 1825 Status.login = MASTER_PASSWORD_LOCKED;
michael@0 1826 do_check_false(errorHandler.shouldReportError());
michael@0 1827
michael@0 1828 Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
michael@0 1829 Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);
michael@0 1830
michael@0 1831 // Test that error log was written.
michael@0 1832 let entries = logsdir.directoryEntries;
michael@0 1833 do_check_true(entries.hasMoreElements());
michael@0 1834 let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
michael@0 1835 do_check_eq(logfile.leafName.slice(0, LOG_PREFIX_ERROR.length),
michael@0 1836 LOG_PREFIX_ERROR);
michael@0 1837
michael@0 1838 clean();
michael@0 1839 run_next_test();
michael@0 1840 });
michael@0 1841 Svc.Obs.notify("weave:service:login:error", {});
michael@0 1842 });
michael@0 1843
michael@0 1844 // This test should be the last one since it monkeypatches the engine object
michael@0 1845 // and we should only have one engine object throughout the file (bug 629664).
michael@0 1846 add_task(function test_engine_applyFailed() {
michael@0 1847 let server = sync_httpd_setup();
michael@0 1848
michael@0 1849 let engine = engineManager.get("catapult");
michael@0 1850 engine.enabled = true;
michael@0 1851 delete engine.exception;
michael@0 1852 engine.sync = function sync() {
michael@0 1853 Svc.Obs.notify("weave:engine:sync:applied", {newFailed:1}, "catapult");
michael@0 1854 };
michael@0 1855
michael@0 1856 let log = Log.repository.getLogger("Sync.ErrorHandler");
michael@0 1857 Svc.Prefs.set("log.appender.file.logOnError", true);
michael@0 1858
michael@0 1859 let deferred = Promise.defer();
michael@0 1860 Svc.Obs.add("weave:service:reset-file-log", function onResetFileLog() {
michael@0 1861 Svc.Obs.remove("weave:service:reset-file-log", onResetFileLog);
michael@0 1862
michael@0 1863 do_check_eq(Status.engines["catapult"], ENGINE_APPLY_FAIL);
michael@0 1864 do_check_eq(Status.service, SYNC_FAILED_PARTIAL);
michael@0 1865
michael@0 1866 // Test Error log was written on SYNC_FAILED_PARTIAL.
michael@0 1867 let entries = logsdir.directoryEntries;
michael@0 1868 do_check_true(entries.hasMoreElements());
michael@0 1869 let logfile = entries.getNext().QueryInterface(Ci.nsILocalFile);
michael@0 1870 do_check_eq(logfile.leafName.slice(0, LOG_PREFIX_ERROR.length),
michael@0 1871 LOG_PREFIX_ERROR);
michael@0 1872
michael@0 1873 clean();
michael@0 1874 server.stop(deferred.resolve);
michael@0 1875 });
michael@0 1876
michael@0 1877 do_check_eq(Status.engines["catapult"], undefined);
michael@0 1878 do_check_true(yield setUp(server));
michael@0 1879 Service.sync();
michael@0 1880 yield deferred.promise;
michael@0 1881 });

mercurial