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

Function testSocket

test/parallel/test-child-process-fork-net-socket.js:54–85  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

52
53 // Send net.Socket to child.
54 function testSocket() {
55
56 // Create a new server and connect to it,
57 // but the socket will be handled by the child.
58 const server = net.createServer();
59 server.on('connection', mustCall((socket) => {
60 // TODO(@jasnell): Close does not seem to actually be called.
61 // It is not clear if it is needed.
62 socket.on('close', () => {
63 debug('CLIENT: socket closed');
64 });
65 child.send({ what: 'socket' }, socket);
66 }));
67 server.on('close', mustCall(() => {
68 debug('PARENT: server closed');
69 }));
70
71 server.listen(0, mustCall(() => {
72 debug('testSocket, listening');
73 const connect = net.connect(server.address().port);
74 let store = '';
75 connect.on('data', mustCallAtLeast((chunk) => {
76 store += chunk;
77 debug('CLIENT: got data');
78 }));
79 connect.on('close', mustCall(() => {
80 debug('CLIENT: closed');
81 assert.strictEqual(store, 'echo');
82 server.close();
83 }));
84 }));
85 }
86
87 const onReady = mustCall((msg) => {
88 if (msg.what !== 'ready') return;

Calls 9

mustCallAtLeastFunction · 0.85
listenMethod · 0.80
mustCallFunction · 0.70
sendMethod · 0.65
connectMethod · 0.65
addressMethod · 0.65
closeMethod · 0.65
debugFunction · 0.50
onMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…