Skip to content

Commit

Permalink
test: add mustcall in test-net-bytes-read.js
Browse files Browse the repository at this point in the history
* add mustcall() on createServerListener
* add mustcall() on listenPortListener
* add mustCall() on onConnectListener
* add mustCallAtLeast() on onDataListener

PR-URL: #27471
Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com>
Reviewed-By: Masashi Hirano <shisama07@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
  • Loading branch information
ImHype authored and targos committed May 1, 2019
1 parent 7be1e0a commit 86c27c6
Showing 1 changed file with 24 additions and 15 deletions.
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);

0 comments on commit 86c27c6

Please sign in to comment.