test: add mustcall in test-net-bytes-read.js

* add mustcall() on createServerListener
* add mustcall() on listenPortListener
* add mustCall() on onConnectListener
* add mustCallAtLeast() on onDataListener

PR-URL: https://github.com/nodejs/node/pull/27471
Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
This commit is contained in:
imhype 2019-04-29 11:08:53 +08:00 committed by Rich Trott
parent 64284aad38
commit aacc046e6b

View File

@ -6,10 +6,12 @@ const net = require('net');
const big = Buffer.alloc(1024 * 1024); const big = Buffer.alloc(1024 * 1024);
const server = net.createServer((socket) => { const handler = common.mustCall((socket) => {
socket.end(big); socket.end(big);
server.close(); server.close();
}).listen(0, () => { });
const onListen = common.mustCall(() => {
let prev = 0; let prev = 0;
function checkRaise(value) { function checkRaise(value) {
@ -17,22 +19,29 @@ const server = net.createServer((socket) => {
prev = value; prev = value;
} }
const socket = net.connect(server.address().port, () => { const onData = common.mustCallAtLeast((chunk) => {
socket.on('data', (chunk) => { checkRaise(socket.bytesRead);
checkRaise(socket.bytesRead); });
});
socket.on('end', common.mustCall(() => { const onEnd = common.mustCall(() => {
assert.strictEqual(socket.bytesRead, prev); assert.strictEqual(socket.bytesRead, prev);
assert.strictEqual(big.length, prev); assert.strictEqual(big.length, prev);
})); });
socket.on('close', common.mustCall(() => { const onClose = common.mustCall(() => {
assert(!socket._handle); assert(!socket._handle);
assert.strictEqual(socket.bytesRead, prev); assert.strictEqual(socket.bytesRead, prev);
assert.strictEqual(big.length, prev); assert.strictEqual(big.length, prev);
})); });
const onConnect = common.mustCall(() => {
socket.on('data', onData);
socket.on('end', onEnd);
socket.on('close', onClose);
socket.end(); socket.end();
}); });
const socket = net.connect(server.address().port, onConnect);
}); });
const server = net.createServer(handler).listen(0, onListen);