<commit_before>local table = require('table')
local async = require('async')
local ConnectionStream = require('monitoring/default/client/connection_stream').ConnectionStream
local misc = require('monitoring/default/util/misc')
local helper = require('../helper')
local timer = require('timer')
local fixtures = require('../fixtures')
local constants = require('constants')
local consts = require('../../default/util/constants')
local Endpoint = require('../../default/endpoint').Endpoint
local path = require('path')

local exports = {}
local child

exports['test_reconnects'] = function(test, asserts)

  local options = {
    datacenter = 'test',
    stateDirectory = './tests',
    tls = { rejectUnauthorized = false }
  }

  local client = ConnectionStream:new('id', 'token', 'guid', options)

  local clientEnd = 0
  local reconnect = 0

  client:on('client_end', function(err)
    clientEnd = clientEnd + 1
  end)

  client:on('reconnect', function(err)
    reconnect = reconnect + 1
  end)

  local endpoints = {}
  for _, address in pairs(fixtures.TESTING_AGENT_ENDPOINTS) do
    -- split ip:port
    table.insert(endpoints, Endpoint:new(address))
  end

  async.series({
    function(callback)
      child = helper.start_server(callback)
    end,
    function(callback)
      client:on('handshake_success', misc.nCallbacks(callback, 3))
      local endpoints = {}
      for _, address in pairs(fixtures.TESTING_AGENT_ENDPOINTS) do
        -- split ip:port
        table.insert(endpoints, Endpoint:new(address))
      end
      client:createConnections(endpoints, function() end)
    end,
    function(callback)
      helper.stop_server(child)
      client:on('reconnect', misc.nCallbacks(callback, 3))
    end,
    function(callback)
      child = helper.start_server(function()
        client:on('handshake_success', misc.nCallbacks(callback, 3))
      end)
    end,
  }, function()
    helper.stop_server(child)
    asserts.ok(clientEnd > 0)
    asserts.ok(reconnect > 0)
    test.done()
  end)
end

exports['test_upgrades'] = function(test, asserts)
  local options, client, endpoints

  test.skip("Skip upgrades test until it is reliable")
  return nil

  -- Override the default download path
  consts.DEFAULT_DOWNLOAD_PATH = path.join('.', 'tmp')

  options = {
    datacenter = 'test',
    stateDirectory = './tests',
    tls = { rejectUnauthorized = false }
  }

  local endpoints = {}
  for _, address in pairs(fixtures.TESTING_AGENT_ENDPOINTS) do
    -- split ip:port
    table.insert(endpoints, Endpoint:new(address))
  end

  async.series({
    function(callback)
      child = helper.start_server(callback)
    end,
    function(callback)<commit_msg>monitoring: tests: net: disable test_upgrades<commit_after>local table = require('table')
local async = require('async')
local ConnectionStream = require('monitoring/default/client/connection_stream').ConnectionStream
local misc = require('monitoring/default/util/misc')
local helper = require('../helper')
local timer = require('timer')
local fixtures = require('../fixtures')
local constants = require('constants')
local consts = require('../../default/util/constants')
local Endpoint = require('../../default/endpoint').Endpoint
local path = require('path')

local exports = {}
local child

exports['test_reconnects'] = function(test, asserts)

  local options = {
    datacenter = 'test',
    stateDirectory = './tests',
    tls = { rejectUnauthorized = false }
  }

  local client = ConnectionStream:new('id', 'token', 'guid', options)

  local clientEnd = 0
  local reconnect = 0

  client:on('client_end', function(err)
    clientEnd = clientEnd + 1
  end)

  client:on('reconnect', function(err)
    reconnect = reconnect + 1
  end)

  local endpoints = {}
  for _, address in pairs(fixtures.TESTING_AGENT_ENDPOINTS) do
    -- split ip:port
    table.insert(endpoints, Endpoint:new(address))
  end

  async.series({
    function(callback)
      child = helper.start_server(callback)
    end,
    function(callback)
      client:on('handshake_success', misc.nCallbacks(callback, 3))
      local endpoints = {}
      for _, address in pairs(fixtures.TESTING_AGENT_ENDPOINTS) do
        -- split ip:port
        table.insert(endpoints, Endpoint:new(address))
      end
      client:createConnections(endpoints, function() end)
    end,
    function(callback)
      helper.stop_server(child)
      client:on('reconnect', misc.nCallbacks(callback, 3))
    end,
    function(callback)
      child = helper.start_server(function()
        client:on('handshake_success', misc.nCallbacks(callback, 3))
      end)
    end,
  }, function()
    helper.stop_server(child)
    asserts.ok(clientEnd > 0)
    asserts.ok(reconnect > 0)
    test.done()
  end)
end

exports['test_upgrades'] = function(test, asserts)
  local options, client, endpoints

  if true then
    test.skip("Skip upgrades test until it is reliable")
    return nil
  end

  -- Override the default download path
  consts.DEFAULT_DOWNLOAD_PATH = path.join('.', 'tmp')

  options = {
    datacenter = 'test',
    stateDirectory = './tests',
    tls = { rejectUnauthorized = false }
  }

  local endpoints = {}
  for _, address in pairs(fixtures.TESTING_AGENT_ENDPOINTS) do
    -- split ip:port
    table.insert(endpoints, Endpoint:new(address))
  end

  async.series({
    function(callback)
      child = helper.start_server(callback)
    end,
    function(callback)
{'fraction_non_alphanumeric': 0.1268283651175708, 'fraction_numerical': 0.0033327161636733937, 'mean_word_length': 3.6609145815358066, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3087273', 'n_tokens_mistral': 1676, 'n_tokens_neox': 1612, 'n_words': 373}