(callback)
| 84 | |
| 85 | // Send net.Server to child and test by connecting. |
| 86 | function testServer(callback) { |
| 87 | |
| 88 | // Destroy server execute callback when done. |
| 89 | const countdown = new Countdown(2, common.mustCall(() => { |
| 90 | server.on('close', common.mustCall(() => { |
| 91 | debug('PARENT: server closed'); |
| 92 | child.send({ what: 'close' }); |
| 93 | })); |
| 94 | server.close(); |
| 95 | })); |
| 96 | |
| 97 | // We expect 4 connections and close events. |
| 98 | const connections = new Countdown(4, () => countdown.dec()); |
| 99 | const closed = new Countdown(4, () => countdown.dec()); |
| 100 | |
| 101 | // Create server and send it to child. |
| 102 | const server = net.createServer(); |
| 103 | |
| 104 | // TODO(@jasnell): The specific number of times the connection |
| 105 | // event is emitted appears to be variable across platforms. |
| 106 | // Need to investigate why and whether it can be made |
| 107 | // more consistent. |
| 108 | server.on('connection', (socket) => { |
| 109 | debug('PARENT: got connection'); |
| 110 | socket.destroy(); |
| 111 | connections.dec(); |
| 112 | }); |
| 113 | |
| 114 | server.on('listening', common.mustCall(() => { |
| 115 | debug('PARENT: server listening'); |
| 116 | child.send({ what: 'server' }, server); |
| 117 | })); |
| 118 | server.listen(0); |
| 119 | |
| 120 | // Handle client messages. |
| 121 | // TODO(@jasnell): The specific number of times the message |
| 122 | // event is emitted appears to be variable across platforms. |
| 123 | // Need to investigate why and whether it can be made |
| 124 | // more consistent. |
| 125 | const messageHandlers = common.mustCallAtLeast((msg) => { |
| 126 | if (msg.what === 'listening') { |
| 127 | // Make connections. |
| 128 | let socket; |
| 129 | for (let i = 0; i < 4; i++) { |
| 130 | socket = net.connect(server.address().port, common.mustCall(() => { |
| 131 | debug('CLIENT: connected'); |
| 132 | })); |
| 133 | socket.on('close', common.mustCall(() => { |
| 134 | closed.dec(); |
| 135 | debug('CLIENT: closed'); |
| 136 | })); |
| 137 | } |
| 138 | |
| 139 | } else if (msg.what === 'connection') { |
| 140 | // Child got connection |
| 141 | connections.dec(); |
| 142 | } else if (msg.what === 'close') { |
| 143 | child.removeListener('message', messageHandlers); |
no test coverage detected
searching dependent graphs…