Skip to content

Commit 8578bee

Browse files
committed
fixup! fixup! Add tests for endpoint option
1 parent 3e2adf0 commit 8578bee

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

spec/acceptance/realtime/connection_failures_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,7 @@ def send_disconnect_message
930930
original_method.call(*args, &block)
931931
end
932932
connection.once(:connected) do
933-
host = "#{"#{environment}-" if environment && environment.to_s != 'production'}#{Ably::Realtime::Client::DOMAIN}"
933+
host = "#{environment}.realtime.ably.net"
934934
expect(hosts.first).to eql(host)
935935
expect(hosts.length).to eql(1)
936936
stop_reactor
@@ -1469,13 +1469,13 @@ def kill_connection_transport_and_prevent_valid_resume
14691469
end
14701470

14711471
context 'with non-production environment' do
1472-
let(:environment) { 'sandbox' }
1473-
let(:expected_host) { "#{environment}-#{Ably::Realtime::Client::DOMAIN}" }
1472+
let(:environment) { 'nonprod:sandbox' }
1473+
let(:expected_host) { "sandbox.realtime.ably-nonprod.net" }
14741474
let(:client_options) { timeout_options.merge(environment: environment) }
14751475

14761476
context ':fallback_hosts_use_default is unset' do
14771477
let(:max_time_in_state_for_tests) { 8 }
1478-
let(:expected_hosts) { Ably::CUSTOM_ENVIRONMENT_FALLBACKS_SUFFIXES.map { |suffix| "#{environment}#{suffix}" } + [expected_host] }
1478+
let(:expected_hosts) { Ably::CUSTOM_ENVIRONMENT_FALLBACKS_SUFFIXES.map { |suffix| "#{environment}.#{suffix}" } + [expected_host] }
14791479
let(:fallback_hosts_used) { Array.new }
14801480

14811481
it 'uses fallback hosts by default' do
@@ -1568,7 +1568,7 @@ def kill_connection_transport_and_prevent_valid_resume
15681568
stub_const 'Ably::FALLBACK_HOSTS', custom_hosts
15691569
end
15701570

1571-
let(:expected_host) { Ably::Realtime::Client::DOMAIN }
1571+
let(:expected_host) { 'main.realtime.ably.net' }
15721572
let(:client_options) { timeout_options.merge(environment: nil) }
15731573

15741574
let(:fallback_hosts_used) { Array.new }

spec/acceptance/rest/client_spec.rb

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ def encode64(text)
139139
let(:client_options) { default_options.merge(key: api_key, client_id: client_id) }
140140

141141
let!(:get_message_history_stub) do
142-
stub_request(:get, "https://#{environment}-#{Ably::Rest::Client::DOMAIN}/channels/#{channel_name}/messages?#{history_querystring}")
142+
stub_request(:get, "https://#{client.hostname}/channels/#{channel_name}/messages?#{history_querystring}")
143143
.with(headers: { 'X-Ably-ClientId' => encode64(client_id) })
144144
.to_return(body: [], headers: { 'Content-Type' => 'application/json' })
145145
end
@@ -155,7 +155,7 @@ def encode64(text)
155155
let(:client_options) { default_options.merge(token: token_string) }
156156

157157
let!(:get_message_history_stub) do
158-
stub_request(:get, "#{http_protocol}://#{environment}-#{Ably::Rest::Client::DOMAIN}/channels/#{channel_name}/messages?#{history_querystring}").
158+
stub_request(:get, "#{http_protocol}://#{client.hostname}/channels/#{channel_name}/messages?#{history_querystring}").
159159
with(headers: { 'Authorization' => "Bearer #{encode64(token_string)}" }).
160160
to_return(body: [], headers: { 'Content-Type' => 'application/json' })
161161
end
@@ -312,9 +312,9 @@ def encode64(text)
312312

