1'use strict'; 2 3const common = require('../common'); 4const assert = require('assert'); 5const net = require('net'); 6 7const big = Buffer.alloc(1024 * 1024); 8 9const handler = common.mustCall((socket) => { 10 socket.end(big); 11 server.close(); 12}); 13 14const onListen = common.mustCall(() => { 15 let prev = 0; 16 17 function checkRaise(value) { 18 assert(value > prev); 19 prev = value; 20 } 21 22 const onData = common.mustCallAtLeast((chunk) => { 23 checkRaise(socket.bytesRead); 24 }); 25 26 const onEnd = common.mustCall(() => { 27 assert.strictEqual(socket.bytesRead, prev); 28 assert.strictEqual(big.length, prev); 29 }); 30 31 const onClose = common.mustCall(() => { 32 assert(!socket._handle); 33 assert.strictEqual(socket.bytesRead, prev); 34 assert.strictEqual(big.length, prev); 35 }); 36 37 const onConnect = common.mustCall(() => { 38 socket.on('data', onData); 39 socket.on('end', onEnd); 40 socket.on('close', onClose); 41 socket.end(); 42 }); 43 44 const socket = net.connect(server.address().port, onConnect); 45}); 46 47const server = net.createServer(handler).listen(0, onListen); 48