spec/acceptance/realtime/connection_spec.rb in ably-0.7.1 vs spec/acceptance/realtime/connection_spec.rb in ably-0.7.2

- old
+ new

@@ -196,11 +196,10 @@ skip 'transitions state to failed' end end end end - end context 'initialization state changes' do let(:phases) { [:connecting, :connected] } let(:events_triggered) { [] } @@ -328,10 +327,52 @@ end end end end + describe '#serial connection serial' do + let(:channel) { client.channel(random_str) } + + it 'is set to -1 when a new connection is opened' do + connection.connect do + expect(connection.serial).to eql(-1) + stop_reactor + end + end + + context 'when a message is sent but the ACK has not yet been received' do + + it 'the sent message msgSerial is 0 but the connection serial remains at -1' do + channel.attach do + connection.__outgoing_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message| + connection.__outgoing_protocol_msgbus__.unsubscribe + expect(protocol_message['msgSerial']).to eql(0) + expect(connection.serial).to eql(-1) + stop_reactor + end + channel.publish('event', 'data') + end + end + end + + it 'is set to 0 when a message sent ACK is received' do + channel.publish('event', 'data') do + expect(connection.serial).to eql(0) + stop_reactor + end + end + + it 'is set to 1 when the second message sent ACK is received' do + channel.publish('event', 'data') do + channel.publish('event', 'data') do + expect(connection.serial).to eql(1) + stop_reactor + end + end + end + end + context '#close' do it 'returns a Deferrable' do connection.connect do expect(connection.close).to be_a(EventMachine::Deferrable) stop_reactor @@ -489,11 +530,11 @@ end let(:available_states) { self.class.available_states} let(:states) { Hash.new } let(:client_options) { default_options.merge(log_level: :none) } - it 'is composed of connection id and serial that is kept up to date with each message sent' do + it 'is composed of connection id and serial that is kept up to date with each message ACK received' do connection.on(:connected) do expected_serial = -1 expect(connection.id).to_not be_nil expect(connection.serial).to eql(expected_serial) @@ -679,10 +720,34 @@ it 'returns a Deferrable' do expect(connection.internet_up?).to be_a(EventMachine::Deferrable) stop_reactor end + context 'internet up URL protocol' do + let(:http_request) { double('EventMachine::HttpRequest', get: EventMachine::DefaultDeferrable.new) } + + context 'when using TLS for the connection' do + let(:client_options) { default_options.merge(tls: true) } + + it 'uses TLS for the Internet check to https://internet-up.ably-realtime.com/is-the-internet-up.txt' do + expect(EventMachine::HttpRequest).to receive(:new).with('https://internet-up.ably-realtime.com/is-the-internet-up.txt').and_return(http_request) + connection.internet_up? + stop_reactor + end + end + + context 'when using a non-secured connection' do + let(:client_options) { default_options.merge(tls: false, use_token_auth: true) } + + it 'uses TLS for the Internet check to http://internet-up.ably-realtime.com/is-the-internet-up.txt' do + expect(EventMachine::HttpRequest).to receive(:new).with('http://internet-up.ably-realtime.com/is-the-internet-up.txt').and_return(http_request) + connection.internet_up? + stop_reactor + end + end + end + context 'when the Internet is up' do it 'calls the block with true' do connection.internet_up? do |result| expect(result).to be_truthy stop_reactor @@ -696,10 +761,10 @@ end end context 'when the Internet is down' do before do - stub_const 'Ably::INTERNET_CHECK', { url: 'http://does.not.exist.com', ok_text: 'no.way.this.will.match' } + stub_const 'Ably::INTERNET_CHECK', { url: '//does.not.exist.com', ok_text: 'no.way.this.will.match' } end it 'calls the block with false' do connection.internet_up? do |result| expect(result).to be_falsey