test/instrumentation/sidekiq-client_test.rb in instana-1.214.4 vs test/instrumentation/sidekiq-client_test.rb in instana-1.215.0

- old
+ new

@@ -7,10 +7,14 @@ class SidekiqClientTest < Minitest::Test def setup ::Sidekiq::Queue.new('some_random_queue').clear end + def teardown + ::Instana.config[:allow_exit_as_root] = false + end + def test_config_defaults assert ::Instana.config[:'sidekiq-client'].is_a?(Hash) assert ::Instana.config[:'sidekiq-client'].key?(:enabled) assert_equal true, ::Instana.config[:'sidekiq-client'][:enabled] end @@ -33,10 +37,40 @@ assert_job_enqueued(job) assert_normal_trace_recorded(job) end + def test_enqueue_as_root_exit_span + clear_all! + ::Instana.config[:allow_exit_as_root] = true + disable_redis_instrumentation + ::Sidekiq::Client.push( + 'queue' => 'some_random_queue', + 'class' => ::SidekiqJobOne, + 'args' => [1, 2, 3], + 'retry' => false + ) + ::Instana.config[:allow_exit_as_root] = false + enable_redis_instrumentation + + queue = ::Sidekiq::Queue.new('some_random_queue') + job = queue.first + + assert_job_enqueued(job) + spans = ::Instana.processor.queued_spans + assert_equal 1, spans.length + + first_span = spans[0] + + assert_equal :'sidekiq-client', first_span[:n] + assert_equal 'some_random_queue', first_span[:data][:'sidekiq-client'][:queue] + assert_equal 'SidekiqJobOne', first_span[:data][:'sidekiq-client'][:job] + assert_equal "false", first_span[:data][:'sidekiq-client'][:retry] + assert first_span[:data][:'sidekiq-client'][:'redis-url'] + assert_equal job['jid'], first_span[:data][:'sidekiq-client'][:job_id] + end + def test_enqueue_failure clear_all! Instana.tracer.start_or_continue_trace(:sidekiqtests) do disable_redis_instrumentation @@ -66,12 +100,12 @@ assert_equal 'some_random_queue', job_message['queue'] assert_equal 'SidekiqJobOne', job_message['class'] assert_equal [1, 2, 3], job_message['args'] assert_equal false, job_message['retry'] - assert_equal false, job_message['X-Instana-T'].nil? - assert_equal false, job_message['X-Instana-S'].nil? + refute_nil job_message['X-Instana-T'] + refute_nil job_message['X-Instana-S'] end def assert_normal_trace_recorded(job) spans = ::Instana.processor.queued_spans assert_equal 2, spans.length @@ -100,10 +134,10 @@ assert_equal first_span[:s], second_span[:p] validate_sdk_span(first_span, {:name => :sidekiqtests, :type => :entry}) assert_equal :'sidekiq-client', second_span[:n] assert_equal true, second_span[:error] - assert_equal false, second_span[:stack].nil? + refute_nil second_span[:stack] assert_equal 'some_random_queue', second_span[:data][:'sidekiq-client'][:queue] assert_equal 'SidekiqJobTwo', second_span[:data][:'sidekiq-client'][:job] assert_equal "false", second_span[:data][:'sidekiq-client'][:retry] assert second_span[:data][:'sidekiq-client'][:'redis-url']