Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: improve test-tcp-wrap-listen #12599

Closed
wants to merge 1 commit into from
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
28 changes: 5 additions & 23 deletions test/parallel/test-tcp-wrap-listen.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,6 @@ port = port.port;

server.listen(128);

let sliceCount = 0;
let eofCount = 0;

let writeCount = 0;
let recvCount = 0;

server.onconnection = (err, client) => {
assert.strictEqual(0, client.writeQueueSize);
console.log('got connection');
Expand All @@ -34,7 +28,7 @@ server.onconnection = (err, client) => {

client.readStart();
client.pendingWrites = [];
client.onread = (err, buffer) => {
client.onread = common.mustCall((err, buffer) => {
if (buffer) {
assert.ok(buffer.length > 0);

Expand All @@ -51,7 +45,7 @@ server.onconnection = (err, client) => {
assert.strictEqual(0, client.writeQueueSize);

if (req.async)
req.oncomplete = done;
req.oncomplete = common.mustCall(done);
else
process.nextTick(done.bind(null, 0, client, req));

Expand All @@ -66,20 +60,16 @@ server.onconnection = (err, client) => {
console.log('client.writeQueueSize: ' + client.writeQueueSize);
assert.strictEqual(0, client.writeQueueSize);

writeCount++;
console.log('write ' + writeCount);
maybeCloseClient();
}

sliceCount++;
} else {
console.log('eof');
client.gotEOF = true;
server.close();
eofCount++;
maybeCloseClient();
}
};
}, 2);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably will never happen but this could be called more than twice.

};

const net = require('net');
Expand All @@ -89,18 +79,10 @@ const c = net.createConnection(port);
c.on('connect', common.mustCall(() => { c.end('hello world'); }));

c.setEncoding('utf8');
c.on('data', (d) => {
c.on('data', common.mustCall((d) => {
assert.strictEqual('hello world', d);
recvCount++;
});
}));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, though highly unlikely, this could be called more than once


c.on('close', () => {
console.error('client closed');
});

process.on('exit', () => {
assert.strictEqual(1, sliceCount);
assert.strictEqual(1, eofCount);
assert.strictEqual(1, writeCount);
assert.strictEqual(1, recvCount);
});