|
29 | 29 | end |
30 | 30 | end |
31 | 31 | end |
| 32 | + |
| 33 | + describe '#num_retries default' do |
| 34 | + let(:base_options) do |
| 35 | + { |
| 36 | + api_key: 'abcd', |
| 37 | + nodes: [ |
| 38 | + { host: 'node0', port: 8108, protocol: 'http' }, |
| 39 | + { host: 'node1', port: 8108, protocol: 'http' }, |
| 40 | + { host: 'node2', port: 8108, protocol: 'http' } |
| 41 | + ], |
| 42 | + log_level: Logger::ERROR |
| 43 | + } |
| 44 | + end |
| 45 | + |
| 46 | + it 'defaults to the number of nodes when no nearest_node is set' do |
| 47 | + config = described_class.new(base_options) |
| 48 | + expect(config.num_retries).to eq(3) |
| 49 | + end |
| 50 | + |
| 51 | + it 'defaults to nodes.length + 1 when a nearest_node is set' do |
| 52 | + config = described_class.new( |
| 53 | + base_options.merge(nearest_node: { host: 'nearestNode', port: 6108, protocol: 'http' }) |
| 54 | + ) |
| 55 | + expect(config.num_retries).to eq(4) |
| 56 | + end |
| 57 | + |
| 58 | + it 'reflects node count for single-node setups' do |
| 59 | + config = described_class.new( |
| 60 | + base_options.merge(nodes: [{ host: 'node0', port: 8108, protocol: 'http' }]) |
| 61 | + ) |
| 62 | + expect(config.num_retries).to eq(1) |
| 63 | + end |
| 64 | + |
| 65 | + it 'honors an explicit num_retries option' do |
| 66 | + config = described_class.new(base_options.merge(num_retries: 7)) |
| 67 | + expect(config.num_retries).to eq(7) |
| 68 | + end |
| 69 | + |
| 70 | + it 'honors an explicit num_retries of 0 (Integer is truthy in Ruby)' do |
| 71 | + config = described_class.new(base_options.merge(num_retries: 0)) |
| 72 | + expect(config.num_retries).to eq(0) |
| 73 | + end |
| 74 | + end |
32 | 75 | end |
0 commit comments