Skip to content

Commit

Permalink
Fixed presence get tests, added code to wait till connected
Browse files Browse the repository at this point in the history
  • Loading branch information
sacOO7 committed Jun 14, 2024
1 parent e7b7689 commit ea9bc6e
Showing 1 changed file with 31 additions and 27 deletions.
58 changes: 31 additions & 27 deletions spec/acceptance/realtime/presence_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1589,14 +1589,16 @@ def setup_members_on(presence)
end

it 'fails if the connection is DETACHED (#RTP11b)' do
channel_client_one.attach do
channel_client_one.detach do
presence_client_one.get.tap do |deferrable|
deferrable.callback { raise 'Get should not succeed' }
deferrable.errback do |error|
expect(error).to be_a(Ably::Exceptions::InvalidState)
expect(error.message).to match(/Operation is not allowed when channel is in STATE.Detached/)
stop_reactor
client_one.connection.on :connected do
channel_client_one.attach do
channel_client_one.detach do
presence_client_one.get.tap do |deferrable|
deferrable.callback { raise 'Get should not succeed' }
deferrable.errback do |error|
expect(error).to be_a(Ably::Exceptions::InvalidState)
expect(error.message).to match(/Operation is not allowed when channel is in STATE.Detached/)
stop_reactor
end
end
end
end
Expand Down Expand Up @@ -1812,29 +1814,31 @@ def connect_members_deferrables
let(:total_members) { members_per_client * 2 }

it 'returns a complete list of members on all clients' do
members_per_client.times do |indx|
presence_client_one.enter_client("client_1:#{indx}")
presence_client_two.enter_client("client_2:#{indx}")
end
wait_until(lambda { client_one.connection.state == :connected and client_two.connection.state == :connected }) do
presence_client_one.subscribe(:enter) do
clients_entered[:client_one] += 1
end

presence_client_one.subscribe(:enter) do
clients_entered[:client_one] += 1
end
presence_client_two.subscribe(:enter) do
clients_entered[:client_two] += 1
end

presence_client_two.subscribe(:enter) do
clients_entered[:client_two] += 1
end
members_per_client.times do |indx|
presence_client_one.enter_client("client_1:#{indx}")
presence_client_two.enter_client("client_2:#{indx}")
end

wait_until(lambda { clients_entered[:client_one] + clients_entered[:client_two] == total_members * 2 }) do
presence_anonymous_client.get(wait_for_sync: true) do |anonymous_members|
expect(anonymous_members.count).to eq(total_members)
expect(anonymous_members.map(&:client_id).uniq.count).to eq(total_members)
wait_until(lambda { clients_entered[:client_one] + clients_entered[:client_two] == total_members * 2 }) do
presence_anonymous_client.get(wait_for_sync: true) do |anonymous_members|
expect(anonymous_members.count).to eq(total_members)
expect(anonymous_members.map(&:client_id).uniq.count).to eq(total_members)

presence_client_one.get(wait_for_sync: true) do |client_one_members|
presence_client_two.get(wait_for_sync: true) do |client_two_members|
expect(client_one_members.count).to eq(total_members)
expect(client_one_members.count).to eq(client_two_members.count)
stop_reactor
presence_client_one.get(wait_for_sync: true) do |client_one_members|
presence_client_two.get(wait_for_sync: true) do |client_two_members|
expect(client_one_members.count).to eq(total_members)
expect(client_one_members.count).to eq(client_two_members.count)
stop_reactor
end
end
end
end
Expand Down

0 comments on commit ea9bc6e

Please sign in to comment.