spec/acceptance/realtime/connection_spec.rb in ably-0.8.13 vs spec/acceptance/realtime/connection_spec.rb in ably-0.8.14
- old
+ new
@@ -831,10 +831,26 @@
end
connection.connect
end
end
end
+
+ context 'with a different connection_state_ttl' do
+ before do
+ old_defaults = Ably::Realtime::Connection::DEFAULTS
+ stub_const 'Ably::Realtime::Connection::DEFAULTS', old_defaults.merge(connection_state_ttl: 15)
+ end
+
+ it 'updates the private Connection#connection_state_ttl' do
+ expect(connection.connection_state_ttl).to eql(15)
+
+ connection.once(:connected) do
+ expect(connection.connection_state_ttl).to be > 15
+ stop_reactor
+ end
+ end
+ end
end
context 'recovery' do
let(:channel_name) { random_str }
let(:channel) { client.channel(channel_name) }
@@ -846,18 +862,18 @@
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,
+ max_connection_state_ttl: 0.2,
realtime_request_timeout: 5
)
end
describe '#recovery_key' do
def self.available_states
- [:connecting, :connected, :disconnected, :suspended, :failed]
+ [:connecting, :connected, :disconnected]
end
let(:available_states) { self.class.available_states }
let(:states) { Hash.new }
let(:channel) { client.channel(random_str) }
@@ -966,23 +982,29 @@
end
context 'when messages have been sent whilst the old connection is disconnected' do
describe 'the new connection' do
it 'recovers server-side queued messages' do
+ connection_id, recovery_key = nil, nil
+
channel.attach do
- connection.transition_state_machine! :failed
+ connection_id = client.connection.id
+ recovery_key = client.connection.recovery_key
+ connection.transport.__incoming_protocol_msgbus__
+ publishing_client_channel.publish('event', 'message') do
+ connection.transition_state_machine! :failed
+ end
end
connection.on(:failed) do
- publishing_client_channel.publish('event', 'message') do
- recover_client = auto_close Ably::Realtime::Client.new(default_options.merge(recover: client.connection.recovery_key))
- recover_client_channel = recover_client.channel(channel_name)
- recover_client_channel.attach do
- recover_client_channel.subscribe('event') do |message|
- expect(message.data).to eql('message')
- stop_reactor
- end
+ recover_client = auto_close Ably::Realtime::Client.new(default_options.merge(recover: recovery_key))
+ recover_client_channel = recover_client.channel(channel_name)
+ recover_client_channel.attach do
+ expect(recover_client.connection.id).to eql(connection_id)
+ recover_client_channel.subscribe('event') do |message|
+ expect(message.data).to eql('message')
+ stop_reactor
end
end
end
end
end
@@ -1210,11 +1232,11 @@
let(:client_options) do
default_options.merge(
log_level: :fatal,
disconnected_retry_timeout: 0.02,
suspended_retry_timeout: 60,
- connection_state_ttl: 0.05
+ max_connection_state_ttl: 0.05
)
end
it 'detaches the channels and prevents publishing of messages on those channels' do
channel.attach do
@@ -1372,9 +1394,30 @@
uri = URI.parse(url)
expect(CGI::parse(uri.query)['lib'][0]).to eql("ruby-#{Ably::VERSION}")
stop_reactor
end
client
+ end
+
+ context 'with variant' do
+ let(:variant) { 'foo ' }
+
+ before do
+ Ably.lib_variant = variant
+ end
+
+ after do
+ Ably.lib_variant = nil
+ end
+
+ it 'sends the lib version param lib with the variant' do
+ expect(EventMachine).to receive(:connect) do |host, port, transport, object, url|
+ uri = URI.parse(url)
+ expect(CGI::parse(uri.query)['lib'][0]).to eql("ruby-#{variant}-#{Ably::VERSION}")
+ stop_reactor
+ end
+ client
+ end
end
end
end
end