spec/acceptance/realtime/connection_spec.rb in ably-0.8.7 vs spec/acceptance/realtime/connection_spec.rb in ably-0.8.8
- old
+ new
@@ -139,11 +139,11 @@
it 'renews the token on connect, and makes one immediate subsequent attempt to obtain a new token' do
started_at = Time.now.to_f
connection.once(:disconnected) do
connection.once(:disconnected) do |connection_state_change|
- expect(connection_state_change.reason.code).to eql(40140) # token expired
+ expect(connection_state_change.reason.code).to eql(40142) # token expired
expect(Time.now.to_f - started_at).to be < 1000
expect(auth_requests.count).to eql(2)
stop_reactor
end
end
@@ -154,11 +154,11 @@
it 'renews the token on connect, and continues to attempt renew based on the retry schedule' do
started_at = Time.now.to_f
disconnect_count = 0
connection.on(:disconnected) do |connection_state_change|
- expect(connection_state_change.reason.code).to eql(40140) # token expired
+ expect(connection_state_change.reason.code).to eql(40142) # token expired
disconnect_count += 1
if disconnect_count == 6
expect(Time.now.to_f - started_at).to be > 4 * 0.5 # at least 4 0.5 second pauses should have happened
expect(Time.now.to_f - started_at).to be < 9 # allow 1.5 seconds for each authentication cycle
stop_reactor
@@ -205,11 +205,11 @@
connection.once(:connected) do
original_token = client.auth.current_token_details
expect(original_token).to_not be_expired
started_at = Time.now
connection.once(:disconnected) do |connection_state_change|
- expect(connection_state_change.reason.code).to eq(40140) # Token expired
+ expect(connection_state_change.reason.code).to eq(40142) # Token expired
# Token has expired, so now ensure it is not used again
stub_const 'Ably::Models::TokenDetails::TOKEN_EXPIRY_BUFFER', original_token_expiry_buffer
stub_const 'Ably::Auth::TOKEN_DEFAULTS', Ably::Auth::TOKEN_DEFAULTS.merge(renew_token_buffer: original_renew_token_buffer)
@@ -331,11 +331,11 @@
it 'transitions state to failed', em_timeout: 10 do
EventMachine.add_timer(1) do # wait for token to expire
expect(expired_token_details).to be_expired
connection.once(:connected) { raise 'Connection should never connect as token has expired' }
connection.once(:failed) do
- expect(client.connection.error_reason.code).to eql(40140)
+ expect(client.connection.error_reason.code).to eql(40142)
stop_reactor
end
end
end
end
@@ -798,10 +798,45 @@
end
end
end
end
+ context '#details' do
+ let(:connection) { client.connection }
+
+ it 'is nil before connected' do
+ connection.on(:connecting) do
+ expect(connection.details).to eql(nil)
+ stop_reactor
+ end
+ end
+
+ it 'contains the ConnectionDetails object once connected' do
+ connection.on(:connected) do
+ expect(connection.details).to be_a(Ably::Models::ConnectionDetails)
+ expect(connection.details.connection_key).to_not be_nil
+ expect(connection.details.server_id).to_not be_nil
+ stop_reactor
+ end
+ end
+
+ it 'contains the new ConnectionDetails object once a subsequent connection is created' do
+ connection.once(:connected) do
+ expect(connection.details.connection_key).to_not be_nil
+ old_key = connection.details.connection_key
+ connection.close do
+ connection.once(:connected) do
+ expect(connection.details.connection_key).to_not be_nil
+ expect(connection.details.connection_key).to_not eql(old_key)
+ stop_reactor
+ end
+ connection.connect
+ end
+ end
+ end
+ end
+
context 'recovery' do
let(:channel_name) { random_str }
let(:channel) { client.channel(channel_name) }
let(:publishing_client) do
auto_close Ably::Realtime::Client.new(client_options)
@@ -811,11 +846,12 @@
let(:client_options) do
default_options.merge(
log_level: :none,
disconnected_retry_timeout: 0.1,
suspended_retry_timeout: 0.1,
- connection_state_ttl: 0.2
+ connection_state_ttl: 0.2,
+ realtime_request_timeout: 5
)
end
describe '#recovery_key' do
def self.available_states
@@ -887,11 +923,12 @@
end
end
context "opening a new connection using a recently disconnected connection's #recovery_key" do
context 'connection#id and connection#key after recovery' do
- it 'remains the same' do
+ it 'remains the same for id and party for key' do
+ connection_key_consistent_part_regex = /.*?!(\w{5,})-/
previous_connection_id = nil
previous_connection_key = nil
connection.once(:connected) do
previous_connection_id = connection.id
@@ -900,11 +937,12 @@
end
connection.once(:failed) do
recover_client = auto_close Ably::Realtime::Client.new(default_options.merge(recover: client.connection.recovery_key))
recover_client.connection.on(:connected) do
- expect(recover_client.connection.key[/^\w{5,}-/, 0]).to_not be_nil
- expect(recover_client.connection.key[/^\w{5,}-/, 0]).to eql(previous_connection_key[/^\w{5,}-/, 0])
+ expect(recover_client.connection.key[connection_key_consistent_part_regex, 1]).to_not be_nil
+ expect(recover_client.connection.key[connection_key_consistent_part_regex, 1]).to eql(
+ previous_connection_key[connection_key_consistent_part_regex, 1])
expect(recover_client.connection.id).to eql(previous_connection_id)
stop_reactor
end
end
end