Skip to content

Commit 51ca559

Browse files
committed
[CLIENT] Use constant to define Elasticsearch hosts and avoid yellow status when number of nodes is 1
1 parent ad7c866 commit 51ca559

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

elasticsearch-transport/spec/elasticsearch/transport/client_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@
630630
end
631631

632632
let(:port) do
633-
(ENV['TEST_CLUSTER_PORT'] || 9250).to_i
633+
TEST_PORT
634634
end
635635

636636
let(:transport_options) do
@@ -652,7 +652,7 @@
652652
end
653653

654654
it 'connects to the cluster' do
655-
expect(response.body['number_of_nodes']).to be > (1)
655+
expect(response.body['number_of_nodes']).to be >= (1)
656656
end
657657
end
658658

@@ -781,7 +781,7 @@
781781
it 'reloads the connections' do
782782
expect(client.transport.connections.size).to eq(3)
783783
expect(responses.all? { true }).to be(true)
784-
expect(client.transport.connections.size).to eq(2)
784+
expect(client.transport.connections.size).to be >= (1)
785785
end
786786
end
787787

@@ -792,7 +792,7 @@
792792
end
793793

794794
let(:logger) do
795-
double('logger', :debug? => false, :warn? => true, :fatal? => false)
795+
double('logger', :debug? => false, :warn? => true, :fatal? => false, :error? => false)
796796
end
797797

798798
before do
@@ -814,7 +814,7 @@
814814
before do
815815
client.perform_request('DELETE', '_all')
816816
client.perform_request('DELETE', 'myindex') rescue
817-
client.perform_request('PUT', 'myindex', {}, { settings: { number_of_shards: 10 } })
817+
client.perform_request('PUT', 'myindex', {}, { settings: { number_of_shards: 2, number_of_replicas: 0 } })
818818
client.perform_request('PUT', 'myindex/mydoc/1', { routing: 'XYZ', timeout: '1s' }, { foo: 'bar' })
819819
client.perform_request('GET', '_cluster/health?wait_for_status=green', {})
820820
end

elasticsearch-transport/spec/spec_helper.rb

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,13 @@
88
# The hosts to use for creating a elasticsearch client.
99
#
1010
# @since 7.0.0
11-
ELASTICSEARCH_HOSTS = ENV['ELASTICSEARCH_HOSTS'] ? ENV['ELASTICSEARCH_HOSTS'].split(',').freeze : [ '127.0.0.1:9250' ].freeze
11+
ELASTICSEARCH_HOSTS = if hosts = ENV['TEST_ES_SERVER'] || ENV['ELASTICSEARCH_HOSTS']
12+
hosts.split(',').map do |host|
13+
/(http\:\/\/)?(\S+)/.match(host)[2]
14+
end
15+
end.freeze
16+
17+
TEST_HOST, TEST_PORT = ELASTICSEARCH_HOSTS.first.split(':') if ELASTICSEARCH_HOSTS
1218

1319
# Are we testing on JRuby?
1420
#

0 commit comments

Comments
 (0)