Sha256: 758232b733a9daed4787127794a4e67e3b07d601495732dc6e950e68fe6615fd

Contents?: true

Size: 1.75 KB

Versions: 25

Compression:

Stored size: 1.75 KB

Contents

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

require 'test_helper'

class ProcessInfoTest < Minitest::Test
  def test_osx_argument_stripping
    host_os = RbConfig::CONFIG['host_os']
    RbConfig::CONFIG['host_os'] = 'darwin'

    subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(cmdline: 'test INSTANA_TEST=1 KV=2'))
    assert_equal ['KV=2'], subject.arguments
  ensure
    RbConfig::CONFIG['host_os'] = host_os
  end

  def test_linux_argument_stripping
    host_os = RbConfig::CONFIG['host_os']
    RbConfig::CONFIG['host_os'] = 'linux'

    subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(cmdline: 'test INSTANA_TEST=1 KV=2'))
    assert_equal ['INSTANA_TEST=1', 'KV=2'], subject.arguments
  ensure
    RbConfig::CONFIG['host_os'] = host_os
  end

  def test_no_proc
    subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 0))

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

      assert_equal 0, subject.parent_pid
      assert_nil subject.cpuset
      assert_nil subject.sched_pid
      refute subject.in_container?
    end
  end

  def test_cpuset_proc
    subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 0))

    FakeFS do
      FakeFS::FileSystem.clone('test/support/proc', '/proc')
      assert_equal '/', subject.cpuset
      refute subject.in_container?
    end
  end

  def test_sched_pid
    subject = Instana::Backend::ProcessInfo.new(OpenStruct.new(pid: 1))

    FakeFS do
      FakeFS::FileSystem.clone('test/support/proc', '/proc')
      refute_equal '/', subject.cpuset

      assert subject.in_container?
      assert_equal 35, subject.sched_pid
      assert subject.from_parent_namespace
      assert_equal subject.sched_pid, subject.parent_pid
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
instana-1.205.0 test/backend/process_info_test.rb
instana-1.204.0 test/backend/process_info_test.rb
instana-1.204.0.pre3 test/backend/process_info_test.rb
instana-1.204.0.pre2 test/backend/process_info_test.rb
instana-1.204.0.pre1 test/backend/process_info_test.rb
instana-1.203.2 test/backend/process_info_test.rb
instana-1.203.1 test/backend/process_info_test.rb
instana-1.203.0 test/backend/process_info_test.rb
instana-1.202.0 test/backend/process_info_test.rb
instana-1.201.0 test/backend/process_info_test.rb
instana-1.201.0.pre1 test/backend/process_info_test.rb
instana-1.200.0 test/backend/process_info_test.rb
instana-1.200.0.pre1 test/backend/process_info_test.rb
instana-1.199.6 test/backend/process_info_test.rb
instana-1.199.5 test/backend/process_info_test.rb
instana-1.199.4 test/backend/process_info_test.rb
instana-1.199.3 test/backend/process_info_test.rb
instana-1.199.2 test/backend/process_info_test.rb
instana-1.199.1 test/backend/process_info_test.rb
instana-1.199.0 test/backend/process_info_test.rb