|
94 | 94 | Sentry.configuration.sidekiq.report_after_job_retries = true
|
95 | 95 | end
|
96 | 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 |
| - |
| 97 | + def retry_last_failed_job |
104 | 98 | retry_set.first.add_to_queue
|
105 | 99 | job = queue.first
|
106 | 100 | work = Sidekiq::BasicFetch::UnitOfWork.new('queue:default', job.value)
|
107 | 101 | process_work(processor, work)
|
108 |
| - expect(transport.events.count).to eq(1) |
109 | 102 | end
|
110 | 103 |
|
111 |
| - it "doesn't affect no-retry jobs" do |
112 |
| - execute_worker(processor, SadWorker) |
| 104 | + context "when retry: is specified" do |
| 105 | + it "doesn't report the error until retries are exhuasted" do |
| 106 | + worker = Class.new(SadWorker) |
| 107 | + worker.sidekiq_options retry: 5 |
| 108 | + execute_worker(processor, worker) |
| 109 | + expect(transport.events.count).to eq(0) |
| 110 | + expect(retry_set.count).to eq(1) |
| 111 | + |
| 112 | + 4.times do |i| |
| 113 | + retry_last_failed_job |
| 114 | + expect(transport.events.count).to eq(0) |
| 115 | + end |
| 116 | + |
| 117 | + retry_last_failed_job |
| 118 | + expect(transport.events.count).to eq(1) |
| 119 | + end |
| 120 | + end |
113 | 121 |
|
114 |
| - expect(transport.events.count).to eq(1) |
115 |
| - expect(retry_set.count).to eq(1) |
| 122 | + context "when the job has 0 retries" do |
| 123 | + it "reports on the first failure" do |
| 124 | + worker = Class.new(SadWorker) |
| 125 | + worker.sidekiq_options retry: 0 |
| 126 | + |
| 127 | + execute_worker(processor, worker) |
| 128 | + |
| 129 | + expect(transport.events.count).to eq(1) |
| 130 | + end |
116 | 131 | end
|
117 | 132 |
|
118 |
| - it "doesn't affect jobs with zero retries" do |
119 |
| - execute_worker(processor, ZeroRetryWorker) |
| 133 | + context "when the job has retry: false" do |
| 134 | + it "reports on the first failure" do |
| 135 | + worker = Class.new(SadWorker) |
| 136 | + worker.sidekiq_options retry: false |
120 | 137 |
|
121 |
| - expect(transport.events.count).to eq(1) |
| 138 | + execute_worker(processor, worker) |
| 139 | + |
| 140 | + expect(transport.events.count).to eq(1) |
| 141 | + end |
| 142 | + end |
| 143 | + |
| 144 | + context "when retry is not specified on the worker" do |
| 145 | + before do |
| 146 | + # this is required for Sidekiq to assign default options to the worker |
| 147 | + SadWorker.sidekiq_options |
| 148 | + end |
| 149 | + |
| 150 | + it "reports on the 25th retry" do |
| 151 | + execute_worker(processor, SadWorker) |
| 152 | + expect(transport.events.count).to eq(0) |
| 153 | + expect(retry_set.count).to eq(1) |
| 154 | + |
| 155 | + 24.times do |i| |
| 156 | + retry_last_failed_job |
| 157 | + expect(transport.events.count).to eq(0) |
| 158 | + end |
| 159 | + |
| 160 | + retry_last_failed_job |
| 161 | + expect(transport.events.count).to eq(1) |
| 162 | + end |
| 163 | + |
| 164 | + context "when Sidekiq.options[:max_retries] is set" do |
| 165 | + it "respects the set limit" do |
| 166 | + Sidekiq.options[:max_retries] = 5 |
| 167 | + |
| 168 | + execute_worker(processor, SadWorker) |
| 169 | + expect(transport.events.count).to eq(0) |
| 170 | + expect(retry_set.count).to eq(1) |
| 171 | + |
| 172 | + 4.times do |i| |
| 173 | + retry_last_failed_job |
| 174 | + expect(transport.events.count).to eq(0) |
| 175 | + end |
| 176 | + |
| 177 | + retry_last_failed_job |
| 178 | + expect(transport.events.count).to eq(1) |
| 179 | + end |
| 180 | + end |
122 | 181 | end
|
123 | 182 | end
|
124 | 183 |
|
|
0 commit comments