|
| 1 | +// On some platforms this test triggers an assertion in cluster.js. |
| 2 | +// The assertion protects against memory leaks. |
| 3 | +// https://github.com/nodejs/node/pull/3510 |
| 4 | + |
| 5 | +'use strict'; |
| 6 | +var common = require('../common'); |
| 7 | +var assert = require('assert'); |
| 8 | +var net = require('net'); |
| 9 | +var cluster = require('cluster'); |
| 10 | +cluster.schedulingPolicy = cluster.SCHED_NONE; |
| 11 | + |
| 12 | +if (cluster.isMaster) { |
| 13 | + var conn, worker1, worker2; |
| 14 | + |
| 15 | + worker1 = cluster.fork(); |
| 16 | + worker1.on('message', common.mustCall(function() { |
| 17 | + worker2 = cluster.fork(); |
| 18 | + worker2.on('online', function() { |
| 19 | + conn = net.connect(common.PORT, common.mustCall(function() { |
| 20 | + worker1.disconnect(); |
| 21 | + worker2.disconnect(); |
| 22 | + })); |
| 23 | + conn.on('error', function(e) { |
| 24 | + // ECONNRESET is OK |
| 25 | + if (e.code !== 'ECONNRESET') |
| 26 | + throw e; |
| 27 | + }); |
| 28 | + }); |
| 29 | + })); |
| 30 | + |
| 31 | + cluster.on('exit', function(worker, exitCode, signalCode) { |
| 32 | + assert(worker === worker1 || worker === worker2); |
| 33 | + assert.strictEqual(exitCode, 0); |
| 34 | + assert.strictEqual(signalCode, null); |
| 35 | + if (Object.keys(cluster.workers).length === 0) |
| 36 | + conn.destroy(); |
| 37 | + }); |
| 38 | + |
| 39 | + return; |
| 40 | +} |
| 41 | + |
| 42 | +var server = net.createServer(function(c) { |
| 43 | + c.end('bye'); |
| 44 | +}); |
| 45 | + |
| 46 | +server.listen(common.PORT, function() { |
| 47 | + process.send('listening'); |
| 48 | +}); |
0 commit comments