lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb in ably-rest-0.8.15 vs lib/submodules/ably-ruby/spec/acceptance/realtime/presence_spec.rb in ably-rest-0.9.0

- old
+ new

@@ -40,15 +40,13 @@ end end def setup_test(method_name, args, options) if options[:enter_first] - presence_client_one.subscribe do - presence_client_one.unsubscribe + presence_client_one.public_send(method_name.to_s.gsub(/leave|update/, 'enter'), args) do yield end - presence_client_one.public_send(method_name.to_s.gsub(/leave|update/, 'enter'), args) else yield end end @@ -468,18 +466,11 @@ end end context 'once server sync is complete' do it 'behaves like an Enumerable allowing direct access to current members' do - presence_client_one.enter - presence_client_two.enter - - entered = 0 - presence_client_one.subscribe(:enter) do - entered += 1 - next unless entered == 2 - + when_all(presence_client_one.enter, presence_client_two.enter) do presence_anonymous_client.members.once(:in_sync) do expect(presence_anonymous_client.members.count).to eql(2) member_ids = presence_anonymous_client.members.map(&:member_key) expect(member_ids.count).to eql(2) expect(member_ids.uniq.count).to eql(2) @@ -502,14 +493,11 @@ end end context 'when attaching to a channel with members present' do it 'is false and the presence channel will subsequently be synced' do - presence_client_one.enter - presence_client_one.subscribe(:enter) do - presence_client_one.unsubscribe :enter - + presence_client_one.enter do channel_anonymous_client.attach do expect(channel_anonymous_client.presence).to_not be_sync_complete channel_anonymous_client.presence.get(wait_for_sync: true) do expect(channel_anonymous_client.presence).to be_sync_complete stop_reactor @@ -690,44 +678,40 @@ context '#get' do context 'with :wait_for_sync option set to true' do it 'waits until sync is complete', em_timeout: 30 do # allow for slow connections and lots of messages enter_expected_count.times do |index| EventMachine.add_timer(index / 10) do - presence_client_one.enter_client("client:#{index}") - end - end + presence_client_one.enter_client("client:#{index}") do |message| + entered << message + next unless entered.count == enter_expected_count - presence_client_one.subscribe(:enter) do |message| - entered << message - next unless entered.count == enter_expected_count - - presence_anonymous_client.get(wait_for_sync: true) do |members| - expect(members.map(&:client_id).uniq.count).to eql(enter_expected_count) - expect(members.count).to eql(enter_expected_count) - stop_reactor + presence_anonymous_client.get(wait_for_sync: true) do |members| + expect(members.map(&:client_id).uniq.count).to eql(enter_expected_count) + expect(members.count).to eql(enter_expected_count) + stop_reactor + end + end end end end end context 'by default' do it 'it does not wait for sync', em_timeout: 30 do # allow for slow connections and lots of messages - enter_expected_count.times do |indx| - EventMachine.add_timer(indx / 10) do - presence_client_one.enter_client "client:#{indx}" - end - end + enter_expected_count.times do |index| + EventMachine.add_timer(index / 10) do + presence_client_one.enter_client("client:#{index}") do |message| + entered << message + next unless entered.count == enter_expected_count - presence_client_one.subscribe(:enter) do |message| - entered << message - next unless entered.count == enter_expected_count - - channel_anonymous_client.attach do - presence_anonymous_client.get do |members| - expect(presence_anonymous_client.members).to_not be_in_sync - expect(members.count).to eql(0) - stop_reactor + channel_anonymous_client.attach do + presence_anonymous_client.get do |members| + expect(presence_anonymous_client.members).to_not be_in_sync + expect(members.count).to eql(0) + stop_reactor + end + end end end end end end @@ -910,29 +894,19 @@ end end context 'and sync is complete' do it 'does not cache members that have left' do - enter_ack = false - - presence_client_one.subscribe(:enter) do - presence_client_one.unsubscribe :enter - + presence_client_one.enter enter_data do expect(presence_client_one.members).to be_in_sync expect(presence_client_one.members.send(:members).count).to eql(1) presence_client_one.leave data end - presence_client_one.enter(enter_data) do - enter_ack = true - end - presence_client_one.subscribe(:leave) do |presence_message| - presence_client_one.unsubscribe :leave expect(presence_message.data).to eql(data) expect(presence_client_one.members.send(:members).count).to eql(0) - expect(enter_ack).to eql(true) stop_reactor end end end end @@ -1314,13 +1288,11 @@ end # skip 'it fails if the connection changes to failed state' it 'returns the current members on the channel' do - presence_client_one.enter - presence_client_one.subscribe(:enter) do - presence_client_one.unsubscribe :enter + presence_client_one.enter do presence_client_one.get do |members| expect(members.count).to eq(1) expect(client_one.client_id).to_not be_nil @@ -1377,31 +1349,26 @@ end end end it 'does not wait for SYNC to complete if :wait_for_sync option is false' do - presence_client_one.enter - presence_client_one.subscribe(:enter) do - presence_client_one.unsubscribe :enter - + presence_client_one.enter do presence_client_two.get(wait_for_sync: false) do |members| expect(members.count).to eql(0) stop_reactor end end end context 'when a member enters and then leaves' do it 'has no members' do presence_client_one.enter do - presence_client_one.leave - end - - presence_client_one.subscribe(:leave) do - presence_client_one.get do |members| - expect(members.count).to eq(0) - stop_reactor + presence_client_one.leave do + presence_client_one.get do |members| + expect(members.count).to eq(0) + stop_reactor + end end end end end @@ -1555,14 +1522,11 @@ end end context 'REST #get' do it 'returns current members' do - presence_client_one.enter data_payload - presence_client_one.subscribe(:enter) do - presence_client_one.unsubscribe :enter - + presence_client_one.enter(data_payload) do members_page = channel_rest_client_one.presence.get this_member = members_page.items.first expect(this_member).to be_a(Ably::Models::PresenceMessage) expect(this_member.client_id).to eql(client_one.client_id) @@ -1572,14 +1536,11 @@ end end it 'returns no members once left' do presence_client_one.enter(data_payload) do - presence_client_one.leave - presence_client_one.subscribe(:leave) do - presence_client_one.unsubscribe :leave - + presence_client_one.leave do members_page = channel_rest_client_one.presence.get expect(members_page.items.count).to eql(0) stop_reactor end end @@ -1691,12 +1652,11 @@ end end context '#get' do it 'returns a list of members with decrypted data' do - encrypted_channel.presence.enter(data) - encrypted_channel.presence.subscribe(:enter) do + encrypted_channel.presence.enter(data) do encrypted_channel.presence.get do |members| member = members.first expect(member.encoding).to be_nil expect(member.data).to eql(data) stop_reactor @@ -1705,12 +1665,11 @@ end end context 'REST #get' do it 'returns a list of members with decrypted data' do - encrypted_channel.presence.enter(data) - encrypted_channel.presence.subscribe(:enter) do + encrypted_channel.presence.enter(data) do member = channel_rest_client_one.presence.get.items.first expect(member.encoding).to be_nil expect(member.data).to eql(data) stop_reactor end @@ -1777,10 +1736,10 @@ end context 'connection failure mid-way through a large member sync' do let(:members_count) { 250 } let(:sync_pages_received) { [] } - let(:client_options) { default_options.merge(log_level: :fatal) } + let(:client_options) { default_options.merge(log_level: :error) } it 'resumes the SYNC operation', em_timeout: 15 do when_all(*members_count.times.map do |index| presence_anonymous_client.enter_client("client:#{index}") end) do