diff options
author | Fedor Indutny <fedor@indutny.com> | 2016-04-19 14:46:53 -0400 |
---|---|---|
committer | Fedor Indutny <fedor@indutny.com> | 2016-04-20 12:42:33 -0400 |
commit | 6198472d8390d9476f555c634b7aa66ce6c6d0fe (patch) | |
tree | 506f7b4824a8754ff2645b49077e918af627386b /test/parallel/test-net-bytes-read.js | |
parent | e1cf634a0bd0cae2b54c60c8f19fc29079bdc309 (diff) | |
download | android-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.tar.gz android-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.tar.bz2 android-node-v8-6198472d8390d9476f555c634b7aa66ce6c6d0fe.zip |
stream_base: expose `bytesRead` getter
This will provide `bytesRead` data on consumed sockets.
Fix: #3021
PR-URL: https://github.com/nodejs/node/pull/6284
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'test/parallel/test-net-bytes-read.js')
-rw-r--r-- | test/parallel/test-net-bytes-read.js | 37 |
1 files changed, 37 insertions, 0 deletions
diff --git a/test/parallel/test-net-bytes-read.js b/test/parallel/test-net-bytes-read.js new file mode 100644 index 0000000000..ba2bc160d0 --- /dev/null +++ b/test/parallel/test-net-bytes-read.js @@ -0,0 +1,37 @@ +'use strict'; + +const common = require('../common'); +const assert = require('assert'); +const net = require('net'); + +const big = Buffer.alloc(1024 * 1024); + +const server = net.createServer((socket) => { + socket.end(big); + server.close(); +}).listen(common.PORT, () => { + let prev = 0; + + function checkRaise(value) { + assert(value > prev); + prev = value; + } + + const socket = net.connect(common.PORT, () => { + socket.on('data', (chunk) => { + checkRaise(socket.bytesRead); + }); + + socket.on('end', common.mustCall(() => { + assert.equal(socket.bytesRead, prev); + assert.equal(big.length, prev); + })); + + socket.on('close', common.mustCall(() => { + assert(!socket._handle); + assert.equal(socket.bytesRead, prev); + assert.equal(big.length, prev); + })); + }); + socket.end(); +}); |