(port, host)
| 25 | const net = require('net'); |
| 26 | |
| 27 | function pingPongTest(port, host) { |
| 28 | const N = 1000; |
| 29 | let count = 0; |
| 30 | let sentPongs = 0; |
| 31 | let sent_final_ping = false; |
| 32 | |
| 33 | const server = net.createServer( |
| 34 | { allowHalfOpen: true }, |
| 35 | common.mustCall(onSocket) |
| 36 | ); |
| 37 | |
| 38 | function onSocket(socket) { |
| 39 | assert.strictEqual(socket.server, server); |
| 40 | assert.strictEqual( |
| 41 | server, |
| 42 | server.getConnections(common.mustSucceed((connections) => { |
| 43 | assert.strictEqual(connections, 1); |
| 44 | })) |
| 45 | ); |
| 46 | |
| 47 | socket.setNoDelay(); |
| 48 | socket.timeout = 0; |
| 49 | |
| 50 | socket.setEncoding('utf8'); |
| 51 | socket.on('data', common.mustCall(function(data) { |
| 52 | // Since we never queue data (we're always waiting for the PING |
| 53 | // before sending a pong) the writeQueueSize should always be less |
| 54 | // than one message. |
| 55 | assert.ok(socket.bufferSize >= 0 && socket.bufferSize <= 4); |
| 56 | |
| 57 | assert.strictEqual(socket.writable, true); |
| 58 | assert.strictEqual(socket.readable, true); |
| 59 | assert.ok(count <= N); |
| 60 | assert.strictEqual(data, 'PING'); |
| 61 | |
| 62 | socket.write('PONG', common.mustCall(function() { |
| 63 | sentPongs++; |
| 64 | })); |
| 65 | }, N + 1)); |
| 66 | |
| 67 | socket.on('end', common.mustCall(function() { |
| 68 | assert.strictEqual(socket.allowHalfOpen, true); |
| 69 | assert.strictEqual(socket.writable, true); // Because allowHalfOpen |
| 70 | assert.strictEqual(socket.readable, false); |
| 71 | socket.end(); |
| 72 | })); |
| 73 | |
| 74 | socket.on('error', common.mustNotCall()); |
| 75 | |
| 76 | socket.on('close', common.mustCall(function() { |
| 77 | assert.strictEqual(socket.writable, false); |
| 78 | assert.strictEqual(socket.readable, false); |
| 79 | socket.server.close(); |
| 80 | })); |
| 81 | } |
| 82 | |
| 83 | |
| 84 | server.listen(port, host, common.mustCall(function() { |
no test coverage detected
searching dependent graphs…