spec/acceptance/realtime/connection_spec.rb in ably-1.0.5 vs spec/acceptance/realtime/connection_spec.rb in ably-1.0.6

- old
+ new

@@ -129,11 +129,11 @@ context 'with immediately expired token' do let(:ttl) { 0.001 } let(:auth_requests) { [] } let(:token_callback) do - Proc.new do + lambda do |token_params| auth_requests << Time.now Ably::Rest::Client.new(default_options).auth.request_token(ttl: ttl).token end end let(:client_options) { default_options.merge(auth_callback: token_callback) } @@ -244,11 +244,11 @@ context 'connection state' do let(:publish_count) { 10 } let(:ttl) { 4 } let(:auth_requests) { [] } let(:token_callback) do - Proc.new do + lambda do |token_params| sleep 2 auth_requests << Time.now Ably::Rest::Client.new(default_options).auth.request_token(ttl: ttl).token end end @@ -296,11 +296,11 @@ end context 'and subsequent token is invalid' do let(:ttl) { 2 } let(:token_callback) do - Proc.new do + lambda do |token_params| if @token_issued "#{app_id}.invalid-token-invalid-token-invalid-token" else @token_issued = true Ably::Rest::Client.new(default_options).auth.request_token(ttl: ttl).token @@ -415,11 +415,11 @@ context 'initialization state changes' do let(:phases) { [:connecting, :connected] } let(:events_emitted) { [] } let(:test_expectation) do - Proc.new do + lambda do expect(events_emitted).to eq(phases) stop_reactor end end @@ -464,11 +464,11 @@ connection.once(:disconnected) do been_disconnected = true end connection.once(:connecting) do - close_if_transport_available = proc do + close_if_transport_available = lambda do EventMachine.add_timer(0.001) do if connection.transport connection.transport.close_connection_after_writing else close_if_transport_available.call @@ -794,11 +794,11 @@ if protocol_message.action == :heartbeat heartbeat_ids << protocol_message.id end end - ping_block = Proc.new do + ping_block = lambda do |time| pings_complete << true if pings_complete.length == 3 expect(heartbeat_ids.uniq.length).to eql(3) stop_reactor end @@ -978,26 +978,23 @@ end end context 'transport-level heartbeats are supported in the websocket transport' do it 'provides the heartbeats argument in the websocket connection params (#RTN23b)' do - skip 'Native heartbeats not yet supported in the WS driver https://github.com/ably/ably-ruby/issues/116' expect(EventMachine).to receive(:connect) do |host, port, transport, object, url| uri = URI.parse(url) expect(CGI::parse(uri.query)['heartbeats'][0]).to eql('false') stop_reactor end client end it 'receives websocket heartbeat messages (#RTN23b) [slow test as need to wait for heartbeat]', em_timeout: 45 do - skip "Heartbeats param is missing from realtime implementation, see https://github.com/ably/realtime/issues/656" - connection.once(:connected) do connection.__incoming_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message| if protocol_message.action == :heartbeat - expect(protocol_message.attributes[:source]).to eql('websocket') + expect(protocol_message.attributes[:source]).to eql(:websocket) expect(connection.time_since_connection_confirmed_alive?).to be_within(1).of(0) stop_reactor end end end @@ -1019,11 +1016,12 @@ it 'receives websocket protocol messages (#RTN23b) [slow test as need to wait for heartbeat]', em_timeout: 45 do connection.once(:connected) do connection.__incoming_protocol_msgbus__.subscribe(:protocol_message) do |protocol_message| if protocol_message.action == :heartbeat - expect(protocol_message.attributes[:source]).to_not eql('websocket') + next if protocol_message.attributes[:source] == :websocket # ignore the native heartbeats + expect(protocol_message.attributes[:source]).to_not eql(:websocket) expect(connection.time_since_connection_confirmed_alive?).to be_within(1).of(0) stop_reactor end end end @@ -1174,28 +1172,22 @@ end end end context "opening a new connection using a recently disconnected connection's #recovery_key" do - context 'connection#id and connection#key after recovery' do - it 'remains the same for id and party for key' do - connection_key_consistent_part_regex = /.*?!([\w-]{5,})-\w+/ + context 'connection#id after recovery' do + it 'remains the same' do previous_connection_id = nil - previous_connection_key = nil connection.once(:connected) do previous_connection_id = connection.id - previous_connection_key = connection.key connection.transition_state_machine! :failed end connection.once(:failed) do recover_client = auto_close Ably::Realtime::Client.new(default_options.merge(recover: client.connection.recovery_key)) recover_client.connection.on(:connected) do - expect(recover_client.connection.key[connection_key_consistent_part_regex, 1]).to_not be_nil - expect(recover_client.connection.key[connection_key_consistent_part_regex, 1]).to eql( - previous_connection_key[connection_key_consistent_part_regex, 1]) expect(recover_client.connection.id).to eql(previous_connection_id) stop_reactor end end end @@ -1483,11 +1475,11 @@ expect(error).to be_a(Ably::Exceptions::MessageQueueingDisabled) stop_reactor end end - close_connection_proc = Proc.new do + close_connection_proc = lambda do EventMachine.add_timer(0.001) do if connection.transport.nil? close_connection_proc.call else connection.transport.close_connection_after_writing @@ -1521,10 +1513,10 @@ context 'connection state change' do # See https://github.com/ably/ably-ruby/issues/103 it 'emits event to all and single subscribers' do connected_emitted = [] - block = Proc.new do |state_change| + block = lambda do |state_change| if state_change.current == :connected connected_emitted << state_change EventMachine.add_timer(0.5) do expect(connected_emitted.length).to eql(2) stop_reactor