Skip to content

Commit 5d16eac

Browse files
committed
test: add shared examples for error capturing and retry semantics in ActiveJob
1 parent 291aa2c commit 5d16eac

3 files changed

Lines changed: 50 additions & 20 deletions

File tree

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.shared_examples "an ActiveJob backend that captures errors" do
4+
let(:failing_job) do
5+
job_fixture do
6+
def perform
7+
raise "boom from failing_job spec"
8+
end
9+
end
10+
end
11+
12+
it "captures an error event when a job fails" do
13+
expect do
14+
failing_job.perform_later
15+
drain
16+
end.to raise_error(RuntimeError, /boom from failing_job spec/)
17+
18+
expect(sentry_events.size).to eq(1)
19+
20+
exception = extract_sentry_exceptions(sentry_events.last).first
21+
expect(exception.value).to match(/boom from failing_job spec/)
22+
end
23+
end
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# frozen_string_literal: true
2+
3+
RSpec.shared_examples "an ActiveJob backend that respects retry semantics" do
4+
let(:retryable_job) do
5+
job_fixture do
6+
retry_on StandardError, attempts: 3, wait: 0
7+
8+
def perform
9+
raise "boom from retryable_job spec"
10+
end
11+
end
12+
end
13+
14+
it "captures one error event after retries are exhausted" do
15+
expect do
16+
retryable_job.perform_later
17+
3.times { drain }
18+
end.to raise_error(RuntimeError, /boom from retryable_job spec/)
19+
20+
expect(sentry_events.size).to eq(1)
21+
22+
exception = extract_sentry_exceptions(sentry_events.last).first
23+
expect(exception.value).to match(/boom from retryable_job spec/)
24+
end
25+
end
Lines changed: 2 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,6 @@
11
# frozen_string_literal: true
22

33
RSpec.shared_examples "a Sentry-instrumented ActiveJob backend" do
4-
let(:failing_job) do
5-
job_fixture do
6-
def perform
7-
raise "boom from failing_job spec"
8-
end
9-
end
10-
end
11-
12-
it "captures an error event when a job fails" do
13-
expect do
14-
failing_job.perform_later
15-
drain
16-
end.to raise_error(RuntimeError, /boom from failing_job spec/)
17-
18-
event = last_sentry_event
19-
expect(event).not_to be_nil
20-
21-
exception = extract_sentry_exceptions(event).first
22-
expect(exception.value).to match(/boom from failing_job spec/)
23-
end
4+
it_behaves_like "an ActiveJob backend that captures errors"
5+
it_behaves_like "an ActiveJob backend that respects retry semantics"
246
end

0 commit comments

Comments
 (0)