commit 9c2a7a9e77d5573238696716a7d71bc5eff7d0c9
parent 9fb85a263a72f9f20ebc63c97742f48b81bc2579
Author: Dan Stillman <dstillman@zotero.org>
Date: Wed, 3 Feb 2016 01:16:09 -0500
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.
Diffstat:
2 files changed, 7 insertions(+), 6 deletions(-)
diff --git a/chrome/content/zotero/xpcom/storage/zfs.js b/chrome/content/zotero/xpcom/storage/zfs.js
@@ -34,7 +34,8 @@ Zotero.Sync.Storage.Mode.ZFS = function (options) {
this._s3Backoff = 1;
this._s3ConsecutiveFailures = 0;
this._maxS3Backoff = 60;
- this._maxS3ConsecutiveFailures = 5;
+ this._maxS3ConsecutiveFailures = options.maxS3ConsecutiveFailures !== undefined
+ ? options.maxS3ConsecutiveFailures : 5;
};
Zotero.Sync.Storage.Mode.ZFS.prototype = {
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
// consecutive failures
if (status == 0 || status == 500 || status == 503) {
- if (this._s3ConsecutiveFailures < this._maxS3ConsecutiveFailures) {
+ if (++this._s3ConsecutiveFailures < this._maxS3ConsecutiveFailures) {
let libraryKey = item.libraryKey;
let msg = "S3 returned 0 for " + libraryKey + " -- retrying download"
Components.utils.reportError(msg);
@@ -165,13 +166,12 @@ Zotero.Sync.Storage.Mode.ZFS.prototype = {
if (this._s3Backoff < this._maxS3Backoff) {
this._s3Backoff *= 2;
}
- this._s3ConsecutiveFailures++;
Zotero.debug("Delaying " + libraryKey + " download for "
+ this._s3Backoff + " seconds", 2);
Zotero.Promise.delay(this._s3Backoff * 1000)
.then(function () {
- deferred.resolve(this._downloadFile(request));
- });
+ deferred.resolve(this.downloadFile(request));
+ }.bind(this));
return;
}
diff --git a/test/tests/zfsTest.js b/test/tests/zfsTest.js
@@ -90,7 +90,8 @@ describe("Zotero.Sync.Storage.Mode.ZFS", function () {
var engine = new Zotero.Sync.Storage.Engine({
libraryID: options.libraryID || Zotero.Libraries.userLibraryID,
controller: new Zotero.Sync.Storage.Mode.ZFS({
- apiClient: client
+ apiClient: client,
+ maxS3ConsecutiveFailures: 2
}),
stopOnError: true
});