1// Flags: --expose-internals 2'use strict'; 3require('../common'); 4const assert = require('assert'); 5const net = require('net'); 6const { internalBinding } = require('internal/test/binding'); 7const TCPWrap = internalBinding('tcp_wrap').TCP; 8 9const echoServer = net.createServer(function(connection) { 10 connection.end(); 11}); 12echoServer.listen(0); 13 14let callCount = 0; 15 16const Socket = net.Socket; 17const setNoDelay = TCPWrap.prototype.setNoDelay; 18 19TCPWrap.prototype.setNoDelay = function(enable) { 20 setNoDelay.call(this, enable); 21 callCount++; 22}; 23 24echoServer.on('listening', function() { 25 const sock1 = new Socket(); 26 // setNoDelay before the handle is created 27 // there is probably a better way to test this 28 29 const s = sock1.setNoDelay(); 30 assert.ok(s instanceof net.Socket); 31 sock1.connect(this.address().port); 32 sock1.on('end', function() { 33 assert.strictEqual(callCount, 1); 34 echoServer.close(); 35 }); 36}); 37