Sha256: 41832ed2fd1473fc91a218ca52500282e96ee5bf7017aa2e7cee5cd49b91b306

Contents?: true

Size: 1.04 KB

Versions: 6

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 foked 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

6 entries across 6 versions & 1 rubygems

Version Path
statsd-instrument-2.8.0 test/integration_test.rb
statsd-instrument-2.7.1 test/integration_test.rb
statsd-instrument-2.7.0 test/integration_test.rb
statsd-instrument-2.6.0 test/integration_test.rb
statsd-instrument-2.5.1 test/integration_test.rb
statsd-instrument-2.5.0 test/integration_test.rb