|
39 | 39 | end |
40 | 40 |
|
41 | 41 | 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 | + |
42 | 64 | it 'raises an error when no nodes are healthy' do |
43 | 65 | node_0_stub = stub_request(:any, described_class.new(typesense.configuration).send(:uri_for, '/', typesense.configuration.nodes[0])) |
44 | 66 | .to_return(status: 500, |
|
0 commit comments