Only retry file sync requests once after 500 error in tests

Now that 500 errors are retried in file downloads (ec28c5a3), we have to
override the default backoff schedule in order to get expected failures.

This also fixes an error that occurred on a retried download.
This commit is contained in:
Dan Stillman 2016-02-03 01:16:09 -05:00
parent 9fb85a263a
commit 9c2a7a9e77
2 changed files with 7 additions and 6 deletions

View File

@ -34,7 +34,8 @@ Zotero.Sync.Storage.Mode.ZFS = function (options) {
this._s3Backoff = 1; this._s3Backoff = 1;
this._s3ConsecutiveFailures = 0; this._s3ConsecutiveFailures = 0;
this._maxS3Backoff = 60; this._maxS3Backoff = 60;
this._maxS3ConsecutiveFailures = 5; this._maxS3ConsecutiveFailures = options.maxS3ConsecutiveFailures !== undefined
? options.maxS3ConsecutiveFailures : 5;
}; };
Zotero.Sync.Storage.Mode.ZFS.prototype = { Zotero.Sync.Storage.Mode.ZFS.prototype = {
mode: "zfs", mode: "zfs",
@ -157,7 +158,7 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
// If S3 connection is interrupted, delay and retry, or bail if too many // If S3 connection is interrupted, delay and retry, or bail if too many
// consecutive failures // consecutive failures
if (status == 0 || status == 500 || status == 503) { if (status == 0 || status == 500 || status == 503) {
if (this._s3ConsecutiveFailures < this._maxS3ConsecutiveFailures) { if (++this._s3ConsecutiveFailures < this._maxS3ConsecutiveFailures) {
let libraryKey = item.libraryKey; let libraryKey = item.libraryKey;
let msg = "S3 returned 0 for " + libraryKey + " -- retrying download" let msg = "S3 returned 0 for " + libraryKey + " -- retrying download"
Components.utils.reportError(msg); Components.utils.reportError(msg);
@ -165,13 +166,12 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
if (this._s3Backoff < this._maxS3Backoff) { if (this._s3Backoff < this._maxS3Backoff) {
this._s3Backoff *= 2; this._s3Backoff *= 2;
} }
this._s3ConsecutiveFailures++;
Zotero.debug("Delaying " + libraryKey + " download for " Zotero.debug("Delaying " + libraryKey + " download for "
+ this._s3Backoff + " seconds", 2); + this._s3Backoff + " seconds", 2);
Zotero.Promise.delay(this._s3Backoff * 1000) Zotero.Promise.delay(this._s3Backoff * 1000)
.then(function () { .then(function () {
deferred.resolve(this._downloadFile(request)); deferred.resolve(this.downloadFile(request));
}); }.bind(this));
return; return;
} }

View File

@ -90,7 +90,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
var engine = new Zotero.Sync.Storage.Engine({ var engine = new Zotero.Sync.Storage.Engine({
libraryID: options.libraryID || Zotero.Libraries.userLibraryID, libraryID: options.libraryID || Zotero.Libraries.userLibraryID,
controller: new Zotero.Sync.Storage.Mode.ZFS({ controller: new Zotero.Sync.Storage.Mode.ZFS({
apiClient: client apiClient: client,
maxS3ConsecutiveFailures: 2
}), }),
stopOnError: true stopOnError: true
}); });