Skip to content

Commit 9f7fec4

Browse files
committed
fix(preprocess): do not preprocess more files then simultaneousUploads opt
1 parent 557e0ba commit 9f7fec4

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/flow.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,8 +1245,6 @@
12451245
return;
12461246
case 1:
12471247
return;
1248-
case 2:
1249-
break;
12501248
}
12511249
}
12521250
if (this.flowObj.opts.testChunks && !this.tested) {
@@ -1293,7 +1291,7 @@
12931291
* @returns {string} 'pending', 'uploading', 'success', 'error'
12941292
*/
12951293
status: function () {
1296-
if (this.pendingRetry) {
1294+
if (this.pendingRetry || this.preprocessState === 1) {
12971295
// if pending retry then that's effectively the same as actively uploading,
12981296
// there might just be a slight delay before the retry starts
12991297
return 'uploading';

test/uploadSpec.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -388,6 +388,25 @@ describe('upload file', function() {
388388
expect(error).not.toHaveBeenCalled();
389389
});
390390

391+
392+
393+
it('should preprocess chunks and wait for preprocess to finish', function () {
394+
flow.opts.simultaneousUploads = 1;
395+
var preprocess = jasmine.createSpy('preprocess');
396+
flow.opts.preprocess = preprocess;
397+
flow.addFile(new Blob(['abc']));
398+
flow.addFile(new Blob(['abca']));
399+
var file = flow.files[0];
400+
var secondFile = flow.files[1];
401+
flow.upload();
402+
expect(requests.length).toBe(0);
403+
expect(preprocess).wasCalledWith(file.chunks[0]);
404+
expect(preprocess).wasNotCalledWith(secondFile.chunks[0]);
405+
406+
flow.upload();
407+
expect(preprocess).wasNotCalledWith(secondFile.chunks[0]);
408+
});
409+
391410
it('should have upload speed', function() {
392411
var clock = sinon.useFakeTimers();
393412
flow.opts.testChunks = false;

0 commit comments

Comments
 (0)