File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1919
2020 it_behaves_like "a job in queue" , "default"
2121 it_behaves_like "a job that adheres to the metric quota" , AutoEvaluation ::AnswerRelevancy
22+ it_behaves_like "a job that retries on service errors" , Aws ::Errors ::ServiceError do
23+ before do
24+ allow ( AutoEvaluation ::AnswerRelevancy )
25+ . to receive ( :call )
26+ . and_raise ( Aws ::Errors ::ServiceError . new ( nil , "error" ) )
27+ end
28+ end
2229
2330 describe "#perform" do
2431 it "calls AutoEvaluation::AnswerRelevancy the configured number of times with the correct arguments" do
126133 end
127134 end
128135
129- context "when the AnswerRelevancy metric raises an Aws::Errors::ServiceError" do
130- it "retries the job the max number of times" do
131- allow ( AutoEvaluation ::AnswerRelevancy )
132- . to receive ( :call )
133- . and_raise ( Aws ::Errors ::ServiceError . new ( nil , "error" ) )
134-
135- described_class . perform_later ( answer . id )
136-
137- assert_performed_jobs described_class ::MAX_RETRIES do
138- expect { perform_enqueued_jobs }
139- . to raise_error ( Aws ::Errors ::ServiceError )
140- end
141- end
142- end
143-
144136 context "when the answer is not eligible for auto-evaluation" do
145137 let ( :answer ) { create ( :answer , status : Answer . statuses . except ( :answered ) . keys . sample ) }
146138
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 metric 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
Original file line number Diff line number Diff line change @@ -35,4 +35,16 @@ module JobExamples
3535 described_class . new . perform ( answer . id )
3636 end
3737 end
38+
39+ shared_examples "a job that retries on service errors" do |error_class |
40+ let ( :answer ) { create ( :answer ) }
41+ it "retries the job the max number of times on #{ error_class } " do
42+ described_class . perform_later ( answer . id )
43+
44+ assert_performed_jobs described_class ::MAX_RETRIES do
45+ expect { perform_enqueued_jobs }
46+ . to raise_error ( error_class )
47+ end
48+ end
49+ end
3850end
You can’t perform that action at this time.
0 commit comments