ably 0.8.7 → 0.8.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +61 -3
- data/ably.gemspec +1 -1
- data/lib/ably/auth.rb +12 -3
- data/lib/ably/logger.rb +3 -1
- data/lib/ably/models/connection_details.rb +2 -1
- data/lib/ably/models/idiomatic_ruby_wrapper.rb +1 -1
- data/lib/ably/models/message.rb +4 -2
- data/lib/ably/models/message_encoders/cipher.rb +2 -2
- data/lib/ably/models/paginated_result.rb +27 -1
- data/lib/ably/models/presence_message.rb +3 -1
- data/lib/ably/models/{stat.rb → stats.rb} +5 -3
- data/lib/ably/modules/async_wrapper.rb +1 -1
- data/lib/ably/modules/channels_collection.rb +11 -1
- data/lib/ably/modules/enum.rb +18 -2
- data/lib/ably/modules/event_emitter.rb +3 -3
- data/lib/ably/modules/safe_deferrable.rb +1 -1
- data/lib/ably/modules/safe_yield.rb +2 -2
- data/lib/ably/modules/state_emitter.rb +8 -8
- data/lib/ably/modules/statesman_monkey_patch.rb +2 -2
- data/lib/ably/modules/uses_state_machine.rb +4 -2
- data/lib/ably/realtime.rb +1 -0
- data/lib/ably/realtime/auth.rb +6 -2
- data/lib/ably/realtime/channel.rb +6 -4
- data/lib/ably/realtime/channel/channel_manager.rb +7 -1
- data/lib/ably/realtime/client.rb +7 -12
- data/lib/ably/realtime/client/incoming_message_dispatcher.rb +9 -2
- data/lib/ably/realtime/client/outgoing_message_dispatcher.rb +7 -1
- data/lib/ably/realtime/connection.rb +19 -8
- data/lib/ably/realtime/connection/connection_manager.rb +16 -9
- data/lib/ably/realtime/connection/websocket_transport.rb +12 -3
- data/lib/ably/realtime/presence.rb +6 -6
- data/lib/ably/realtime/presence/members_map.rb +21 -7
- data/lib/ably/rest/channel.rb +8 -8
- data/lib/ably/rest/client.rb +1 -1
- data/lib/ably/rest/middleware/exceptions.rb +3 -1
- data/lib/ably/rest/presence.rb +4 -4
- data/lib/ably/version.rb +1 -1
- data/spec/acceptance/realtime/channel_history_spec.rb +4 -4
- data/spec/acceptance/realtime/connection_failures_spec.rb +2 -4
- data/spec/acceptance/realtime/connection_spec.rb +46 -8
- data/spec/acceptance/realtime/presence_spec.rb +49 -34
- data/spec/acceptance/rest/auth_spec.rb +1 -1
- data/spec/acceptance/rest/base_spec.rb +1 -1
- data/spec/shared/safe_deferrable_behaviour.rb +4 -4
- data/spec/unit/models/message_encoders/cipher_spec.rb +1 -1
- data/spec/unit/models/token_details_spec.rb +20 -18
- data/spec/unit/modules/event_emitter_spec.rb +2 -2
- data/spec/unit/modules/state_emitter_spec.rb +6 -6
- data/spec/unit/realtime/channel_spec.rb +4 -4
- data/spec/unit/realtime/connection_spec.rb +1 -1
- data/spec/unit/realtime/presence_spec.rb +5 -5
- metadata +5 -5
@@ -98,11 +98,20 @@ module Ably::Realtime
|
|
98
98
|
end
|
99
99
|
|
100
100
|
private
|
101
|
-
|
101
|
+
def driver
|
102
|
+
@driver
|
103
|
+
end
|
104
|
+
|
105
|
+
def connection
|
106
|
+
@connection
|
107
|
+
end
|
108
|
+
|
109
|
+
def reason_closed
|
110
|
+
@reason_closed
|
111
|
+
end
|
102
112
|
|
103
113
|
# Send object down the WebSocket driver connection as a serialized string/byte array based on protocol
|
104
114
|
# @param [Object] object to serialize and send to the WebSocket driver
|
105
|
-
# @api public
|
106
115
|
def send_object(object)
|
107
116
|
case client.protocol
|
108
117
|
when :json
|
@@ -122,7 +131,7 @@ module Ably::Realtime
|
|
122
131
|
end
|
123
132
|
|
124
133
|
def clear_timer
|
125
|
-
if @timer
|
134
|
+
if defined?(@timer) && @timer
|
126
135
|
@timer.cancel
|
127
136
|
@timer = nil
|
128
137
|
end
|
@@ -250,11 +250,11 @@ module Ably::Realtime
|
|
250
250
|
ensure_channel_attached(deferrable) do
|
251
251
|
members.get(options).tap do |members_map_deferrable|
|
252
252
|
members_map_deferrable.callback do |*args|
|
253
|
-
safe_yield
|
254
|
-
deferrable.succeed
|
253
|
+
safe_yield(block, *args) if block_given?
|
254
|
+
deferrable.succeed(*args)
|
255
255
|
end
|
256
256
|
members_map_deferrable.errback do |*args|
|
257
|
-
deferrable.fail
|
257
|
+
deferrable.fail(*args)
|
258
258
|
end
|
259
259
|
end
|
260
260
|
end
|
@@ -426,14 +426,14 @@ module Ably::Realtime
|
|
426
426
|
end
|
427
427
|
|
428
428
|
def deferrable_succeed(deferrable, *args, &block)
|
429
|
-
safe_yield
|
429
|
+
safe_yield(block, self, *args) if block_given?
|
430
430
|
EventMachine.next_tick { deferrable.succeed self, *args } # allow callback to be added to the returned Deferrable before calling succeed
|
431
431
|
deferrable
|
432
432
|
end
|
433
433
|
|
434
434
|
def deferrable_fail(deferrable, *args, &block)
|
435
|
-
safe_yield
|
436
|
-
EventMachine.next_tick { deferrable.fail
|
435
|
+
safe_yield(block, *args) if block_given?
|
436
|
+
EventMachine.next_tick { deferrable.fail(*args) } # allow errback to be added to the returned Deferrable
|
437
437
|
deferrable
|
438
438
|
end
|
439
439
|
|
@@ -99,12 +99,12 @@ module Ably::Realtime
|
|
99
99
|
end
|
100
100
|
|
101
101
|
reset_callbacks = proc do
|
102
|
-
off
|
103
|
-
off
|
104
|
-
channel.off
|
102
|
+
off(&in_sync_callback)
|
103
|
+
off(&failed_callback)
|
104
|
+
channel.off(&failed_callback)
|
105
105
|
end
|
106
106
|
|
107
|
-
once
|
107
|
+
once(:in_sync, &in_sync_callback)
|
108
108
|
|
109
109
|
once(:failed, &failed_callback)
|
110
110
|
channel.unsafe_once(:detaching, :detached, :failed) do |error_reason|
|
@@ -131,7 +131,21 @@ module Ably::Realtime
|
|
131
131
|
end
|
132
132
|
|
133
133
|
private
|
134
|
-
|
134
|
+
def members
|
135
|
+
@members
|
136
|
+
end
|
137
|
+
|
138
|
+
def sync_serial
|
139
|
+
@sync_serial
|
140
|
+
end
|
141
|
+
|
142
|
+
def presence
|
143
|
+
@presence
|
144
|
+
end
|
145
|
+
|
146
|
+
def absent_member_cleanup_queue
|
147
|
+
@absent_member_cleanup_queue
|
148
|
+
end
|
135
149
|
|
136
150
|
def channel
|
137
151
|
presence.channel
|
@@ -156,9 +170,9 @@ module Ably::Realtime
|
|
156
170
|
end
|
157
171
|
|
158
172
|
resume_sync_proc = method(:resume_sync).to_proc
|
159
|
-
connection.on_resume
|
173
|
+
connection.on_resume(&resume_sync_proc)
|
160
174
|
once(:in_sync, :failed) do
|
161
|
-
connection.off_resume
|
175
|
+
connection.off_resume(&resume_sync_proc)
|
162
176
|
end
|
163
177
|
|
164
178
|
once(:in_sync) do
|
data/lib/ably/rest/channel.rb
CHANGED
@@ -65,15 +65,15 @@ module Ably
|
|
65
65
|
end
|
66
66
|
|
67
67
|
payload = messages.map do |message|
|
68
|
-
Ably::Models::Message(message.dup).tap do |
|
69
|
-
|
68
|
+
Ably::Models::Message(message.dup).tap do |msg|
|
69
|
+
msg.encode self
|
70
70
|
|
71
|
-
next if
|
72
|
-
if
|
71
|
+
next if msg.client_id.nil?
|
72
|
+
if msg.client_id == '*'
|
73
73
|
raise Ably::Exceptions::IncompatibleClientId.new('Wildcard client_id is reserved and cannot be used when publishing messages', 400, 40012)
|
74
74
|
end
|
75
|
-
unless client.auth.can_assume_client_id?(
|
76
|
-
raise Ably::Exceptions::IncompatibleClientId.new("Cannot publish with client_id '#{
|
75
|
+
unless client.auth.can_assume_client_id?(msg.client_id)
|
76
|
+
raise Ably::Exceptions::IncompatibleClientId.new("Cannot publish with client_id '#{msg.client_id}' as it is incompatible with the current configured client_id '#{client.client_id}'", 400, 40012)
|
77
77
|
end
|
78
78
|
end.as_json
|
79
79
|
end
|
@@ -111,8 +111,8 @@ module Ably
|
|
111
111
|
response = client.get(url, options)
|
112
112
|
|
113
113
|
Ably::Models::PaginatedResult.new(response, url, client, paginated_options) do |message|
|
114
|
-
message.tap do |
|
115
|
-
decode_message
|
114
|
+
message.tap do |msg|
|
115
|
+
decode_message msg
|
116
116
|
end
|
117
117
|
end
|
118
118
|
end
|
data/lib/ably/rest/client.rb
CHANGED
@@ -315,7 +315,7 @@ module Ably
|
|
315
315
|
#
|
316
316
|
# @api private
|
317
317
|
def fallback_connection
|
318
|
-
unless @fallback_connections
|
318
|
+
unless defined?(@fallback_connections) && @fallback_connections
|
319
319
|
@fallback_connections = Ably::FALLBACK_HOSTS.shuffle.map { |host| Faraday.new(endpoint_for_host(host).to_s, connection_options) }
|
320
320
|
end
|
321
321
|
@fallback_index ||= 0
|
@@ -7,6 +7,8 @@ module Ably
|
|
7
7
|
# HTTP exceptions raised by Ably due to an error status code
|
8
8
|
# Ably returns JSON/Msgpack error codes and messages so include this if possible in the exception messages
|
9
9
|
class Exceptions < Faraday::Response::Middleware
|
10
|
+
TOKEN_EXPIRED_CODE = 40140..40149
|
11
|
+
|
10
12
|
def on_complete(env)
|
11
13
|
if env.status >= 400
|
12
14
|
error_status_code = env.status
|
@@ -30,7 +32,7 @@ module Ably
|
|
30
32
|
|
31
33
|
if env.status >= 500
|
32
34
|
raise Ably::Exceptions::ServerError.new(message, error_status_code, error_code)
|
33
|
-
elsif env.status == 401 && error_code
|
35
|
+
elsif env.status == 401 && TOKEN_EXPIRED_CODE.include?(error_code)
|
34
36
|
raise Ably::Exceptions::TokenExpired.new(message, error_status_code, error_code)
|
35
37
|
else
|
36
38
|
raise Ably::Exceptions::InvalidRequest.new(message, error_status_code, error_code)
|
data/lib/ably/rest/presence.rb
CHANGED
@@ -40,8 +40,8 @@ module Ably
|
|
40
40
|
response = client.get(base_path, options)
|
41
41
|
|
42
42
|
Ably::Models::PaginatedResult.new(response, base_path, client, paginated_options) do |presence_message|
|
43
|
-
presence_message.tap do |
|
44
|
-
decode_message
|
43
|
+
presence_message.tap do |message|
|
44
|
+
decode_message message
|
45
45
|
end
|
46
46
|
end
|
47
47
|
end
|
@@ -74,8 +74,8 @@ module Ably
|
|
74
74
|
response = client.get(url, options)
|
75
75
|
|
76
76
|
Ably::Models::PaginatedResult.new(response, url, client, paginated_options) do |presence_message|
|
77
|
-
presence_message.tap do |
|
78
|
-
decode_message
|
77
|
+
presence_message.tap do |message|
|
78
|
+
decode_message message
|
79
79
|
end
|
80
80
|
end
|
81
81
|
end
|
data/lib/ably/version.rb
CHANGED
@@ -19,7 +19,7 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
19
19
|
let(:options) { { :protocol => :json } }
|
20
20
|
|
21
21
|
it 'returns a SafeDeferrable that catches exceptions in callbacks and logs them' do
|
22
|
-
channel.publish('event', payload) do
|
22
|
+
channel.publish('event', payload) do
|
23
23
|
history = channel.history
|
24
24
|
expect(history).to be_a(Ably::Util::SafeDeferrable)
|
25
25
|
history.callback do |page|
|
@@ -32,7 +32,7 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
32
32
|
|
33
33
|
context 'with a single client publishing and receiving' do
|
34
34
|
it 'retrieves realtime history' do
|
35
|
-
channel.publish('event', payload) do
|
35
|
+
channel.publish('event', payload) do
|
36
36
|
channel.history do |page|
|
37
37
|
expect(page.items.length).to eql(1)
|
38
38
|
expect(page.items[0].data).to eql(payload)
|
@@ -44,8 +44,8 @@ describe Ably::Realtime::Channel, '#history', :event_machine do
|
|
44
44
|
|
45
45
|
context 'with two clients publishing messages on the same channel' do
|
46
46
|
it 'retrieves realtime history on both channels' do
|
47
|
-
channel.publish('event', payload) do
|
48
|
-
channel2.publish('event', payload) do
|
47
|
+
channel.publish('event', payload) do
|
48
|
+
channel2.publish('event', payload) do
|
49
49
|
channel.history do |page|
|
50
50
|
expect(page.items.length).to eql(2)
|
51
51
|
expect(page.items.map(&:data).uniq).to eql([payload])
|
@@ -481,8 +481,6 @@ describe Ably::Realtime::Connection, 'failures', :event_machine do
|
|
481
481
|
end
|
482
482
|
|
483
483
|
it 'retains channel subscription state' do
|
484
|
-
messages_received = false
|
485
|
-
|
486
484
|
channel.subscribe('event') do |message|
|
487
485
|
expect(message.data).to eql('message')
|
488
486
|
stop_reactor
|
@@ -712,6 +710,7 @@ describe Ably::Realtime::Connection, 'failures', :event_machine do
|
|
712
710
|
context 'when the Internet is up' do
|
713
711
|
before do
|
714
712
|
allow(connection).to receive(:internet_up?).and_yield(true)
|
713
|
+
@suspended = 0
|
715
714
|
end
|
716
715
|
|
717
716
|
it 'uses a fallback host on every subsequent disconnected attempt until suspended' do
|
@@ -740,14 +739,13 @@ describe Ably::Realtime::Connection, 'failures', :event_machine do
|
|
740
739
|
expect(host).to eql(expected_host)
|
741
740
|
else
|
742
741
|
expect(custom_hosts).to include(host)
|
743
|
-
fallback_hosts_used << host if @suspended
|
742
|
+
fallback_hosts_used << host if @suspended > 0
|
744
743
|
end
|
745
744
|
request += 1
|
746
745
|
raise EventMachine::ConnectionError
|
747
746
|
end
|
748
747
|
|
749
748
|
connection.on(:suspended) do
|
750
|
-
@suspended ||= 0
|
751
749
|
@suspended += 1
|
752
750
|
|
753
751
|
if @suspended > 3
|
@@ -141,7 +141,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
141
141
|
started_at = Time.now.to_f
|
142
142
|
connection.once(:disconnected) do
|
143
143
|
connection.once(:disconnected) do |connection_state_change|
|
144
|
-
expect(connection_state_change.reason.code).to eql(
|
144
|
+
expect(connection_state_change.reason.code).to eql(40142) # token expired
|
145
145
|
expect(Time.now.to_f - started_at).to be < 1000
|
146
146
|
expect(auth_requests.count).to eql(2)
|
147
147
|
stop_reactor
|
@@ -156,7 +156,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
156
156
|
started_at = Time.now.to_f
|
157
157
|
disconnect_count = 0
|
158
158
|
connection.on(:disconnected) do |connection_state_change|
|
159
|
-
expect(connection_state_change.reason.code).to eql(
|
159
|
+
expect(connection_state_change.reason.code).to eql(40142) # token expired
|
160
160
|
disconnect_count += 1
|
161
161
|
if disconnect_count == 6
|
162
162
|
expect(Time.now.to_f - started_at).to be > 4 * 0.5 # at least 4 0.5 second pauses should have happened
|
@@ -207,7 +207,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
207
207
|
expect(original_token).to_not be_expired
|
208
208
|
started_at = Time.now
|
209
209
|
connection.once(:disconnected) do |connection_state_change|
|
210
|
-
expect(connection_state_change.reason.code).to eq(
|
210
|
+
expect(connection_state_change.reason.code).to eq(40142) # Token expired
|
211
211
|
|
212
212
|
# Token has expired, so now ensure it is not used again
|
213
213
|
stub_const 'Ably::Models::TokenDetails::TOKEN_EXPIRY_BUFFER', original_token_expiry_buffer
|
@@ -333,7 +333,7 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
333
333
|
expect(expired_token_details).to be_expired
|
334
334
|
connection.once(:connected) { raise 'Connection should never connect as token has expired' }
|
335
335
|
connection.once(:failed) do
|
336
|
-
expect(client.connection.error_reason.code).to eql(
|
336
|
+
expect(client.connection.error_reason.code).to eql(40142)
|
337
337
|
stop_reactor
|
338
338
|
end
|
339
339
|
end
|
@@ -800,6 +800,41 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
800
800
|
end
|
801
801
|
end
|
802
802
|
|
803
|
+
context '#details' do
|
804
|
+
let(:connection) { client.connection }
|
805
|
+
|
806
|
+
it 'is nil before connected' do
|
807
|
+
connection.on(:connecting) do
|
808
|
+
expect(connection.details).to eql(nil)
|
809
|
+
stop_reactor
|
810
|
+
end
|
811
|
+
end
|
812
|
+
|
813
|
+
it 'contains the ConnectionDetails object once connected' do
|
814
|
+
connection.on(:connected) do
|
815
|
+
expect(connection.details).to be_a(Ably::Models::ConnectionDetails)
|
816
|
+
expect(connection.details.connection_key).to_not be_nil
|
817
|
+
expect(connection.details.server_id).to_not be_nil
|
818
|
+
stop_reactor
|
819
|
+
end
|
820
|
+
end
|
821
|
+
|
822
|
+
it 'contains the new ConnectionDetails object once a subsequent connection is created' do
|
823
|
+
connection.once(:connected) do
|
824
|
+
expect(connection.details.connection_key).to_not be_nil
|
825
|
+
old_key = connection.details.connection_key
|
826
|
+
connection.close do
|
827
|
+
connection.once(:connected) do
|
828
|
+
expect(connection.details.connection_key).to_not be_nil
|
829
|
+
expect(connection.details.connection_key).to_not eql(old_key)
|
830
|
+
stop_reactor
|
831
|
+
end
|
832
|
+
connection.connect
|
833
|
+
end
|
834
|
+
end
|
835
|
+
end
|
836
|
+
end
|
837
|
+
|
803
838
|
context 'recovery' do
|
804
839
|
let(:channel_name) { random_str }
|
805
840
|
let(:channel) { client.channel(channel_name) }
|
@@ -813,7 +848,8 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
813
848
|
log_level: :none,
|
814
849
|
disconnected_retry_timeout: 0.1,
|
815
850
|
suspended_retry_timeout: 0.1,
|
816
|
-
connection_state_ttl: 0.2
|
851
|
+
connection_state_ttl: 0.2,
|
852
|
+
realtime_request_timeout: 5
|
817
853
|
)
|
818
854
|
end
|
819
855
|
|
@@ -889,7 +925,8 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
889
925
|
|
890
926
|
context "opening a new connection using a recently disconnected connection's #recovery_key" do
|
891
927
|
context 'connection#id and connection#key after recovery' do
|
892
|
-
it 'remains the same' do
|
928
|
+
it 'remains the same for id and party for key' do
|
929
|
+
connection_key_consistent_part_regex = /.*?!(\w{5,})-/
|
893
930
|
previous_connection_id = nil
|
894
931
|
previous_connection_key = nil
|
895
932
|
|
@@ -902,8 +939,9 @@ describe Ably::Realtime::Connection, :event_machine do
|
|
902
939
|
connection.once(:failed) do
|
903
940
|
recover_client = auto_close Ably::Realtime::Client.new(default_options.merge(recover: client.connection.recovery_key))
|
904
941
|
recover_client.connection.on(:connected) do
|
905
|
-
expect(recover_client.connection.key[
|
906
|
-
expect(recover_client.connection.key[
|
942
|
+
expect(recover_client.connection.key[connection_key_consistent_part_regex, 1]).to_not be_nil
|
943
|
+
expect(recover_client.connection.key[connection_key_consistent_part_regex, 1]).to eql(
|
944
|
+
previous_connection_key[connection_key_consistent_part_regex, 1])
|
907
945
|
expect(recover_client.connection.id).to eql(previous_connection_id)
|
908
946
|
stop_reactor
|
909
947
|
end
|
@@ -509,7 +509,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
509
509
|
end
|
510
510
|
|
511
511
|
context '250 existing (present) members on a channel (3 SYNC pages)' do
|
512
|
-
context 'requires at least 3 SYNC ProtocolMessages' do
|
512
|
+
context 'requires at least 3 SYNC ProtocolMessages', em_timeout: 30 do
|
513
513
|
let(:enter_expected_count) { 250 }
|
514
514
|
let(:present) { [] }
|
515
515
|
let(:entered) { [] }
|
@@ -518,15 +518,18 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
518
518
|
|
519
519
|
def setup_members_on(presence)
|
520
520
|
enter_expected_count.times do |index|
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
521
|
+
# 10 messages per second max rate on simulation accounts
|
522
|
+
EventMachine.add_timer(index / 10) do
|
523
|
+
presence.enter_client("client:#{index}") do |message|
|
524
|
+
entered << message
|
525
|
+
next unless entered.count == enter_expected_count
|
526
|
+
yield
|
527
|
+
end
|
525
528
|
end
|
526
529
|
end
|
527
530
|
end
|
528
531
|
|
529
|
-
context 'when a client attaches to the presence channel'
|
532
|
+
context 'when a client attaches to the presence channel' do
|
530
533
|
it 'emits :present for each member' do
|
531
534
|
setup_members_on(presence_client_one) do
|
532
535
|
presence_anonymous_client.subscribe(:present) do |present_message|
|
@@ -676,14 +679,16 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
676
679
|
context 'with :wait_for_sync option set to true' do
|
677
680
|
it 'waits until sync is complete', em_timeout: 15 do
|
678
681
|
enter_expected_count.times do |index|
|
679
|
-
|
680
|
-
|
681
|
-
|
682
|
-
|
683
|
-
|
684
|
-
|
685
|
-
|
686
|
-
|
682
|
+
EventMachine.add_timer(index / 10) do
|
683
|
+
presence_client_one.enter_client("client:#{index}") do |message|
|
684
|
+
entered << message
|
685
|
+
next unless entered.count == enter_expected_count
|
686
|
+
|
687
|
+
presence_anonymous_client.get(wait_for_sync: true) do |members|
|
688
|
+
expect(members.map(&:client_id).uniq.count).to eql(enter_expected_count)
|
689
|
+
expect(members.count).to eql(enter_expected_count)
|
690
|
+
stop_reactor
|
691
|
+
end
|
687
692
|
end
|
688
693
|
end
|
689
694
|
end
|
@@ -693,15 +698,17 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
693
698
|
context 'by default' do
|
694
699
|
it 'it does not wait for sync', em_timeout: 15 do
|
695
700
|
enter_expected_count.times do |index|
|
696
|
-
|
697
|
-
|
698
|
-
|
699
|
-
|
700
|
-
|
701
|
-
|
702
|
-
|
703
|
-
|
704
|
-
|
701
|
+
EventMachine.add_timer(index / 10) do
|
702
|
+
presence_client_one.enter_client("client:#{index}") do |message|
|
703
|
+
entered << message
|
704
|
+
next unless entered.count == enter_expected_count
|
705
|
+
|
706
|
+
channel_anonymous_client.attach do
|
707
|
+
presence_anonymous_client.get do |members|
|
708
|
+
expect(presence_anonymous_client.members).to_not be_in_sync
|
709
|
+
expect(members.count).to eql(0)
|
710
|
+
stop_reactor
|
711
|
+
end
|
705
712
|
end
|
706
713
|
end
|
707
714
|
end
|
@@ -1225,7 +1232,7 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1225
1232
|
end
|
1226
1233
|
end
|
1227
1234
|
|
1228
|
-
context 'during a sync' do
|
1235
|
+
context 'during a sync', em_timeout: 30 do
|
1229
1236
|
let(:pages) { 2 }
|
1230
1237
|
let(:members_per_page) { 100 }
|
1231
1238
|
let(:sync_pages_received) { [] }
|
@@ -1234,7 +1241,15 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1234
1241
|
|
1235
1242
|
def connect_members_deferrables
|
1236
1243
|
(members_per_page * pages + 1).times.map do |index|
|
1237
|
-
|
1244
|
+
# rate limit to 10 per second
|
1245
|
+
EventMachine::DefaultDeferrable.new.tap do |deferrable|
|
1246
|
+
EventMachine.add_timer(index / 10) do
|
1247
|
+
presence_client_one.enter_client("client:#{index}").tap do |enter_deferrable|
|
1248
|
+
enter_deferrable.callback { |*args| deferrable.succeed *args }
|
1249
|
+
enter_deferrable.errback { |*args| deferrable.fail *args }
|
1250
|
+
end
|
1251
|
+
end
|
1252
|
+
end
|
1238
1253
|
end
|
1239
1254
|
end
|
1240
1255
|
|
@@ -1316,9 +1331,9 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1316
1331
|
expect(members.count).to eq(1)
|
1317
1332
|
expect(members.first.connection_id).to eql(client_one.connection.id)
|
1318
1333
|
|
1319
|
-
presence_client_one.get(connection_id: client_two.connection.id) do |
|
1320
|
-
expect(
|
1321
|
-
expect(
|
1334
|
+
presence_client_one.get(connection_id: client_two.connection.id) do |members_two|
|
1335
|
+
expect(members_two.count).to eq(1)
|
1336
|
+
expect(members_two.first.connection_id).to eql(client_two.connection.id)
|
1322
1337
|
stop_reactor
|
1323
1338
|
end
|
1324
1339
|
end
|
@@ -1339,10 +1354,10 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1339
1354
|
expect(members.first.client_id).to eql(client_one_id)
|
1340
1355
|
expect(members.first.connection_id).to eql(client_one.connection.id)
|
1341
1356
|
|
1342
|
-
presence_client_one.get(client_id: client_two_id) do |
|
1343
|
-
expect(
|
1344
|
-
expect(
|
1345
|
-
expect(
|
1357
|
+
presence_client_one.get(client_id: client_two_id) do |members_two|
|
1358
|
+
expect(members_two.count).to eq(1)
|
1359
|
+
expect(members_two.first.client_id).to eql(client_two_id)
|
1360
|
+
expect(members_two.first.connection_id).to eql(client_two.connection.id)
|
1346
1361
|
stop_reactor
|
1347
1362
|
end
|
1348
1363
|
end
|
@@ -1469,8 +1484,8 @@ describe Ably::Realtime::Presence, :event_machine do
|
|
1469
1484
|
it 'removes the callback for all presence events' do
|
1470
1485
|
when_all(channel_client_one.attach, channel_client_two.attach) do
|
1471
1486
|
subscribe_callback = proc { raise 'Should not be called' }
|
1472
|
-
presence_client_two.subscribe
|
1473
|
-
presence_client_two.unsubscribe
|
1487
|
+
presence_client_two.subscribe(&subscribe_callback)
|
1488
|
+
presence_client_two.unsubscribe(&subscribe_callback)
|
1474
1489
|
|
1475
1490
|
presence_client_one.enter
|
1476
1491
|
presence_client_one.update
|