spec/acceptance/realtime/message_spec.rb in ably-0.8.4 vs spec/acceptance/realtime/message_spec.rb in ably-0.8.5
- old
+ new
@@ -7,16 +7,16 @@
describe 'Ably::Realtime::Channel Message', :event_machine do
vary_by_protocol do
let(:default_options) { options.merge(key: api_key, environment: environment, protocol: protocol) }
let(:client_options) { default_options }
let(:client) do
- Ably::Realtime::Client.new(client_options)
+ auto_close Ably::Realtime::Client.new(client_options)
end
let(:channel) { client.channel(channel_name) }
let(:other_client) do
- Ably::Realtime::Client.new(client_options)
+ auto_close Ably::Realtime::Client.new(client_options)
end
let(:other_client_channel) { other_client.channel(channel_name) }
let(:channel_name) { "subscribe_send_text-#{random_str}" }
let(:options) { { :protocol => :json } }
@@ -179,16 +179,16 @@
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, log_level: :debug))
+ auto_close Ably::Realtime::Client.new(default_options.merge(echo_messages: false))
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))
+ Ably::Rest::Client.new(default_options)
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
@@ -273,20 +273,19 @@
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, :log_level => :error))
+ auto_close 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
restricted_channel.attach do
deferrable = restricted_channel.publish('test_event', payload)
- deferrable.errback do |message, error|
- expect(message.data).to eql(payload)
+ deferrable.errback do |error|
expect(error.status).to eql(401)
stop_reactor
end
deferrable.callback do |message|
fail 'Success callback should not have been called'
@@ -416,43 +415,51 @@
context 'with multiple sends from one client to another' do
let(:cipher_options) { { key: random_str(32) } }
let(:encrypted_channel_client1) { client.channel(channel_name, encrypted: true, cipher_params: cipher_options) }
let(:encrypted_channel_client2) { other_client.channel(channel_name, encrypted: true, cipher_params: cipher_options) }
- let(:data) { MessagePack.pack({ 'key' => random_str }) }
+ let(:data) { { 'key' => random_str } }
let(:message_count) { 50 }
it 'encrypts and decrypts all messages' do
- messages_received = {
- decrypted: 0,
- encrypted: 0
- }
+ messages_received = []
- encrypted_channel_client2.attach do
- encrypted_channel_client2.subscribe do |message|
- expect(message.data).to eql("#{message.name}-#{data}")
+ encrypted_channel_client1.attach do
+ encrypted_channel_client1.subscribe do |message|
+ expect(message.data).to eql(MessagePack.pack(data.merge(index: message.name.to_i)))
expect(message.encoding).to be_nil
- messages_received[:decrypted] += 1
- stop_reactor if messages_received[:decrypted] == message_count
+ messages_received << message
+ stop_reactor if messages_received.count == message_count
end
- encrypted_channel_client1.__incoming_msgbus__.subscribe(:message) do |message|
- expect(message['encoding']).to match(/cipher\+/)
- messages_received[:encrypted] += 1
+ message_count.times do |index|
+ encrypted_channel_client2.publish index.to_s, MessagePack.pack(data.merge(index: index))
end
end
+ end
- message_count.times do |index|
- encrypted_channel_client2.publish index.to_s, "#{index}-#{data}"
+ it 'receives raw messages with the correct encoding' do
+ encrypted_channel_client1.attach do
+ client.connection.__incoming_protocol_msgbus__.unsubscribe # remove all listeners
+ client.connection.__incoming_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message|
+ if protocol_message.action == Ably::Models::ProtocolMessage::ACTION.Message
+ protocol_message.messages.each do |message|
+ expect(message['encoding']).to match(/cipher\+/)
+ end
+ stop_reactor
+ end
+ end
+
+ encrypted_channel_client2.publish 'name', MessagePack.pack('data')
end
end
end
context 'subscribing with a different transport protocol' do
let(:other_protocol) { protocol == :msgpack ? :json : :msgpack }
let(:other_client) do
- Ably::Realtime::Client.new(default_options.merge(protocol: other_protocol))
+ auto_close Ably::Realtime::Client.new(default_options.merge(protocol: other_protocol))
end
let(:cipher_options) { { key: random_str(32), algorithm: 'aes', mode: 'cbc', key_length: 256 } }
let(:encrypted_channel_client1) { client.channel(channel_name, encrypted: true, cipher_params: cipher_options) }
let(:encrypted_channel_client2) { other_client.channel(channel_name, encrypted: true, cipher_params: cipher_options) }
@@ -590,10 +597,10 @@
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(:client_options) { default_options.merge(:log_level => :none) }
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