Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
  • Loading branch information
ImHype committed Apr 29, 2019
commit 889d6198ec99e9d6cacbda67a1b773a2aaa23357
39 changes: 24 additions & 15 deletions test/parallel/test-net-bytes-read.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,33 +6,42 @@ const net = require('net');

const big = Buffer.alloc(1024 * 1024);

const server = net.createServer((socket) => {
const handler = common.mustCall((socket) => {
socket.end(big);
server.close();
}).listen(0, () => {
});

const onListen = common.mustCall(() => {
let prev = 0;

function checkRaise(value) {
assert(value > prev);
prev = value;
}

const socket = net.connect(server.address().port, () => {
socket.on('data', (chunk) => {
checkRaise(socket.bytesRead);
});
const onData = common.mustCallAtLeast((chunk) => {
checkRaise(socket.bytesRead);
});

socket.on('end', common.mustCall(() => {
assert.strictEqual(socket.bytesRead, prev);
assert.strictEqual(big.length, prev);
}));
const onEnd = common.mustCall(() => {
assert.strictEqual(socket.bytesRead, prev);
assert.strictEqual(big.length, prev);
});

socket.on('close', common.mustCall(() => {
assert(!socket._handle);
assert.strictEqual(socket.bytesRead, prev);
assert.strictEqual(big.length, prev);
}));
const onClose = common.mustCall(() => {
assert(!socket._handle);
assert.strictEqual(socket.bytesRead, prev);
assert.strictEqual(big.length, prev);
});

const onConnect = common.mustCall(() => {
socket.on('data', onData);
socket.on('end', onEnd);
socket.on('close', onClose);
socket.end();
});

const socket = net.connect(server.address().port, onConnect);
});

const server = net.createServer(handler).listen(0, onListen);