Sha256: a3a254d1c7845ad18ddfa3f30064567ed1373d755332cc1dc88281b58b958420

Contents?: true

Size: 1.04 KB

Versions: 3

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

require 'test_helper'

class IntegrationTest < Minitest::Test
  def setup
    @server = UDPSocket.new
    @server.bind('localhost', 0)
    port = @server.addr[1]

    @old_backend = StatsD.backend
    StatsD.backend = StatsD::Instrument::Backends::UDPBackend.new("localhost:#{port}")
  end

  def teardown
    @server.close
    StatsD.backend = @old_backend
  end

  def test_live_local_udp_socket
    StatsD.increment('counter')
    assert_equal "counter:1|c", @server.recvfrom(100).first
  end

  def test_synchronize_in_exit_handler_handles_thread_error_and_exits_cleanly
    pid = fork do
      Signal.trap('TERM') do
        StatsD.increment('exiting')
        Process.exit!(0)
      end

      sleep 100
    end

    Process.kill('TERM', pid)
    _, exit_status = Process.waitpid2(pid)

    assert_equal 0, exit_status, "The forked process did not exit cleanly"
    assert_equal "exiting:1|c", @server.recvfrom_nonblock(100).first

  rescue NotImplementedError
    pass("Fork is not implemented on #{RUBY_PLATFORM}")
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
statsd-instrument-2.9.2 test/integration_test.rb
statsd-instrument-2.9.1 test/integration_test.rb
statsd-instrument-2.9.0 test/integration_test.rb