From 2b48fa829783b61515f47e037418536bdb88e153 Mon Sep 17 00:00:00 2001 From: Galvin Hsiu Date: Sun, 21 Jan 2018 01:14:50 -0800 Subject: [PATCH 1/4] Added in unit tests along with reset logic etc --- client/js/uploader.basic.api.js | 9 ++++ test/unit/chunked-uploads.js | 87 +++++++++++++++++++++++++++++++++ 2 files changed, 96 insertions(+) diff --git a/client/js/uploader.basic.api.js b/client/js/uploader.basic.api.js index b02f03894..c634cc37e 100644 --- a/client/js/uploader.basic.api.js +++ b/client/js/uploader.basic.api.js @@ -778,6 +778,7 @@ self._options.callbacks.onUploadChunk(id, name, chunkData); }, onUploadChunkSuccess: function(id, chunkData, result, xhr) { + self._onUploadChunkSuccess(id, chunkData); self._options.callbacks.onUploadChunkSuccess.apply(self, arguments); }, onResume: function(id, name, chunkData) { @@ -1574,6 +1575,14 @@ //nothing to do in the base uploader }, + _onUploadChunkSuccess: function(id, chunkData) { + var uploadData = this._uploadData.retrieve({id: id}); + + if (!this._preventRetries[id] && this._options.retry.enableAuto && uploadData.status !== qq.status.PAUSED) { + this._autoRetries[id] = 0; + } + }, + _onUploadStatusChange: function(id, oldStatus, newStatus) { // Make sure a "queued" retry attempt is canceled if the upload has been paused if (newStatus === qq.status.PAUSED) { diff --git a/test/unit/chunked-uploads.js b/test/unit/chunked-uploads.js index 04c3d5ad3..92f2392f8 100644 --- a/test/unit/chunked-uploads.js +++ b/test/unit/chunked-uploads.js @@ -56,6 +56,9 @@ if (qqtest.canDownloadFileAsBlob) { request.respond(200, null, JSON.stringify({success: true, testParam: "testVal"})); }, 10); }, + onAutoRetry: function(id, name, attemptNumber) { + assert.fail("This should not be called"); + }, onUploadChunkSuccess: function (id, chunkData, response, xhr) { var request = fileTestHelper.getRequests()[fileTestHelper.getRequests().length - 1], requestParams; @@ -197,6 +200,86 @@ if (qqtest.canDownloadFileAsBlob) { }); } + function testChunkedEveryFailureAndRecovery(done) { + assert.expect(6 + (expectedChunks * 17) + (expectedChunks * 6), done); + + var alreadyFailed = false, + uploader = new qq.FineUploaderBasic({ + request: { + endpoint: testUploadEndpoint + }, + chunking: { + enabled: true, + partSize: chunkSize + }, + retry: { + autoAttemptDelay: 0, + enableAuto: true + }, + callbacks: { + onUploadChunk: function (id, name, chunkData) { + chunksSent++; + + assert.equal(id, 0, "Wrong ID passed to onUpoadChunk"); + assert.equal(name, uploader.getName(id), "Wrong name passed to onUploadChunk"); + assert.equal(chunkData.partIndex, chunksSent - 1, "Wrong partIndex passed to onUploadChunk"); + assert.equal(chunkData.startByte, (chunksSent - 1) * chunkSize + 1, "Wrong startByte passed to onUploadChunk"); + assert.equal(chunkData.endByte, chunksSent === expectedChunks ? expectedFileSize : chunkData.startByte + chunkSize - 1, "Wrong startByte passed to onUploadChunk"); + assert.equal(chunkData.totalParts, expectedChunks, "Wrong totalParts passed to onUploadChunk"); + + setTimeout(function () { + var request = fileTestHelper.getRequests()[fileTestHelper.getRequests().length - 1]; + + if (!alreadyFailed) { + alreadyFailed = true; + + chunksSent--; + request.respond(500, null, JSON.stringify({testParam: "testVal"})); + } + else { + alreadyFailed = false; + request.respond(200, null, JSON.stringify({success: true, testParam: "testVal"})); + } + }, 10); + }, + onAutoRetry: function(id, name, attemptNumber) { + assert.equal(id, 0, "Wrong ID passed to onAutoRetry"); + assert.equal(name, uploader.getName(id), "Wrong name passed to onAutoRetry"); + assert.equal(attemptNumber, 1, "Wrong auto retry attempt #"); + }, + onUploadChunkSuccess: function (id, chunkData, response, xhr) { + var request = fileTestHelper.getRequests()[fileTestHelper.getRequests().length - 1], + requestParams = request.requestBody.fields; + + chunksSucceeded++; + + assert.equal(requestParams.qquuid, uploader.getUuid(id), "Wrong uuid param"); + assert.equal(requestParams.qqpartindex, chunksSent - 1, "Wrong part index param"); + assert.equal(requestParams.qqpartbyteoffset, (chunksSent - 1) * chunkSize, "Wrong part byte offset param"); + assert.equal(requestParams.qqtotalfilesize, expectedFileSize, "Wrong total file size param"); + assert.equal(requestParams.qqtotalparts, expectedChunks, "Wrong total parts param"); + assert.equal(requestParams.qqfilename, uploader.getName(id), "Wrong filename param"); + assert.equal(requestParams.qqchunksize, requestParams.qqfile.size, "Wrong chunk size param"); + assert.equal(id, 0, "Wrong ID passed to onUpoadChunkSuccess"); + + assert.equal(response.testParam, "testVal"); + }, + onComplete: function (id, name, response) { + assert.equal(expectedChunks, chunksSent, "Wrong # of chunks sent."); + assert.equal(expectedChunks, chunksSucceeded, "Wrong # of chunks succeeded"); + assert.equal(response.testParam, "testVal"); + } + } + }), + chunksSent = 0, + chunksSucceeded = 0; + + qqtest.downloadFileAsBlob("up.jpg", "image/jpeg").then(function (blob) { + fileTestHelper.mockXhr(); + uploader.addFiles({name: "test", blob: blob}); + }); + } + it("sends proper number of chunks when chunking is enabled, MPE", function(done) { testChunkedUpload({ mpe: true, @@ -246,6 +329,10 @@ if (qqtest.canDownloadFileAsBlob) { testChunkedFailureAndRecovery(true, done); }); + it("fails every chunk once, then recovers and ensure attemptNumber is 1", function(done) { + testChunkedEveryFailureAndRecovery(done); + }); + describe("resume feature tests", function() { var nativeLocalStorageSetItem = window.localStorage.setItem, acknowledgeRequests = function(endpoint) { From 7c4412efd479efafa51b4a300787cdada6a373c3 Mon Sep 17 00:00:00 2001 From: Galvin Hsiu Date: Mon, 22 Jan 2018 01:44:10 -0800 Subject: [PATCH 2/4] Ripped out unwanted condition, changed test --- client/js/uploader.basic.api.js | 4 +--- test/unit/chunked-uploads.js | 5 +++-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/client/js/uploader.basic.api.js b/client/js/uploader.basic.api.js index c634cc37e..b4c1ad071 100644 --- a/client/js/uploader.basic.api.js +++ b/client/js/uploader.basic.api.js @@ -1576,9 +1576,7 @@ }, _onUploadChunkSuccess: function(id, chunkData) { - var uploadData = this._uploadData.retrieve({id: id}); - - if (!this._preventRetries[id] && this._options.retry.enableAuto && uploadData.status !== qq.status.PAUSED) { + if (!this._preventRetries[id] && this._options.retry.enableAuto) { this._autoRetries[id] = 0; } }, diff --git a/test/unit/chunked-uploads.js b/test/unit/chunked-uploads.js index 92f2392f8..9555ffdee 100644 --- a/test/unit/chunked-uploads.js +++ b/test/unit/chunked-uploads.js @@ -201,8 +201,6 @@ if (qqtest.canDownloadFileAsBlob) { } function testChunkedEveryFailureAndRecovery(done) { - assert.expect(6 + (expectedChunks * 17) + (expectedChunks * 6), done); - var alreadyFailed = false, uploader = new qq.FineUploaderBasic({ request: { @@ -268,6 +266,9 @@ if (qqtest.canDownloadFileAsBlob) { assert.equal(expectedChunks, chunksSent, "Wrong # of chunks sent."); assert.equal(expectedChunks, chunksSucceeded, "Wrong # of chunks succeeded"); assert.equal(response.testParam, "testVal"); + assert.equal(response.success, true); + + done(); } } }), From ac1b165aa631eb6881ce3e78c70a9f54124dcf43 Mon Sep 17 00:00:00 2001 From: Ray Nicholus Date: Fri, 26 Jan 2018 20:45:39 -0600 Subject: [PATCH 3/4] this will be v5.15.6 --- client/js/version.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/client/js/version.js b/client/js/version.js index e36d26931..cfb31675a 100644 --- a/client/js/version.js +++ b/client/js/version.js @@ -1,2 +1,2 @@ /*global qq */ -qq.version = "5.15.5"; +qq.version = "5.15.6"; From cfbfa3bb9f113594af4aab9c6d145b288354bff9 Mon Sep 17 00:00:00 2001 From: Ray Nicholus Date: Fri, 26 Jan 2018 20:46:01 -0600 Subject: [PATCH 4/4] this will be v5.15.6 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index cd91b3e9d..22fba21eb 100644 --- a/package.json +++ b/package.json @@ -3,7 +3,7 @@ "title": "Fine Uploader", "main": "lib/traditional.js", "types" : "typescript/fine-uploader.d.ts", - "version": "5.15.5", + "version": "5.15.6", "description": "Multiple file upload plugin with progress-bar, drag-and-drop, direct-to-S3 & Azure uploading, client-side image scaling, preview generation, form support, chunking, auto-resume, and tons of other features.", "keywords": [ "amazon",