Sha256: af67b2f59f8291aa077df0f0f4fe0b35d85fbbc07c21a8b0f5f94998d244c97e

Contents?: true

Size: 1.95 KB

Versions: 26

Compression:

Stored size: 1.95 KB

Contents

require 'test_helper'

class TraceTest < Minitest::Test
  def test_trace_spans_count
    t = ::Instana::Trace.new(:test_trace, { :one => 1, :two => 2 })
    t.new_span(:sub_span, { :sub_four => 4 })
    t.end_span(:sub_five => 5)
    t.end_span(:three => 3)
    assert t.spans.size == 2
  end

  def test_trace_with_incoming_context
    incoming_context = { :trace_id => "1234", :span_id => "4321" }
    t = ::Instana::Trace.new(:test_trace, { :one => 1, :two => 2 }, incoming_context)
    first_span = t.spans.first
    assert_equal "1234", first_span[:t]
    assert_equal "4321", first_span[:p]
    assert t.spans.size == 1
  end

  def test_max_value_of_generated_id
    # Max is the maximum value for a Java signed long
    max_value = 9223372036854775807
    1000.times do
      assert ::Instana::Util.generate_id <= max_value
    end
  end

  def test_min_value_of_generated_id
    # Max is the maximum value for a Java signed long
    max_value = -9223372036854775808
    1000.times do
      assert ::Instana::Util.generate_id >= max_value
    end
  end

  def test_entry_span_doesnt_have_stack_by_default
    t = ::Instana::Trace.new(:rack)
    first_span = t.spans.first
    assert !first_span.key?(:stack)
  end

  def test_entry_span_has_stack_by_config
    ::Instana.config[:collect_backtraces] = true
    t = ::Instana::Trace.new(:rack)
    first_span = t.spans.first
    assert first_span.key?(:stack)
    assert_equal 2, first_span[:stack].count
    ::Instana.config[:collect_backtraces] = false
  end

  def test_exit_span_doesnt_have_stack_by_default
    t = ::Instana::Trace.new(:trace_test)
    t.new_span(:excon)
    second_span = t.spans.to_a[1]
    assert !second_span.key?(:stack)
  end

  def test_exit_span_has_stack_by_config
    ::Instana.config[:collect_backtraces] = true
    t = ::Instana::Trace.new(:trace_test)
    t.new_span(:excon)
    second_span = t.spans.to_a[1]
    assert second_span.key?(:stack)
    ::Instana.config[:collect_backtraces] = false
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
instana-1.9.7 test/tracing/trace_test.rb
instana-1.9.6 test/tracing/trace_test.rb
instana-1.9.5 test/tracing/trace_test.rb
instana-1.9.4 test/tracing/trace_test.rb
instana-1.9.3 test/tracing/trace_test.rb
instana-1.9.2 test/tracing/trace_test.rb
instana-1.9.1 test/tracing/trace_test.rb
instana-1.9.0 test/tracing/trace_test.rb
instana-1.9.0.daftrabbit test/tracing/trace_test.rb
instana-1.8.3 test/tracing/trace_test.rb
instana-1.9.0.sillyrabbit test/tracing/trace_test.rb
instana-1.8.2 test/tracing/trace_test.rb
instana-1.8.1 test/tracing/trace_test.rb
instana-1.8.0 test/tracing/trace_test.rb
instana-1.7.15 test/tracing/trace_test.rb
instana-1.7.14 test/tracing/trace_test.rb
instana-1.7.14a test/tracing/trace_test.rb
instana-1.7.13 test/tracing/trace_test.rb
instana-1.7.12 test/tracing/trace_test.rb
instana-1.7.11 test/tracing/trace_test.rb