Skip to content

Commit c048dab

Browse files
committed
Add additional test case
1 parent df43976 commit c048dab

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

spec/typesense/api_call_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,28 @@
3939
end
4040

4141
shared_examples 'Node selection' do |method|
42+
it 'does not retry requests when nodes are healthy' do
43+
node_0_stub = stub_request(:any, described_class.new(typesense.configuration).send(:uri_for, '/', typesense.configuration.nodes[0]))
44+
.to_return(status: 422,
45+
body: JSON.dump('message' => 'Object unprocessable'),
46+
headers: { 'Content-Type' => 'application/json' })
47+
48+
node_1_stub = stub_request(:any, described_class.new(typesense.configuration).send(:uri_for, '/', typesense.configuration.nodes[1]))
49+
.to_return(status: 409,
50+
body: JSON.dump('message' => 'Object already exists'),
51+
headers: { 'Content-Type' => 'application/json' })
52+
53+
node_2_stub = stub_request(:any, described_class.new(typesense.configuration).send(:uri_for, '/', typesense.configuration.nodes[2]))
54+
.to_return(status: 500,
55+
body: JSON.dump('message' => 'Error Message'),
56+
headers: { 'Content-Type' => 'application/json' })
57+
58+
expect { subject.send(method, '/') }.to raise_error(Typesense::Error::ObjectUnprocessable)
59+
expect(node_0_stub).to have_been_requested
60+
expect(node_1_stub).not_to have_been_requested
61+
expect(node_2_stub).not_to have_been_requested
62+
end
63+
4264
it 'raises an error when no nodes are healthy' do
4365
node_0_stub = stub_request(:any, described_class.new(typesense.configuration).send(:uri_for, '/', typesense.configuration.nodes[0]))
4466
.to_return(status: 500,

0 commit comments

Comments
 (0)