spec/acceptance/realtime/presence_spec.rb in ably-0.8.3 vs spec/acceptance/realtime/presence_spec.rb in ably-0.8.4
- old
+ new
@@ -38,22 +38,33 @@
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
@@ -1059,20 +1070,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 +1138,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|
@@ -1563,9 +1583,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