313313
context 'when environment is NOT production (#RSC15b)' do
314314
context 'and custom fallback hosts are empty' do
315-
let(:client_options) { default_options.merge(environment: 'sandbox', key: api_key, fallback_hosts: []) }
315+
let(:client_options) { default_options.merge(environment: 'nonprod:sandbox', key: api_key, fallback_hosts: []) }
316316
let!(:default_host_request_stub) do
317-
stub_request(:post, "https://#{environment}-#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
317+
stub_request(:post, "https://#{client.hostname}#{path}").to_return do
318318
raise Faraday::TimeoutError.new('timeout error message')
319319
end
320320
end
@@ -325,7 +325,7 @@ def encode64(text)
325325
end
326326

327327
context 'and no custom fallback hosts are provided' do
328-
let(:client_options) { default_options.merge(environment: 'sandbox', key: api_key) }
328+
let(:client_options) { default_options.merge(environment: 'nonprod:sandbox', key: api_key) }
329329

330330
it 'should make connection attempts to sandbox.a.fallback.ably-realtime.com, sandbox.b.fallback.ably-realtime.com, sandbox.c.fallback.ably-realtime.com, sandbox.d.fallback.ably-realtime.com, sandbox.e.fallback.ably-realtime.com (#RSC15a)' do
331331
hosts = []
@@ -338,7 +338,7 @@ def encode64(text)
338338
end
339339

340340
context 'when environment is production' do
341-
let(:custom_hosts) { %w(a.ably-realtime.com b.ably-realtime.com) }
341+
let(:custom_hosts) { %w(main.a.fallback.ably-realtime.com main.b.fallback.ably-realtime.com) }
342342
let(:max_retry_count) { 2 }
343343
let(:max_retry_duration) { 0.5 }
344344
let(:fallback_block) { proc { raise Faraday::SSLError.new('ssl error message') } }
@@ -366,7 +366,7 @@ def encode64(text)
366366

367367
context 'and connection times out' do
368368
let!(:default_host_request_stub) do
369-
stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
369+
stub_request(:post, "https://#{client.hostname}#{path}").to_return do
370370
raise Faraday::TimeoutError.new('timeout error message')
371371
end
372372
end
@@ -380,7 +380,7 @@ def encode64(text)
380380

381381
context "and the total request time exeeds #{http_defaults.fetch(:max_retry_duration)} seconds" do
382382
let!(:default_host_request_stub) do
383-
stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
383+
stub_request(:post, "https://#{client.hostname}#{path}").to_return do
384384
sleep max_retry_duration * 1.5
385385
raise Faraday::TimeoutError.new('timeout error message')
386386
end
@@ -397,7 +397,7 @@ def encode64(text)
397397

398398
context 'and connection fails' do
399399
let!(:default_host_request_stub) do
400-
stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
400+
stub_request(:post, "https://#{client.hostname}#{path}").to_return do
401401
raise Faraday::ConnectionFailed.new('connection failure error message')
402402
end
403403
end
@@ -422,7 +422,7 @@ def encode64(text)
422422
end
423423
let(:requests) { [] }
424424
let!(:default_host_request_stub) do
425-
stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").to_return do
425+
stub_request(:post, "https://#{client.hostname}#{path}").to_return do
426426
requests << true
427427
if requests.count == 1
428428
raise Faraday::ConnectionFailed.new('connection failure error message')
@@ -450,7 +450,7 @@ def encode64(text)
450450
context 'and basic authentication fails' do
451451
let(:status) { 401 }
452452
let!(:default_host_request_stub) do
453-
stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").to_return(
453+
stub_request(:post, "https://#{client.hostname}#{path}").to_return(
454454
headers: { 'Content-Type' => 'application/json' },
455455
status: status,
456456
body: {
@@ -482,7 +482,7 @@ def encode64(text)
482482
end
483483
end
484484
let!(:default_host_request_stub) do
485-
stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block)
485+
stub_request(:post, "https://#{client.hostname}#{path}").to_return(&fallback_block)
486486
end
487487

488488
it 'attempts the fallback hosts as this is an authentication failure (#RSC15d)' do
@@ -518,7 +518,7 @@ def encode64(text)
518518
end
519519
end
520520
let!(:default_host_request_stub) do
521-
stub_request(:post, "https://#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block)
521+
stub_request(:post, "https://#{client.hostname}#{path}").to_return(&fallback_block)
522522
end
523523

524524
context 'with custom fallback hosts provided' do
@@ -555,7 +555,7 @@ def encode64(text)
555555

556556
context 'using a local web-server', webmock: false do
557557
let(:primary_host) { 'local.realtime.ably.net' }
558-
let(:fallbacks) { ['local.ably.net', 'localhost'] }
558+
let(:fallbacks) { ['localhost.ably.net', 'localhost'] }
559559
let(:port) { rand(10000) + 2000 }
560560
let(:channel_name) { 'foo' }
561561
let(:request_timeout) { 3 }
@@ -863,7 +863,7 @@ def encode64(text)
863863
end
864864
end
865865
let!(:default_host_request_stub) do
866-
stub_request(:post, "https://#{env}-#{Ably::Rest::Client::DOMAIN}#{path}").to_return(&fallback_block)
866+
stub_request(:post, "https://#{client.hostname}#{path}").to_return(&fallback_block)
867867
end
868868

869869
context 'with no fallback hosts provided (#TBC, see https://github.com/ably/wiki/issues/361)' do
@@ -1374,7 +1374,7 @@ def encode64(text)
13741374
let(:client_options) do
13751375
default_options.merge(
13761376
rest_host: 'non.existent.domain.local',
1377-
fallback_hosts: [[environment, Ably::Rest::Client::DOMAIN].join('-')],
1377+
fallback_hosts: ["sandbox.realtime.ably-nonprod.net"],
13781378
key: api_key,
13791379
logger: custom_logger,
13801380
log_retries_as_info: false)

spec/shared/client_initializer_behaviour.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,10 +164,10 @@ def rest?
164164
end
165165

166166
context 'with environment option' do
167-
let(:client_options) { default_options.merge(environment: 'sandbox', auto_connect: false) }
167+
let(:client_options) { default_options.merge(environment: 'nonprod:sandbox', auto_connect: false) }
168168

169169
it 'uses an alternate uri' do
170-
expect(subject.uri.to_s).to eql("#{protocol}s://sandbox.realtime.ably.net")
170+
expect(subject.uri.to_s).to eql("#{protocol}s://sandbox.realtime.ably-nonprod.net")
171171
end
172172
end
173173

0 commit comments

Comments
 (0)