exports['test_check_connection_failure'] = function(test, assert) { var port = testUtil.getPort(); var check = new tcpCheck.TCPCheck({'ip_address': '127.0.0.1', 'port': port, 'type': tcpCheck.config.types.CONNECTION_CHECK}); check.run(function(result) { assert.equal(result.status, CheckStatus.ERROR); assert.match(result.details, /(connection refused|connection timed out|ETIMEDOUT)/i); test.finish(); }); };
exports['test_check_connection_timeout'] = function(test, assert) { var port = testUtil.getPort(); var check = new tcpCheck.TCPCheck({'ip_address': '74.125.39.104', 'port': port, 'type': tcpCheck.config.types.CONNECTION_CHECK, 'connect_timeout': 2000}); check.run(function(result) { assert.equal(result.status, CheckStatus.ERROR); assert.match(result.details, /connection timed out/i); test.finish(); }); };
testUtil.runTestTcpServer('127.0.0.1', port, responseDictionary, true, function() { var self = this; var check = new tcpCheck.TCPCheck({'ip_address': '127.0.0.1', 'port': port, 'type': tcpCheck.config.types.CONNECTION_CHECK}); check.run(function(result) { assert.equal(result.status, CheckStatus.SUCCESS); assert.match(result.details, /established connection to /i); self.close(); test.finish(); }); });
var tcp_server = testUtil.runTestTcpServer('127.0.0.1', port, responseDictionary, true, function() { var self = this; var check = new tcpCheck.TCPCheck({'ip_address': '127.0.0.1', 'port': port, 'type': tcpCheck.config.types.RESPONSE_REGEX_MATCH, 'match_value': /blah/i}); check.run(function(result) { assert.equal(result.status, CheckStatus.ERROR); assert.match(result.details, /didn.?t match the regular/i); self.close(); test.finish(); }); });
testUtil.runTestTcpServer('127.0.0.1', port, responseDictionary, true, function() { var self = this; var check = new tcpCheck.TCPCheck({'ip_address': '127.0.0.1', 'port': port, 'type': tcpCheck.config.types.RESPONSE_REGEX_MATCH, 'command': 'stats 12345', 'match_value': /.*keys 12345.*/i}); check.run(function(result) { assert.equal(result.status, CheckStatus.SUCCESS); assert.match(result.details, /matched the regular/i); self.close(); test.finish(); }); });
exports['test_invalid_ip_address'] = function(test, assert) { test.skip('Broken in node 0.4.9, ENOTFOUND is never thrown'); var port = testUtil.getPort(); var check = new tcpCheck.TCPCheck({'ip_address': '999.99.99.99', 'port': port, 'type': tcpCheck.config.types.CONNECTION_CHECK, 'idle_timeout': 2000}); check.run(function(result) { assert.equal(result.status, CheckStatus.ERROR); assert.match(result.details, /domain name not found/i); test.finish(); }); };