nodejs/test/parallel/test-net-connect-handle-econnrefused.js

26 lines
499 B
JavaScript
Raw Normal View History

'use strict';
2010-11-29 17:36:59 -08:00
var common = require('../common');
var net = require('net');
var assert = require('assert');
// Hopefully nothing is running on common.PORT
var c = net.createConnection(common.PORT);
2010-12-05 01:45:52 +03:00
c.on('connect', function() {
console.error('connected?!');
2010-11-29 17:36:59 -08:00
assert.ok(false);
});
2010-11-29 17:36:59 -08:00
var gotError = false;
2010-12-05 01:45:52 +03:00
c.on('error', function(e) {
console.error('couldn\'t connect.');
2010-11-29 17:36:59 -08:00
gotError = true;
2011-02-04 14:35:14 -08:00
assert.equal('ECONNREFUSED', e.code);
2010-11-29 17:36:59 -08:00
});
2010-12-05 01:45:52 +03:00
process.on('exit', function() {
2010-11-29 17:36:59 -08:00
assert.ok(gotError);
});