File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1818
1919 it_behaves_like "a job in queue" , "default"
2020 it_behaves_like "a job that adheres to the auto_evaluation quota" , AutoEvaluation ::AnswerRelevancy
21+ it_behaves_like "a job that retries on service errors" , Aws ::Errors ::ServiceError do
22+ before do
23+ allow ( AutoEvaluation ::AnswerRelevancy )
24+ . to receive ( :call )
25+ . and_raise ( Aws ::Errors ::ServiceError . new ( nil , "error" ) )
26+ end
27+ end
2128
2229 describe "#perform" do
2330 it "calls AutoEvaluation::AnswerRelevancy the configured number of times with the correct arguments" do
119126 end
120127 end
121128
122- context "when the AnswerRelevancy metric raises an Aws::Errors::ServiceError" do
123- it "retries the job the max number of times" do
124- allow ( AutoEvaluation ::AnswerRelevancy )
125- . to receive ( :call )
126- . and_raise ( Aws ::Errors ::ServiceError . new ( nil , "error" ) )
127-
128- described_class . perform_later ( answer . id )
129-
130- assert_performed_jobs described_class ::MAX_RETRIES do
131- expect { perform_enqueued_jobs }
132- . to raise_error ( Aws ::Errors ::ServiceError )
133- end
134- end
135- end
136-
137129 context "when the answer is not eligible for auto-evaluation" do
138130 let ( :answer ) { create ( :answer , status : Answer . statuses . except ( :answered ) . keys . sample ) }
139131
Original file line number Diff line number Diff line change 2020
2121 it_behaves_like "a job in queue" , "default"
2222 it_behaves_like "a job that adheres to the auto_evaluation quota" , AutoEvaluation ::TopicTagger
23+ it_behaves_like "a job that retries on service errors" , Anthropic ::Errors ::APIError do
24+ before do
25+ allow ( AutoEvaluation ::TopicTagger )
26+ . to receive ( :call )
27+ . and_raise ( Anthropic ::Errors ::APIError . new ( url : "url" ) )
28+ end
29+ end
2330
2431 describe "#perform" do
2532 it "calls the AutoEvaluation::TopicTagger with the answer message" do
6976 end
7077 end
7178
72- context "when AutoEvaluation::TopicTagger raises an Anthropic::Errors::APIError" do
73- it "retries the job the max number of times" do
74- allow ( AutoEvaluation ::TopicTagger ) . to receive ( :call )
75- . and_raise ( Anthropic ::Errors ::APIError . new (
76- url : "url" ,
77- ) )
78-
79- ( described_class ::MAX_RETRIES - 1 ) . times do
80- described_class . perform_later ( answer . id )
81- expect { perform_enqueued_jobs } . not_to raise_error
82- end
83-
84- described_class . perform_later ( answer . id )
85- expect { perform_enqueued_jobs } . to raise_error ( Anthropic ::Errors ::APIError )
86- end
87- end
88-
8979 context "when the answer is not eligible for topic analysis" do
9080 let ( :answer ) { create ( :answer , status : Answer ::STATUSES_EXCLUDED_FROM_TOPIC_ANALYSIS . sample ) }
9181
Original file line number Diff line number Diff line change @@ -37,4 +37,16 @@ module JobExamples
3737 described_class . new . perform ( answer . id )
3838 end
3939 end
40+
41+ shared_examples "a job that retries on service errors" do |error_class |
42+ let ( :answer ) { create ( :answer ) }
43+ it "retries the job the max number of times on #{ error_class } " do
44+ described_class . perform_later ( answer . id )
45+
46+ assert_performed_jobs described_class ::MAX_RETRIES do
47+ expect { perform_enqueued_jobs }
48+ . to raise_error ( error_class )
49+ end
50+ end
51+ end
4052end
You can’t perform that action at this time.
0 commit comments