Bug 684798 - Part 4: Schedule syncs on temporary/recoverable login errors. r=rnewman (reland)

This commit is contained in:
Richard Newman 2011-10-27 22:25:00 -07:00
Родитель 7b1cca1dbd
Коммит 71846f4cc9
2 изменённых файлов: 79 добавлений и 2 удалений

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

@ -55,6 +55,12 @@ Cu.import("resource://services-sync/main.js"); // So we can get to Service fo
let SyncScheduler = {
_log: Log4Moz.repository.getLogger("Sync.SyncScheduler"),
_fatalLoginStatus: [LOGIN_FAILED_NO_USERNAME,
LOGIN_FAILED_NO_PASSWORD,
LOGIN_FAILED_NO_PASSPHRASE,
LOGIN_FAILED_INVALID_PASSPHRASE,
LOGIN_FAILED_LOGIN_REJECTED],
/**
* The nsITimer object that schedules the next sync. See scheduleNextSync().
*/
@ -172,12 +178,16 @@ let SyncScheduler = {
case "weave:service:login:error":
this.clearSyncTriggers();
// Try again later, just as if we threw an error... only without the
// error count.
if (Status.login == MASTER_PASSWORD_LOCKED) {
// Try again later, just as if we threw an error... only without the
// error count.
this._log.debug("Couldn't log in: master password is locked.");
this._log.trace("Scheduling a sync at MASTER_PASSWORD_LOCKED_RETRY_INTERVAL");
this.scheduleAtInterval(MASTER_PASSWORD_LOCKED_RETRY_INTERVAL);
} else if (this._fatalLoginStatus.indexOf(Status.login) == -1) {
// Not a fatal login error, just an intermittent network or server
// issue. Keep on syncin'.
this.checkSyncStatus();
}
break;
case "weave:service:logout:finish":

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

@ -863,3 +863,70 @@ add_test(function test_sync_503_Retry_After() {
cleanUpAndGo(server);
});
add_test(function test_loginError_recoverable_reschedules() {
_("Verify that a recoverable login error schedules a new sync.");
Service.username = "johndoe";
Service.password = "ilovejane";
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
Service.clusterURL = "http://localhost:8080/";
Service.persistLogin();
Status.resetSync(); // reset Status.login
Svc.Obs.add("weave:service:login:error", function onLoginError() {
Svc.Obs.remove("weave:service:login:error", onLoginError);
Utils.nextTick(function aLittleBitAfterLoginError() {
do_check_eq(Status.login, LOGIN_FAILED_NETWORK_ERROR);
let expectedNextSync = Date.now() + SyncScheduler.syncInterval;
do_check_true(SyncScheduler.nextSync > Date.now());
do_check_true(SyncScheduler.nextSync <= expectedNextSync);
do_check_true(SyncScheduler.syncTimer.delay > 0);
do_check_true(SyncScheduler.syncTimer.delay <= SyncScheduler.syncInterval);
cleanUpAndGo();
});
});
// Sanity check.
do_check_eq(SyncScheduler.nextSync, 0);
do_check_eq(SyncScheduler.syncTimer, null);
do_check_eq(Status.checkSetup(), STATUS_OK);
do_check_eq(Status.login, LOGIN_SUCCEEDED);
SyncScheduler.scheduleNextSync(0);
});
add_test(function test_loginError_fatal_clearsTriggers() {
_("Verify that a fatal login error clears sync triggers.");
Service.username = "johndoe";
Service.password = "ilovejane";
Service.passphrase = "abcdeabcdeabcdeabcdeabcdea";
Service.clusterURL = "http://localhost:8080/";
Service.persistLogin();
Status.resetSync(); // reset Status.login
let server = httpd_setup({
"/1.1/johndoe/info/collections": httpd_handler(401, "Unauthorized")
});
Svc.Obs.add("weave:service:login:error", function onLoginError() {
Svc.Obs.remove("weave:service:login:error", onLoginError);
Utils.nextTick(function aLittleBitAfterLoginError() {
do_check_eq(Status.login, LOGIN_FAILED_LOGIN_REJECTED);
do_check_eq(SyncScheduler.nextSync, 0);
do_check_eq(SyncScheduler.syncTimer, null);
cleanUpAndGo(server);
});
});
// Sanity check.
do_check_eq(SyncScheduler.nextSync, 0);
do_check_eq(SyncScheduler.syncTimer, null);
do_check_eq(Status.checkSetup(), STATUS_OK);
do_check_eq(Status.login, LOGIN_SUCCEEDED);
SyncScheduler.scheduleNextSync(0);
});