MCPcopy Index your code
hub / github.com/nodejs/node / testServer

Function testServer

test/parallel/test-child-process-fork-net-server.js:86–149  ·  view source on GitHub ↗
(callback)

Source from the content-addressed store, hash-verified

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);

Calls 11

decMethod · 0.95
listenMethod · 0.80
callbackFunction · 0.70
sendMethod · 0.65
closeMethod · 0.65
connectMethod · 0.65
addressMethod · 0.65
debugFunction · 0.50
onMethod · 0.45
destroyMethod · 0.45
removeListenerMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…