8000 test: add mustcall in test-net-bytes-read.js · nodejs/node@86c27c6 · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Commit 86c27c6

Browse files
ImHypetargos
authored andcommitted
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: #27471 Reviewed-By: Ouyang Yadong <oyydoibh@gmail.com> Reviewed-By: Masashi Hirano <shisama07@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
1 parent 7be1e0a commit 86c27c6

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

test/parallel/test-net-bytes-read.js

+24-15
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,42 @@ const net = require('net');
66

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

9-
const server = net.createServer((socket) => {
9+
const handler = common.mustCall((socket) => {
1010
socket.end(big);
1111
server.close();
12-
}).listen(0, () => {
12+
});
13+
14+
const onListen = common.mustCall(() => {
1315
let prev = 0;
1416

1517
function checkRaise(value) {
1618
assert(value > prev);
1719
prev = value;
1820
}
1921

20-
const socket = net.connect(server.address().port, () => {
21-
socket.on('data', (chunk) => {
22-
checkRaise(socket.bytesRead);
23-
});
22+
const onData = common.mustCallAtLeast((chunk) => {
23+
checkRaise(socket.bytesRead);
24+
});
2425

25-
socket.on('end', common.mustCall(() => {
26-
assert.strictEqual(socket.bytesRead, prev);
27-
assert.strictEqual(big.length, prev);
28-
}));
26+
const onEnd = common.mustCall(() => {
27+
assert.strictEqual(socket.bytesRead, prev);
28+
assert.strictEqual(big.length, prev);
29+
});
2930

30-
socket.on('close', common.mustCall(() => {
31-
assert(!socket._handle);
32-
assert.strictEqual(socket.bytesRead, prev);
33-
assert.strictEqual(big.length, prev);
34-
}));
31+
const onClose = common.mustCall(() => {
32+
assert(!socket._handle);
33+
assert.strictEqual(socket.bytesRead, prev);
34+
assert.strictEqual(big.length, prev);
35+
});
3536

37+
const onConnect = common.mustCall(() => {
38+
socket.on('data', onData);
39+
socket.on('end', onEnd);
40+
socket.on('close', onClose);
3641
socket.end();
3742
});
43+
44+
const socket = net.connect(server.address().port, onConnect);
3845
});
46+
47+
const server = net.createServer(handler).listen(0, onListen);

0 commit comments

Comments
 (0)
0