Skip to content

Commit

Permalink
test: Add extra coverage for root exit span scenarios
Browse files Browse the repository at this point in the history
Signed-off-by: Ferenc Géczi <[email protected]>
  • Loading branch information
Ferenc- committed Jun 26, 2024
1 parent 654fc2c commit efe91b2
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
41 changes: 41 additions & 0 deletions test/instrumentation/graphql_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,10 @@ class Schema < GraphQL::Schema
mutation MutationType
end

def teardown
::Instana.config[:allow_exit_as_root] = false
end

def test_it_works
assert defined?(GraphQL)
end
Expand Down Expand Up @@ -127,6 +131,43 @@ def test_query
assert_equal expected_data, query_span[:data][:graphql]
end

def test_query_as_root_exit_span
clear_all!

query = "query FirstTwoTaskSamples {
tasks(after: \"\", first: 2) {
nodes {
action
}
}
}"

expected_data = {
:operationName => "FirstTwoTaskSamples",
:operationType => "query",
:arguments => { "tasks" => ["after", "first"] },
:fields => { "tasks" => ["nodes"], "nodes" => ["action"] }
}
expected_results = {
"data" => {
"tasks" => {
"nodes" => [{"action" => "Sample 00"}, {"action" => "Sample 01"}]
}
}
}

::Instana.config[:allow_exit_as_root] = true
results = Schema.execute(query)
::Instana.config[:allow_exit_as_root] = false
queued_spans = Instana.processor.queued_spans
assert_equal 1, queued_spans.length
query_span = queued_spans[0]

assert_equal expected_results, results.to_h
assert_equal :'graphql.server', query_span[:n]
assert_equal expected_data, query_span[:data][:graphql]
end

def test_query_with_fragment
clear_all!

Expand Down
18 changes: 18 additions & 0 deletions test/instrumentation/rails_action_mailer_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ def setup
clear_all!
end

def teardown
::Instana.config[:allow_exit_as_root] = false
end

def test_mailer
Instana.tracer.start_or_continue_trace(:test) do
TestMailer.sample_email.deliver_now
Expand All @@ -45,4 +49,18 @@ def test_mailer
assert_equal 'RailsActionMailerTest::TestMailer', mail_span[:data][:actionmailer][:class]
assert_equal 'sample_email', mail_span[:data][:actionmailer][:method]
end

def test_mailer_as_root_exit_span
::Instana.config[:allow_exit_as_root] = true
TestMailer.sample_email.deliver_now
::Instana.config[:allow_exit_as_root] = false

queued_spans = Instana.processor.queued_spans
assert_equal 1, queued_spans.length
mail_span = queued_spans[0]

assert_equal :"mail.actionmailer", mail_span[:n]
assert_equal 'RailsActionMailerTest::TestMailer', mail_span[:data][:actionmailer][:class]
assert_equal 'sample_email', mail_span[:data][:actionmailer][:method]
end
end

0 comments on commit efe91b2

Please sign in to comment.