lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb in ably-rest-1.1.7 vs lib/submodules/ably-ruby/spec/acceptance/realtime/channel_spec.rb in ably-rest-1.1.8
- old
+ new
@@ -748,10 +748,111 @@
stop_reactor if messages.count == 3
end
end
end
+ describe '#(RTL17)' do
+ context 'when channel is initialized' do
+ it 'sends messages only on attach' do
+ expect(channel).to be_initialized
+ channel.publish('event', payload)
+
+ channel.subscribe do |message|
+ stop_reactor if message.data == payload && channel.attached?
+ end
+
+ channel.attach
+ end
+ end
+
+ context 'when channel is attaching' do
+ it 'sends messages only on attach' do
+ channel.publish('event', payload)
+
+ sent_message = nil
+ channel.subscribe do |message|
+ return if message.data != payload
+ sent_message = message
+
+ stop_reactor if channel.attached?
+ end
+
+ channel.on(:attaching) do
+ expect(channel).to be_attaching
+ expect(sent_message).to be_nil
+ end
+
+ channel.attach
+ end
+ end
+
+ context 'when channel is detaching' do
+ it 'stops sending message' do
+ sent_message = nil
+ event_published = false
+ channel.subscribe do |message|
+ sent_message = message if message.data == payload
+ end
+
+ channel.on(:detaching) do
+ channel.publish('event', payload)
+ event_published = true
+ end
+
+ channel.on(:detaching) do
+ EventMachine.next_tick do
+ expect(sent_message).to be_nil
+ stop_reactor if event_published
+ end
+ end
+
+ channel.attach do
+ channel.detach
+ end
+ end
+ end
+
+ context 'when channel is detached' do
+ it 'stops sending message' do
+ sent_message = nil
+ event_published = false
+ channel.subscribe do |message|
+ sent_message = message if message.data == payload
+ end
+
+ channel.on(:detaching) do
+ channel.publish('event', payload)
+ event_published = true
+ end
+
+ channel.on(:detached) do
+ expect(sent_message).to be_nil
+ stop_reactor if event_published
+ end
+
+ channel.attach do
+ channel.detach
+ end
+ end
+ end
+
+ context 'when channel is failed' do
+ it 'errors when trying to send a message' do
+ channel.once(:failed) do
+ channel.publish('event', payload).errback do |error|
+ expect(error).to be_a(Ably::Exceptions::ChannelInactive)
+ stop_reactor
+ end
+ end
+
+ channel.attach do
+ channel.transition_state_machine(:failed)
+ end
+ end
+ end
+ end
+
context 'when channel is not attached in state Initializing (#RTL6c1)' do
it 'publishes messages immediately and does not implicitly attach (#RTL6c1)' do
sub_channel.attach do
sub_channel.subscribe do |message|
messages << message if message.name == 'event'
@@ -1179,11 +1280,11 @@
end
end
end
context 'with more than allowed messages in a single publish' do
- let(:channel_name) { random_str }
+ 65536
it 'rejects the publish' do
messages = (Ably::Realtime::Connection::MAX_PROTOCOL_MESSAGE_BATCH_SIZE + 1).times.map do
{ name: 'foo' }
end
@@ -1403,21 +1504,104 @@
end
end
end
context 'message size exceeded (#TO3l8)' do
- let(:message) { 'x' * 700000 }
-
let(:client) { auto_close Ably::Realtime::Client.new(client_options) }
let(:channel) { client.channels.get(channel_name) }
- it 'should not allow to send a message' do
- channel.publish('event', message).errback do |error|
- expect(error).to be_instance_of(Ably::Exceptions::MaxMessageSizeExceeded)
- stop_reactor
+ context 'and max_message_size is default (65536 bytes)' do
+ let(:channel_name) { random_str }
+ let(:max_message_size) { 65536 }
+
+ it 'should allow to send a message (32 bytes)' do
+ client.connection.once(:connected) do
+ channel.subscribe('event') do |msg|
+ expect(msg.data).to eq('x' * 32)
+ stop_reactor
+ end
+ channel.publish('event', 'x' * 32)
+ end
end
+
+ it 'should not allow to send a message (700000 bytes)' do
+ client.connection.once(:connected) do
+ connection_details = Ably::Models::ConnectionDetails.new(
+ client.connection.details.attributes.attributes.merge('maxMessageSize' => max_message_size)
+ )
+ client.connection.set_connection_details(connection_details)
+ expect(client.connection.details.max_message_size).to eq(65536)
+ channel.publish('event', 'x' * 700000).errback do |error|
+ expect(error).to be_instance_of(Ably::Exceptions::MaxMessageSizeExceeded)
+ stop_reactor
+ end
+ end
+ end
end
+
+ context 'and max_message_size is customized (11 bytes)' do
+ let(:max_message_size) { 11 }
+
+ context 'and the message size is 30 bytes' do
+ let(:channel_name) { random_str }
+
+ it 'should not allow to send a message' do
+ client.connection.once(:connected) do
+ connection_details = Ably::Models::ConnectionDetails.new(
+ client.connection.details.attributes.attributes.merge('maxMessageSize' => max_message_size)
+ )
+ client.connection.set_connection_details(connection_details)
+ expect(client.connection.details.max_message_size).to eq(11)
+ channel.publish('event', 'x' * 30).errback do |error|
+ expect(error).to be_instance_of(Ably::Exceptions::MaxMessageSizeExceeded)
+ stop_reactor
+ end
+ end
+ end
+ end
+ end
+
+ context 'and max_message_size is nil' do
+ let(:max_message_size) { nil }
+
+ context 'and the message size is 30 bytes' do
+ let(:channel_name) { random_str }
+
+ it 'should allow to send a message' do
+ client.connection.once(:connected) do
+ connection_details = Ably::Models::ConnectionDetails.new(
+ client.connection.details.attributes.attributes.merge('maxMessageSize' => max_message_size)
+ )
+ client.connection.set_connection_details(connection_details)
+ expect(client.connection.details.max_message_size).to eq(65536)
+ channel.subscribe('event') do |msg|
+ expect(msg.data).to eq('x' * 30)
+ stop_reactor
+ end
+ channel.publish('event', 'x' * 30)
+ end
+ end
+ end
+
+ context 'and the message size is 65537 bytes' do
+ let(:channel_name) { random_str }
+
+ it 'should not allow to send a message' do
+ client.connection.once(:connected) do
+ connection_details = Ably::Models::ConnectionDetails.new(
+ client.connection.details.attributes.attributes.merge('maxMessageSize' => max_message_size)
+ )
+ client.connection.set_connection_details(connection_details)
+ expect(client.connection.details.max_message_size).to eq(65536)
+ channel.publish('event', 'x' * 65537).errback do |error|
+ expect(error).to be_instance_of(Ably::Exceptions::MaxMessageSizeExceeded)
+ stop_reactor
+ end
+ end
+ end
+ end
+ end
end
end
describe '#subscribe' do
context 'with an event argument' do
@@ -2220,9 +2404,30 @@
detach_message = Ably::Models::ProtocolMessage.new(action: detached_action, channel: channel_name, error: { code: 50505 })
client.connection.__incoming_protocol_msgbus__.publish :protocol_message, detach_message
end
channel.transition_state_machine! :suspended
+ end
+ end
+
+ context 'when connection is no longer connected' do
+ it 'will not attempt to reattach (#RTL13c)' do
+ channel.attach do
+ connection.once(:closing) do
+ channel.once(:attaching) do |state_change|
+ raise 'Channel should not attempt to reattach'
+ end
+
+ channel.transition_state_machine! :suspended
+ end
+
+ connection.once(:closed) do
+ expect(channel).to be_suspended
+ stop_reactor
+ end
+
+ connection.close
+ end
end
end
end
context 'and channel is attaching' do