|
6 | 6 | perform_basic_setup |
7 | 7 | end |
8 | 8 |
|
| 9 | + let(:queue) do |
| 10 | + Sidekiq::Queue.new("default") |
| 11 | + end |
| 12 | + |
| 13 | + let(:retry_set) do |
| 14 | + Sidekiq::RetrySet.new |
| 15 | + end |
| 16 | + |
| 17 | + before do |
| 18 | + retry_set.clear |
| 19 | + queue.clear |
| 20 | + end |
| 21 | + |
9 | 22 | after do |
10 | 23 | # those test jobs will go into the real Redis and be visiable to other sidekiq processes |
11 | 24 | # this can affect local testing and development, so we should clear them after each test |
12 | | - Sidekiq::RetrySet.new.clear |
| 25 | + retry_set.clear |
| 26 | + queue.clear |
13 | 27 | end |
14 | 28 |
|
15 | 29 | let(:processor) do |
|
28 | 42 | end |
29 | 43 |
|
30 | 44 | it "captues exception raised in the worker" do |
31 | | - expect { process_job(processor, "SadWorker") }.to change { transport.events.size }.by(1) |
| 45 | + expect { execute_worker(processor, SadWorker) }.to change { transport.events.size }.by(1) |
32 | 46 |
|
33 | 47 | event = transport.events.last.to_hash |
34 | 48 | expect(event[:sdk]).to eq({ name: "sentry.ruby.sidekiq", version: described_class::VERSION }) |
|
37 | 51 |
|
38 | 52 | describe "context cleanup" do |
39 | 53 | it "cleans up context from processed jobs" do |
40 | | - process_job(processor, "HappyWorker") |
41 | | - process_job(processor, "SadWorker") |
| 54 | + execute_worker(processor, HappyWorker) |
| 55 | + execute_worker(processor, SadWorker) |
42 | 56 |
|
43 | 57 | expect(transport.events.count).to eq(1) |
44 | 58 | event = transport.events.last.to_json_compatible |
|
49 | 63 | end |
50 | 64 |
|
51 | 65 | it "cleans up context from failed jobs" do |
52 | | - process_job(processor, "SadWorker") |
53 | | - process_job(processor, "VerySadWorker") |
| 66 | + execute_worker(processor, SadWorker) |
| 67 | + execute_worker(processor, VerySadWorker) |
54 | 68 |
|
55 | 69 | expect(transport.events.count).to eq(2) |
56 | 70 | event = transport.events.last.to_json_compatible |
|
61 | 75 | end |
62 | 76 |
|
63 | 77 | it "has some context when capturing, even if no exception raised" do |
64 | | - process_job(processor, "ReportingWorker") |
| 78 | + execute_worker(processor, ReportingWorker) |
65 | 79 |
|
66 | 80 | event = transport.events.last.to_json_compatible |
67 | 81 |
|
68 | 82 | expect(event["message"]).to eq "I have something to say!" |
69 | | - expect(event["contexts"]["sidekiq"]).to eq("class" => "ReportingWorker", "jid" => "123123", "queue" => "default") |
| 83 | + expect(event["contexts"]["sidekiq"]).to eq("args" => [], "class" => "ReportingWorker", "jid" => "123123", "queue" => "default") |
70 | 84 | end |
71 | 85 |
|
72 | 86 | it "adds the failed job to the retry queue" do |
73 | | - process_job(processor, "SadWorker") |
| 87 | + execute_worker(processor, SadWorker) |
| 88 | + |
| 89 | + expect(retry_set.count).to eq(1) |
| 90 | + end |
74 | 91 |
|
75 | | - retries = Sidekiq::RetrySet.new |
76 | | - expect(retries.count).to eq(1) |
| 92 | + context "with config.report_after_job_retries = true" do |
| 93 | + before do |
| 94 | + Sentry.configuration.sidekiq.report_after_job_retries = true |
| 95 | + end |
| 96 | + |
| 97 | + it "doesn't report the error until retries are exhuasted" do |
| 98 | + execute_worker(processor, RetryWorker) |
| 99 | + |
| 100 | + expect(transport.events.count).to eq(0) |
| 101 | + |
| 102 | + expect(retry_set.count).to eq(1) |
| 103 | + |
| 104 | + retry_set.first.add_to_queue |
| 105 | + job = queue.first |
| 106 | + work = Sidekiq::BasicFetch::UnitOfWork.new('queue:default', job.value) |
| 107 | + process_work(processor, work) |
| 108 | + expect(transport.events.count).to eq(1) |
| 109 | + end |
| 110 | + |
| 111 | + it "doesn't affect no-retry jobs" do |
| 112 | + execute_worker(processor, SadWorker) |
| 113 | + |
| 114 | + expect(transport.events.count).to eq(1) |
| 115 | + expect(retry_set.count).to eq(1) |
| 116 | + end |
77 | 117 | end |
78 | 118 |
|
79 | 119 | context "when tracing is enabled" do |
|
84 | 124 | end |
85 | 125 |
|
86 | 126 | it "records transaction" do |
87 | | - process_job(processor, "HappyWorker") |
| 127 | + execute_worker(processor, HappyWorker) |
88 | 128 |
|
89 | 129 | expect(transport.events.count).to eq(1) |
90 | 130 | transaction = transport.events.first |
|
96 | 136 | end |
97 | 137 |
|
98 | 138 | it "records transaction with exception" do |
99 | | - process_job(processor, "SadWorker") |
| 139 | + execute_worker(processor, SadWorker) |
100 | 140 |
|
101 | 141 | expect(transport.events.count).to eq(2) |
102 | 142 | transaction = transport.events.first |
|
0 commit comments