node/test/parallel/test-net-persistent-nodelay.js
Gibson Fahnestock 7a0e462f9f test: use eslint to fix var->const/let
Manually fix issues that eslint --fix couldn't do automatically.

PR-URL: https://github.com/nodejs/node/pull/10685
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
2017-01-11 11:43:52 +00:00

35 lines
823 B
JavaScript

'use strict';
require('../common');
const assert = require('assert');
const net = require('net');
const TCPWrap = process.binding('tcp_wrap').TCP;
const echoServer = net.createServer(function(connection) {
connection.end();
});
echoServer.listen(0);
let callCount = 0;
const Socket = net.Socket;
const setNoDelay = TCPWrap.prototype.setNoDelay;
TCPWrap.prototype.setNoDelay = function(enable) {
setNoDelay.call(this, enable);
callCount++;
};
echoServer.on('listening', function() {
const sock1 = new Socket();
// setNoDelay before the handle is created
// there is probably a better way to test this
const s = sock1.setNoDelay();
assert.ok(s instanceof net.Socket);
sock1.connect(this.address().port);
sock1.on('end', function() {
assert.equal(callCount, 1);
echoServer.close();
});
});