From 9c2a7a9e77d5573238696716a7d71bc5eff7d0c9 Mon Sep 17 00:00:00 2001 From: Dan Stillman Date: Wed, 3 Feb 2016 01:16:09 -0500 Subject: [PATCH] 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. --- chrome/content/zotero/xpcom/storage/zfs.js | 10 +++++----- test/tests/zfsTest.js | 3 ++- 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 index 65cc79d06..4483ecec0 100644 --- 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 index 41a680bcc..70bf7db7b 100644 --- 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 });