spec/acceptance/realtime/message_spec.rb in ably-0.8.3 vs spec/acceptance/realtime/message_spec.rb in ably-0.8.4
- old
+ new
@@ -179,14 +179,18 @@
end
end
context 'with :echo_messages option set to false' do
let(:no_echo_client) do
- Ably::Realtime::Client.new(default_options.merge(echo_messages: false))
+ Ably::Realtime::Client.new(default_options.merge(echo_messages: false, log_level: :debug))
end
let(:no_echo_channel) { no_echo_client.channel(channel_name) }
+ let(:rest_client) do
+ Ably::Rest::Client.new(default_options.merge(log_level: :debug))
+ end
+
it 'will not echo messages to the client but will still broadcast messages to other connected clients', em_timeout: 10 do
channel.attach do |echo_channel|
no_echo_channel.attach do
no_echo_channel.publish 'test_event', payload
@@ -194,17 +198,31 @@
fail "Message should not have been echoed back"
end
echo_channel.subscribe('test_event') do |message|
expect(message.data).to eql(payload)
- EventMachine.add_timer(1) do
+ EventMachine.add_timer(1.5) do
stop_reactor
end
end
end
end
end
+
+ it 'will not echo messages to the client from other REST clients publishing using that connection_ID', em_timeout: 10 do
+ skip 'Waiting on realtime#285 to be resolved'
+ no_echo_channel.attach do
+ no_echo_channel.subscribe('test_event') do |message|
+ fail "Message should not have been echoed back"
+ end
+
+ rest_client.channel(channel_name).publish('test_event', nil, connection_id: no_echo_client.connection.id)
+ EventMachine.add_timer(1.5) do
+ stop_reactor
+ end
+ end
+ end
end
end
context 'publishing lots of messages across two connections' do
let(:send_count) { 30 }
@@ -255,11 +273,11 @@
end
end
context 'without suitable publishing permissions' do
let(:restricted_client) do
- Ably::Realtime::Client.new(options.merge(key: restricted_api_key, environment: environment, protocol: protocol))
+ Ably::Realtime::Client.new(options.merge(key: restricted_api_key, environment: environment, protocol: protocol, :log_level => :error))
end
let(:restricted_channel) { restricted_client.channel("cansubscribe:example") }
let(:payload) { 'Test message without permission to publish' }
it 'calls the error callback' do
@@ -561,9 +579,107 @@
encrypted_channel_client1.publish 'example', payload
encrypted_channel_client2.on(:error) do |error|
expect(error).to be_a(Ably::Exceptions::CipherError)
expect(error.code).to eql(92003)
expect(error.message).to match(/CipherError decrypting data/)
+ stop_reactor
+ end
+ end
+ end
+ end
+ end
+
+ describe 'when message is published, the connection disconnects before the ACK is received, and the connection is resumed' do
+ let(:event_name) { random_str }
+ let(:message_state) { [] }
+ let(:connection) { client.connection }
+ let(:client_options) { default_options.merge(:log_level => :debug) }
+ let(:msgs_received) { [] }
+
+ it 'publishes the message again, later receives the ACK and only one message is ever received from Ably' do
+ on_reconnected = Proc.new do
+ expect(message_state).to be_empty
+ EventMachine.add_timer(2) do
+ expect(message_state).to contain_exactly(:delivered)
+ # TODO: Uncomment once issue realtime#42 is resolved
+ # expect(msgs_received.length).to eql(1)
+ stop_reactor
+ end
+ end
+
+ connection.once(:connected) do
+ connection.transport.__outgoing_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message|
+ if protocol_message.messages.find { |message| message.name == event_name }
+ EventMachine.add_timer(0.001) do
+ connection.transport.unbind # trigger failure
+ expect(message_state).to be_empty
+ connection.once :connected, &on_reconnected
+ end
+ end
+ end
+ end
+
+ channel.publish(event_name).tap do |deferrable|
+ deferrable.callback { message_state << :delivered }
+ deferrable.errback do
+ raise 'Message delivery should not fail'
+ end
+ end
+
+ channel.subscribe do |message|
+ msgs_received << message
+ end
+ end
+ end
+
+ describe 'when message is published, the connection disconnects before the ACK is received' do
+ let(:connection) { client.connection }
+ let(:event_name) { random_str }
+
+ describe 'the connection becomes suspended' do
+ let(:client_options) { default_options.merge(:log_level => :fatal) }
+
+ it 'calls the errback for all messages' do
+ connection.once(:connected) do
+ connection.transport.__outgoing_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message|
+ if protocol_message.messages.find { |message| message.name == event_name }
+ EventMachine.add_timer(0.001) do
+ connection.transition_state_machine :suspended
+ end
+ end
+ end
+ end
+
+ channel.publish(event_name).tap do |deferrable|
+ deferrable.callback do
+ raise 'Message delivery should not happen'
+ end
+ deferrable.errback do
+ stop_reactor
+ end
+ end
+ end
+ end
+
+ describe 'the connection becomes failed' do
+ let(:client_options) { default_options.merge(:log_level => :none) }
+
+ it 'calls the errback for all messages' do
+ connection.once(:connected) do
+ connection.transport.__outgoing_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message|
+ if protocol_message.messages.find { |message| message.name == event_name }
+ EventMachine.add_timer(0.001) do
+ connection.transition_state_machine :failed, reason: RuntimeError.new
+ end
+ end
+ end
+ end
+
+ channel.publish(event_name).tap do |deferrable|
+ deferrable.callback do
+ raise 'Message delivery should not happen'
+ end
+ deferrable.errback do
stop_reactor
end
end
end
end