|
73 | 73 | it_behaves_like 'a redacted string'
|
74 | 74 | end
|
75 | 75 | end
|
| 76 | + |
| 77 | + context 'when reload_on_failure is true and and hosts are unreachable' do |
| 78 | + |
| 79 | + let(:client) do |
| 80 | + Elasticsearch::Transport::Client.new(arguments) |
| 81 | + end |
| 82 | + |
| 83 | + let(:arguments) do |
| 84 | + { |
| 85 | + hosts: ['http://unavabilable:9200', 'http://unavabilable:9201'], |
| 86 | + reload_on_failure: true, |
| 87 | + sniffer_timeout: 5 |
| 88 | + } |
| 89 | + end |
| 90 | + |
| 91 | + it 'raises an exception' do |
| 92 | + expect { |
| 93 | + client.info |
| 94 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 95 | + end |
| 96 | + end |
| 97 | + |
| 98 | + context 'when the client has `retry_on_failure` set to an integer' do |
| 99 | + |
| 100 | + let(:client) do |
| 101 | + Elasticsearch::Transport::Client.new(arguments) |
| 102 | + end |
| 103 | + |
| 104 | + let(:arguments) do |
| 105 | + { |
| 106 | + hosts: ['http://unavabilable:9200', 'http://unavabilable:9201'], |
| 107 | + retry_on_failure: 2 |
| 108 | + } |
| 109 | + end |
| 110 | + |
| 111 | + context 'when `perform_request` is called without a `retry_on_failure` option value' do |
| 112 | + |
| 113 | + before do |
| 114 | + expect(client.transport).to receive(:get_connection).exactly(3).times.and_call_original |
| 115 | + end |
| 116 | + |
| 117 | + it 'uses the client `retry_on_failure` value' do |
| 118 | + expect { |
| 119 | + client.transport.perform_request('GET', '/info') |
| 120 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 121 | + end |
| 122 | + end |
| 123 | + |
| 124 | + context 'when `perform_request` is called with a `retry_on_failure` option value' do |
| 125 | + |
| 126 | + before do |
| 127 | + expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original |
| 128 | + end |
| 129 | + |
| 130 | + it 'uses the option `retry_on_failure` value' do |
| 131 | + expect { |
| 132 | + client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5) |
| 133 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 134 | + end |
| 135 | + end |
| 136 | + end |
| 137 | + |
| 138 | + context 'when the client has `retry_on_failure` set to true' do |
| 139 | + |
| 140 | + let(:client) do |
| 141 | + Elasticsearch::Transport::Client.new(arguments) |
| 142 | + end |
| 143 | + |
| 144 | + let(:arguments) do |
| 145 | + { |
| 146 | + hosts: ['http://unavabilable:9200', 'http://unavabilable:9201'], |
| 147 | + retry_on_failure: true |
| 148 | + } |
| 149 | + end |
| 150 | + |
| 151 | + context 'when `perform_request` is called without a `retry_on_failure` option value' do |
| 152 | + |
| 153 | + before do |
| 154 | + expect(client.transport).to receive(:get_connection).exactly(4).times.and_call_original |
| 155 | + end |
| 156 | + |
| 157 | + it 'uses the default `MAX_RETRIES` value' do |
| 158 | + expect { |
| 159 | + client.transport.perform_request('GET', '/info') |
| 160 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 161 | + end |
| 162 | + end |
| 163 | + |
| 164 | + context 'when `perform_request` is called with a `retry_on_failure` option value' do |
| 165 | + |
| 166 | + before do |
| 167 | + expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original |
| 168 | + end |
| 169 | + |
| 170 | + it 'uses the option `retry_on_failure` value' do |
| 171 | + expect { |
| 172 | + client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5) |
| 173 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 174 | + end |
| 175 | + end |
| 176 | + end |
| 177 | + |
| 178 | + context 'when the client has `retry_on_failure` set to false' do |
| 179 | + |
| 180 | + let(:client) do |
| 181 | + Elasticsearch::Transport::Client.new(arguments) |
| 182 | + end |
| 183 | + |
| 184 | + let(:arguments) do |
| 185 | + { |
| 186 | + hosts: ['http://unavabilable:9200', 'http://unavabilable:9201'], |
| 187 | + retry_on_failure: false |
| 188 | + } |
| 189 | + end |
| 190 | + |
| 191 | + context 'when `perform_request` is called without a `retry_on_failure` option value' do |
| 192 | + |
| 193 | + before do |
| 194 | + expect(client.transport).to receive(:get_connection).once.and_call_original |
| 195 | + end |
| 196 | + |
| 197 | + it 'does not retry' do |
| 198 | + expect { |
| 199 | + client.transport.perform_request('GET', '/info') |
| 200 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 201 | + end |
| 202 | + end |
| 203 | + |
| 204 | + context 'when `perform_request` is called with a `retry_on_failure` option value' do |
| 205 | + |
| 206 | + before do |
| 207 | + expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original |
| 208 | + end |
| 209 | + |
| 210 | + it 'uses the option `retry_on_failure` value' do |
| 211 | + expect { |
| 212 | + client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5) |
| 213 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 214 | + end |
| 215 | + end |
| 216 | + end |
| 217 | + |
| 218 | + context 'when the client has no `retry_on_failure` set' do |
| 219 | + |
| 220 | + let(:client) do |
| 221 | + Elasticsearch::Transport::Client.new(arguments) |
| 222 | + end |
| 223 | + |
| 224 | + let(:arguments) do |
| 225 | + { |
| 226 | + hosts: ['http://unavabilable:9200', 'http://unavabilable:9201'], |
| 227 | + } |
| 228 | + end |
| 229 | + |
| 230 | + context 'when `perform_request` is called without a `retry_on_failure` option value' do |
| 231 | + |
| 232 | + before do |
| 233 | + expect(client.transport).to receive(:get_connection).exactly(1).times.and_call_original |
| 234 | + end |
| 235 | + |
| 236 | + it 'does not retry' do |
| 237 | + expect { |
| 238 | + client.transport.perform_request('GET', '/info') |
| 239 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 240 | + end |
| 241 | + end |
| 242 | + |
| 243 | + context 'when `perform_request` is called with a `retry_on_failure` option value' do |
| 244 | + |
| 245 | + before do |
| 246 | + expect(client.transport).to receive(:get_connection).exactly(6).times.and_call_original |
| 247 | + end |
| 248 | + |
| 249 | + it 'uses the option `retry_on_failure` value' do |
| 250 | + expect { |
| 251 | + client.transport.perform_request('GET', '/info', {}, nil, nil, retry_on_failure: 5) |
| 252 | + }.to raise_exception(Faraday::ConnectionFailed) |
| 253 | + end |
| 254 | + end |
| 255 | + end |
76 | 256 | end
|
0 commit comments