spec/acceptance/realtime/message_spec.rb in ably-0.8.5 vs spec/acceptance/realtime/message_spec.rb in ably-0.8.6

- old
+ new

@@ -130,11 +130,10 @@ context 'when the message publisher has a client_id' do let(:client_id) { random_str } let(:client_options) { default_options.merge(client_id: client_id) } it 'contains a #client_id attribute' do - skip 'Waiting for issue #256 to be resolved' when_all(channel.attach, other_client_channel.attach) do other_client_channel.subscribe('event') do |message| expect(message.client_id).to eql(client_id) stop_reactor end @@ -206,23 +205,35 @@ 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' + it 'will not echo messages to the client from other REST clients publishing using that connection_key', em_timeout: 10 do 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) + rest_client.channel(channel_name).publish('test_event', nil, connection_key: no_echo_client.connection.key) EventMachine.add_timer(1.5) do stop_reactor end end end + + it 'will echo messages with a valid connection_id to the client from other REST clients publishing using that connection_key', em_timeout: 10 do + channel.attach do + channel.subscribe('test_event') do |message| + expect(message.connection_id).to eql(client.connection.id) + end + + rest_client.channel(channel_name).publish('test_event', nil, connection_key: client.connection.key) + 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 } @@ -597,11 +608,11 @@ 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 => :none) } + let(:client_options) { default_options.merge(:log_level => :fatal) } 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 @@ -640,18 +651,46 @@ 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 is not resumed' 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.0001) do + connection.transport.unbind # trigger failure + connection.configure_new '0123456789abcdef', 'wVIsgTHAB1UvXh7z-1991d8586', -1 # force the resume connection key to be invalid + 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 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 + EventMachine.add_timer(0.0001) do connection.transition_state_machine :suspended + stub_const 'Ably::FALLBACK_HOSTS', [] + allow(client).to receive(:endpoint).and_return(URI::Generic.build(scheme: 'wss', host: 'does.not.exist.com')) end end end end