test: replace closure with arrow function
PR-URL: https://github.com/nodejs/node/pull/24489 Reviewed-By: Franziska Hinkelmann <franziska.hinkelmann@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
parent
282e533636
commit
4d35fa7d07
@ -29,46 +29,46 @@ let starttime = null;
|
|||||||
let timeouttime = null;
|
let timeouttime = null;
|
||||||
const timeout = 1000;
|
const timeout = 1000;
|
||||||
|
|
||||||
const echo_server = net.createServer(function(socket) {
|
const echo_server = net.createServer((socket) => {
|
||||||
socket.setTimeout(timeout);
|
socket.setTimeout(timeout);
|
||||||
|
|
||||||
socket.on('timeout', function() {
|
socket.on('timeout', () => {
|
||||||
console.log('server timeout');
|
console.log('server timeout');
|
||||||
timeouttime = new Date();
|
timeouttime = new Date();
|
||||||
console.dir(timeouttime);
|
console.dir(timeouttime);
|
||||||
socket.destroy();
|
socket.destroy();
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('error', function(e) {
|
socket.on('error', (e) => {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
'Server side socket should not get error. We disconnect willingly.');
|
'Server side socket should not get error. We disconnect willingly.');
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('data', function(d) {
|
socket.on('data', (d) => {
|
||||||
console.log(d);
|
console.log(d);
|
||||||
socket.write(d);
|
socket.write(d);
|
||||||
});
|
});
|
||||||
|
|
||||||
socket.on('end', function() {
|
socket.on('end', () => {
|
||||||
socket.end();
|
socket.end();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
echo_server.listen(common.PORT, function() {
|
echo_server.listen(common.PORT, () => {
|
||||||
console.log(`server listening at ${common.PORT}`);
|
console.log(`server listening at ${common.PORT}`);
|
||||||
|
|
||||||
const client = net.createConnection(common.PORT);
|
const client = net.createConnection(common.PORT);
|
||||||
client.setEncoding('UTF8');
|
client.setEncoding('UTF8');
|
||||||
client.setTimeout(0); // disable the timeout for client
|
client.setTimeout(0); // disable the timeout for client
|
||||||
client.on('connect', function() {
|
client.on('connect', () => {
|
||||||
console.log('client connected.');
|
console.log('client connected.');
|
||||||
client.write('hello\r\n');
|
client.write('hello\r\n');
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('data', function(chunk) {
|
client.on('data', (chunk) => {
|
||||||
assert.strictEqual(chunk, 'hello\r\n');
|
assert.strictEqual(chunk, 'hello\r\n');
|
||||||
if (exchanges++ < 5) {
|
if (exchanges++ < 5) {
|
||||||
setTimeout(function() {
|
setTimeout(() => {
|
||||||
console.log('client write "hello"');
|
console.log('client write "hello"');
|
||||||
client.write('hello\r\n');
|
client.write('hello\r\n');
|
||||||
}, 500);
|
}, 500);
|
||||||
@ -81,22 +81,22 @@ echo_server.listen(common.PORT, function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('timeout', function() {
|
client.on('timeout', () => {
|
||||||
throw new Error("client timeout - this shouldn't happen");
|
throw new Error("client timeout - this shouldn't happen");
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('end', function() {
|
client.on('end', () => {
|
||||||
console.log('client end');
|
console.log('client end');
|
||||||
client.end();
|
client.end();
|
||||||
});
|
});
|
||||||
|
|
||||||
client.on('close', function() {
|
client.on('close', () => {
|
||||||
console.log('client disconnect');
|
console.log('client disconnect');
|
||||||
echo_server.close();
|
echo_server.close();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
process.on('exit', function() {
|
process.on('exit', () => {
|
||||||
assert.ok(starttime != null);
|
assert.ok(starttime != null);
|
||||||
assert.ok(timeouttime != null);
|
assert.ok(timeouttime != null);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user