lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb in ably-rest-0.8.3 vs lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb in ably-rest-0.8.5
- old
+ new
@@ -6,13 +6,13 @@
vary_by_protocol do
let(:default_options) { { key: api_key, environment: environment, protocol: protocol } }
let(:client_options) { default_options }
- let(:anonymous_client) { Ably::Realtime::Client.new(client_options) }
- let(:client_one) { Ably::Realtime::Client.new(client_options.merge(client_id: random_str)) }
- let(:client_two) { Ably::Realtime::Client.new(client_options.merge(client_id: random_str)) }
+ let(:anonymous_client) { auto_close Ably::Realtime::Client.new(client_options) }
+ let(:client_one) { auto_close Ably::Realtime::Client.new(client_options.merge(client_id: random_str)) }
+ let(:client_two) { auto_close Ably::Realtime::Client.new(client_options.merge(client_id: random_str)) }
let(:channel_name) { "presence-#{random_str(4)}" }
let(:channel_anonymous_client) { anonymous_client.channel(channel_name) }
let(:presence_anonymous_client) { channel_anonymous_client.presence }
let(:channel_client_one) { client_one.channel(channel_name) }
@@ -38,32 +38,43 @@
yield
end
end
unless expected_state == :left
- %w(detached failed).each do |state|
- it "raise an exception if the channel is #{state}" do
- setup_test(method_name, args, options) do
- channel_client_one.attach do
- channel_client_one.change_state state.to_sym
- expect { presence_client_one.public_send(method_name, args) }.to raise_error Ably::Exceptions::InvalidStateChange, /Operation is not allowed when channel is in STATE.#{state}/i
+ it 'raise an exception if the channel is detached' do
+ setup_test(method_name, args, options) do
+ channel_client_one.attach do
+ channel_client_one.transition_state_machine :detaching
+ channel_client_one.once(:detached) do
+ expect { presence_client_one.public_send(method_name, args) }.to raise_error Ably::Exceptions::InvalidStateChange, /Operation is not allowed when channel is in STATE.detached/i
stop_reactor
end
end
end
end
+ it 'raise an exception if the channel is failed' do
+ setup_test(method_name, args, options) do
+ channel_client_one.attach do
+ channel_client_one.transition_state_machine :failed
+ expect(channel_client_one.state).to eq(:failed)
+ expect { presence_client_one.public_send(method_name, args) }.to raise_error Ably::Exceptions::InvalidStateChange, /Operation is not allowed when channel is in STATE.failed/i
+ stop_reactor
+ end
+ end
+ end
+
it 'implicitly attaches the channel' do
expect(channel_client_one).to_not be_attached
presence_client_one.public_send(method_name, args) do
expect(channel_client_one).to be_attached
stop_reactor
end
end
context 'when :queue_messages client option is false' do
- let(:client_one) { Ably::Realtime::Client.new(default_options.merge(queue_messages: false, client_id: random_str)) }
+ let(:client_one) { auto_close Ably::Realtime::Client.new(default_options.merge(queue_messages: false, client_id: random_str)) }
context 'and connection state initialized' do
it 'raises an exception' do
expect { presence_client_one.public_send(method_name, args) }.to raise_error Ably::Exceptions::MessageQueueingDisabled
expect(client_one.connection).to be_initialized
@@ -81,11 +92,11 @@
end
end
end
context 'and connection state disconnected' do
- let(:client_one) { Ably::Realtime::Client.new(default_options.merge(queue_messages: false, client_id: random_str, :log_level => :error)) }
+ let(:client_one) { auto_close Ably::Realtime::Client.new(default_options.merge(queue_messages: false, client_id: random_str, :log_level => :error)) }
it 'raises an exception' do
client_one.connection.once(:connected) do
client_one.connection.once(:disconnected) do
expect { presence_client_one.public_send(method_name, args) }.to raise_error Ably::Exceptions::MessageQueueingDisabled
@@ -264,12 +275,11 @@
force_connection_failure client_one
end
presence_client_one.public_send(method_name, args).tap do |deferrable|
deferrable.callback { raise 'Should not succeed' }
- deferrable.errback do |presence, error|
- expect(presence).to be_a(Ably::Realtime::Presence)
+ deferrable.errback do |error|
expect(error).to be_kind_of(Ably::Exceptions::BaseAblyException)
stop_reactor
end
end
end
@@ -650,11 +660,11 @@
stop_reactor
end
context 'without necessary capabilities to join presence' do
let(:restricted_client) do
- Ably::Realtime::Client.new(default_options.merge(key: restricted_api_key, log_level: :fatal))
+ auto_close Ably::Realtime::Client.new(default_options.merge(key: restricted_api_key, log_level: :fatal))
end
let(:restricted_channel) { restricted_client.channel("cansubscribe:channel") }
let(:restricted_presence) { restricted_channel.presence }
it 'calls the Deferrable errback on capabilities failure' do
@@ -867,11 +877,11 @@
it_should_behave_like 'a public presence method', :enter_client, nil, 'client_id'
context 'without necessary capabilities to enter on behalf of another client' do
let(:restricted_client) do
- Ably::Realtime::Client.new(default_options.merge(key: restricted_api_key, log_level: :fatal))
+ auto_close Ably::Realtime::Client.new(default_options.merge(key: restricted_api_key, log_level: :fatal))
end
let(:restricted_channel) { restricted_client.channel("cansubscribe:channel") }
let(:restricted_presence) { restricted_channel.presence }
it 'calls the Deferrable errback on capabilities failure' do
@@ -1059,20 +1069,29 @@
stop_reactor
end
presence_client_one.get { raise 'Intentional exception' }
end
- %w(detached failed).each do |state|
- it "raise an exception if the channel is #{state}" do
- channel_client_one.attach do
- channel_client_one.change_state state.to_sym
- expect { presence_client_one.get }.to raise_error Ably::Exceptions::InvalidStateChange, /Operation is not allowed when channel is in STATE.#{state}/i
+ it 'raise an exception if the channel is detached' do
+ channel_client_one.attach do
+ channel_client_one.transition_state_machine :detaching
+ channel_client_one.once(:detached) do
+ expect { presence_client_one.get }.to raise_error Ably::Exceptions::InvalidStateChange, /Operation is not allowed when channel is in STATE.detached/i
stop_reactor
end
end
end
+ it 'raise an exception if the channel is failed' do
+ channel_client_one.attach do
+ channel_client_one.transition_state_machine :failed
+ expect(channel_client_one.state).to eq(:failed)
+ expect { presence_client_one.get }.to raise_error Ably::Exceptions::InvalidStateChange, /Operation is not allowed when channel is in STATE.failed/i
+ stop_reactor
+ end
+ end
+
context 'during a sync' do
let(:pages) { 2 }
let(:members_per_page) { 100 }
let(:sync_pages_received) { [] }
let(:client_options) { default_options.merge(log_level: :none) }
@@ -1118,12 +1137,12 @@
channel_client_two.attach do
client_two.connection.transport.__incoming_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message|
if protocol_message.action == :sync
# prevent any more SYNC messages coming through
client_two.connection.transport.__incoming_protocol_msgbus__.unsubscribe
- channel_client_two.change_state :detaching
- channel_client_two.change_state :detached
+ channel_client_two.transition_state_machine :detaching
+ channel_client_two.transition_state_machine :detached
end
end
end
presence_client_two.get(wait_for_sync: true).tap do |deferrable|
@@ -1378,11 +1397,11 @@
context 'client_id with ASCII_8BIT' do
let(:client_id) { random_str.encode(Encoding::ASCII_8BIT) }
context 'in connection set up' do
- let(:client_one) { Ably::Realtime::Client.new(default_options.merge(client_id: client_id)) }
+ let(:client_one) { auto_close Ably::Realtime::Client.new(default_options.merge(client_id: client_id)) }
it 'is converted into UTF_8' do
presence_client_one.enter
presence_client_one.on(:entered) do |presence|
expect(presence.client_id.encoding).to eql(Encoding::UTF_8)
@@ -1391,11 +1410,11 @@
end
end
end
context 'in channel options' do
- let(:client_one) { Ably::Realtime::Client.new(default_options) }
+ let(:client_one) { auto_close Ably::Realtime::Client.new(default_options) }
it 'is converted into UTF_8' do
presence_client_one.enter(client_id: client_id)
presence_client_one.on(:entered) do |presence|
expect(presence.client_id.encoding).to eql(Encoding::UTF_8)
@@ -1563,9 +1582,10 @@
end
context 'connection failure mid-way through a large member sync' do
let(:members_count) { 400 }
let(:sync_pages_received) { [] }
+ let(:client_options) { default_options.merge(log_level: :error) }
it 'resumes the SYNC operation', em_timeout: 15 do
when_all(*members_count.times.map do |index|
presence_client_one.enter_client("client:#{index}")
end) do