Skip to content

Commit

Permalink
test: refactor test to use arrow functions
Browse files Browse the repository at this point in the history
In `test/parallel/test-cluster-send-deadlock.js`, callbacks use
anonymous closure functions. It is safe to replace them with arrow
functions since these callbacks don't contain references to `this`,
`super` or `arguments`. This results in shorter functions.

PR-URL: nodejs#24479
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Gireesh Punathil <[email protected]>
  • Loading branch information
sagirk authored and gireeshpunathil committed Nov 22, 2018
1 parent 4d35fa7 commit a67b22a
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions test/parallel/test-cluster-send-deadlock.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,42 +30,42 @@ const net = require('net');

if (cluster.isMaster) {
const worker = cluster.fork();
worker.on('exit', function(code, signal) {
worker.on('exit', (code, signal) => {
assert.strictEqual(code, 0, `Worker exited with an error code: ${code}`);
assert(!signal, `Worker exited by a signal: ${signal}`);
server.close();
});

const server = net.createServer(function(socket) {
const server = net.createServer((socket) => {
worker.send('handle', socket);
});

server.listen(0, function() {
server.listen(0, () => {
worker.send({ message: 'listen', port: server.address().port });
});
} else {
process.on('message', function(msg, handle) {
process.on('message', (msg, handle) => {
if (msg.message && msg.message === 'listen') {
assert(msg.port);
const client1 = net.connect({
host: 'localhost',
port: msg.port
}, function() {
}, () => {
const client2 = net.connect({
host: 'localhost',
port: msg.port
}, function() {
}, () => {
client1.on('close', onclose);
client2.on('close', onclose);
client1.end();
client2.end();
});
});
let waiting = 2;
function onclose() {
const onclose = () => {
if (--waiting === 0)
cluster.worker.disconnect();
}
};
} else {
process.send('reply', handle);
}
Expand Down

0 comments on commit a67b22a

Please sign in to comment.