示例#1
0
exports['test_incoming_restart_command'] = function() {
  var n = 0;
  var logBuffer = [];
  var port = test.getPort();
  var agent = new AgentTest();

  test.runTestTcpServer('127.0.0.1', port, responseDictionary, false, function(connection) {
    var self = this;
    agent.start(port, '127.0.0.1');

    setTimeout(function() {
      var stream;
      n++;
      assert.ok(agent._connected);
      assert.equal(agent.logBufferContains('restart', 'incoming'), false);

      stream = self._streams[0];
      stream.write('restart\n');
    }, 300);

    setTimeout(function() {
      agent.stop();
      self.close();
      assert.equal(n, 1);
    }, 700);
  });
};
示例#2
0
exports['test_command_queuing'] = function() {
  var n = 0;
  var port = test.getPort();
  var agent = new AgentTest();

  test.runTestTcpServer('127.0.0.1', port, responseDictionary, false, function(connection) {
    var self = this;
    agent.start(port, '127.0.0.1');

    setTimeout(function() {
      n++;
      var stream;
      agent._connected = false;
      assert.ok(!agent._connected);

      agent.sendCommand('run_check', {});
    }, 200);

    setTimeout(function() {
      n++;
      var pendingCommands = agent._pendingCommandsQueue;

      assert.ok(pendingCommands.length > 0);
      assert.equal(pendingCommands[0][0], 'run_check');
    }, 800);

    setTimeout(function() {
      agent.stop();
      self.close();
      assert.equal(n, 2);
    }, 900);
  });
};
示例#3
0
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();
  });
};
示例#4
0
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();
  });
};
示例#5
0
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();
  });
};
示例#6
0
exports['test_check_connection_success'] = function(test, assert) {
  var port = testUtil.getPort();

  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();
    });
  });
};
示例#7
0
exports['test_agent_connection'] = function() {
// Test agent connection
  var port = test.getPort();
  var agent = new AgentTest();

  test.runTestTcpServer('127.0.0.1', port, {}, false, function() {
    var self = this;
    agent.start(port, '127.0.0.1');

    setTimeout(function() {
      agent.stop();
      self.close();
      assert.ok(agent._connected);
    }, 200);
  });
};
示例#8
0
exports['test_check_response_regex_match_error'] = function(test, assert) {
  var port = testUtil.getPort();

  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();
    });
  });
};
示例#9
0
exports['test_check_response_regex_match_success_2'] = function(test, assert) {
  var port = testUtil.getPort();

  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();
    });
  });
};
示例#10
0
exports['test_agent_hello_and_ping'] = function() {
  var n = 0;
  var port = test.getPort();
  var agent = new AgentTest();
  test.runTestTcpServer('127.0.0.1', port, responseDictionary, false, function(connection) {
    var self = this;
    agent.start(port, '127.0.0.1');

    setTimeout(function() {
      n++;
      assert.ok(agent._connected);
    }, 200);

    var intervalId = setInterval(function() {
      if (agent._pongGotCount >= 2) {
        clearInterval(intervalId);
        agent.stop();
        self.close();
        assert.equal(n, 1);
        assert.equal(agent._pingSentCount, agent._pongGotCount);
      }
    }, 200);
  });
};