Sha256: d2f261c979f40e0e6367fefb5ba54ea1059b89642e9d4af049611d591539c7c1

Contents?: true

Size: 1.61 KB

Versions: 25

Compression:

Stored size: 1.61 KB

Contents

# (c) Copyright IBM Corp. 2021
# (c) Copyright Instana Inc. 2021

require 'test_helper'

class HostAgentTest < Minitest::Test
  def test_spawn_background_thread
    ENV['INSTANA_TEST'] = nil
    ::Instana.config[:agent_host] = '10.10.10.10'

    if File.exist?('/sbin/ip')
      addr = `/sbin/ip route | awk '/default/ { print $3 }'`.strip
      stub_request(:get, "http://#{addr}:42699/")
        .to_timeout
    end

    stub_request(:get, "http://10.10.10.10:42699/")
      .to_timeout.times(3).then
      .to_return(status: 200, body: "", headers: {})

    discovery = Minitest::Mock.new
    discovery.expect(:delete_observers, discovery, [])
    discovery.expect(:with_observer, discovery, [Instana::Backend::HostAgentActivationObserver])
    discovery.expect(:with_observer, discovery, [Instana::Backend::HostAgentReportingObserver])
    discovery.expect(:swap, discovery, [])

    subject = Instana::Backend::HostAgent.new(discovery: discovery)

    FakeFS.with_fresh do
      FakeFS::FileSystem.clone('test/support/ecs', '/proc')
      subject.spawn_background_thread
    end

    subject.future.value!

    discovery.verify
  ensure
    ::Instana.config[:agent_host] = '127.0.0.1'
    ENV['INSTANA_TEST'] = 'true'
  end

  def test_discovery_value
    discovery = Concurrent::Atom.new({'pid' => 1})
    subject = Instana::Backend::HostAgent.new(discovery: discovery)
    assert_equal 1, subject.source[:e]
  end

  def test_start
    subject = Instana::Backend::HostAgent.new
    assert subject.respond_to? :start
  end

  def test_after_fork
    subject = Instana::Backend::HostAgent.new
    assert subject.respond_to? :after_fork
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
instana-1.209.2 test/backend/host_agent_test.rb
instana-1.209.1 test/backend/host_agent_test.rb
instana-1.209.0.pre3 test/backend/host_agent_test.rb
instana-1.209.0.pre2 test/backend/host_agent_test.rb
instana-1.209.0.pre1 test/backend/host_agent_test.rb
instana-1.208.0 test/backend/host_agent_test.rb
instana-1.207.0 test/backend/host_agent_test.rb
instana-1.206.0 test/backend/host_agent_test.rb
instana-1.205.0 test/backend/host_agent_test.rb
instana-1.204.0 test/backend/host_agent_test.rb
instana-1.204.0.pre3 test/backend/host_agent_test.rb
instana-1.204.0.pre2 test/backend/host_agent_test.rb
instana-1.204.0.pre1 test/backend/host_agent_test.rb
instana-1.203.2 test/backend/host_agent_test.rb
instana-1.203.1 test/backend/host_agent_test.rb
instana-1.203.0 test/backend/host_agent_test.rb
instana-1.202.0 test/backend/host_agent_test.rb
instana-1.201.0 test/backend/host_agent_test.rb
instana-1.201.0.pre1 test/backend/host_agent_test.rb
instana-1.200.0 test/backend/host_agent_test.rb