Skip to content

Commit 6c424d8

Browse files
committed
Test Sidekiq error handler for more scenarios
Make sure to test the two different error reporting scenarios: - a transaction is active for a job, and - no transaction is active for an internal Sidekiq error.
1 parent c76952f commit 6c424d8

File tree

1 file changed

+48
-17
lines changed

1 file changed

+48
-17
lines changed

spec/lib/appsignal/integrations/sidekiq_spec.rb

+48-17
Original file line numberDiff line numberDiff line change
@@ -21,23 +21,54 @@
2121
}
2222
end
2323

24-
it "tracks error on a new transaction" do
25-
described_class.new.call(exception, job_context)
26-
27-
transaction_hash = last_transaction.to_h
28-
expect(transaction_hash["error"]).to include(
29-
"name" => "ExampleStandardError",
30-
"message" => "uh oh",
31-
"backtrace" => kind_of(String)
32-
)
33-
expect(transaction_hash["sample_data"]).to include(
34-
"params" => {
35-
"jobstr" => "{ bad json }"
36-
}
37-
)
38-
expect(transaction_hash["metadata"]).to include(
39-
"sidekiq_error" => "Sidekiq internal error!"
40-
)
24+
context "when error is an internal error" do
25+
it "tracks error on a new transaction" do
26+
expect do
27+
described_class.new.call(exception, job_context)
28+
end.to(change { created_transactions.count }.by(1))
29+
30+
transaction_hash = last_transaction.to_h
31+
expect(transaction_hash).to include(
32+
"action" => "SidekiqInternal",
33+
"error" => hash_including(
34+
"name" => "ExampleStandardError",
35+
"message" => "uh oh",
36+
"backtrace" => kind_of(String)
37+
)
38+
)
39+
expect(transaction_hash["sample_data"]).to include(
40+
"params" => {
41+
"jobstr" => "{ bad json }"
42+
}
43+
)
44+
expect(transaction_hash["metadata"]).to include(
45+
"sidekiq_error" => "Sidekiq internal error!"
46+
)
47+
end
48+
end
49+
50+
context "when error is a job error" do
51+
let(:transaction) { http_request_transaction }
52+
before do
53+
transaction.set_action("existing transaction action")
54+
set_current_transaction(transaction)
55+
end
56+
57+
it "tracks error on the existing transaction" do
58+
expect do
59+
described_class.new.call(exception, job_context)
60+
end.to_not(change { created_transactions.count })
61+
62+
transaction_hash = last_transaction.to_h
63+
expect(transaction_hash).to include(
64+
"action" => "existing transaction action",
65+
"error" => hash_including(
66+
"name" => "ExampleStandardError",
67+
"message" => "uh oh",
68+
"backtrace" => kind_of(String)
69+
)
70+
)
71+
end
4172
end
4273
end
4374
end

0 commit comments

Comments
 (0)