-
Notifications
You must be signed in to change notification settings - Fork 116
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add integration test for large file upload #1094
base: develop
Are you sure you want to change the base?
Add integration test for large file upload #1094
Conversation
Codecov Report
@@ Coverage Diff @@
## develop #1094 +/- ##
========================================
Coverage 91.10% 91.10%
========================================
Files 42 42
Lines 2563 2563
Branches 735 735
========================================
Hits 2335 2335
Misses 228 228
Flags with carried forward coverage won't be shown. Click here to find out more. Continue to review full report at Codecov.
|
c3b92c4
to
44a3088
Compare
0c90ac5
to
77162d1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's see if we can achieve this by overriding the file resolver and sending a dynamic read stream.
stat: function (src, cb) { | ||
cb(null, {isFile: function () { return true; }, mode: 33188}); | ||
}, | ||
createReadStream: function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it's returning a buffer instead of a. stream?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed, returning a stream in case of file
mode, when returning stream in case of form-data
it is not working response
is undefined in that case, hence using Buffer.alloc()
. I tried reading about how form-data
works but couldn't find a solution, do let me know if I am missing something here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you can't re-use the same stream. Return a new stream here instead of pushing data to a common stream.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tried using the new stream still I get response as undefined
the error has calls going in recursion will need to verify where it is failing in case of streams.
d6f5c19
to
5d2b9d4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, move the integration test to /test/integration/benchmark
.
CHANGELOG.yaml
Outdated
@@ -1,3 +1,7 @@ | |||
master: | |||
chores: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wrong indentation.
@@ -1,7 +1,8 @@ | |||
var fs = require('fs'), | |||
expect = require('chai').expect, | |||
sinon = require('sinon'), | |||
IS_BROWSER = typeof window !== 'undefined'; | |||
IS_BROWSER = typeof window !== 'undefined', |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it's not working in the browser?
@@ -48,4 +48,19 @@ httpServer.on('/custom-reason', function (req, res) { | |||
res.end(); | |||
}); | |||
|
|||
httpServer.on('/file-upload', function (req, res) { | |||
if (req.method === 'POST') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why it only supports POST
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was supporting POST
only as currently API was only being used for upload files. Have added GET
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What I meant was method doesn't matter. Don't have method-specific checks.
let body = []; | ||
|
||
req.on('data', function (data) { | ||
body.push(data); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Buffer has a concat
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than calling concat()
each time on buffer which will be slow can't we push all the buffers in the array and then call concat()
at once like Buffer.concat(body)
. Please let me know if there is any issue with this approach just for learning.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Have you benchmarked? Share the results.
test/fixtures/servers/http.js
Outdated
@@ -48,4 +48,19 @@ httpServer.on('/custom-reason', function (req, res) { | |||
res.end(); | |||
}); | |||
|
|||
httpServer.on('/file-upload', function (req, res) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's not parsing any file, this can just be /upload
.
test/fixtures/servers/http.js
Outdated
|
||
req.on('end', function () { | ||
res.writeHead(200, {'content-type': 'text/plain'}); | ||
res.end('received-content-length:' + Buffer.concat(body).byteLength); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of an API response is this?
Either return the bytes received or a JSON response.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was returning a plain-text response similar to what is being done in Line 38 of this file, do let me know if I need to change that as well.
stat: function (src, cb) { | ||
cb(null, {isFile: function () { return true; }, mode: 33188}); | ||
}, | ||
createReadStream: function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because you can't re-use the same stream. Return a new stream here instead of pushing data to a common stream.
Added integration test for file upload of 50 MB.
5d2b9d4
to
9862d37
Compare
Added integration test for file upload of 50 MB.