ably 1.1.6 → 1.1.7
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/.github/workflows/check.yml +15 -1
- data/CHANGELOG.md +26 -0
- data/README.md +14 -2
- data/ably.gemspec +11 -6
- data/lib/ably.rb +1 -0
- data/lib/ably/agent.rb +3 -0
- data/lib/ably/exceptions.rb +6 -0
- data/lib/ably/models/connection_details.rb +2 -0
- data/lib/ably/models/message.rb +14 -0
- data/lib/ably/models/presence_message.rb +14 -0
- data/lib/ably/models/protocol_message.rb +8 -0
- data/lib/ably/realtime/channel/channel_manager.rb +2 -2
- data/lib/ably/realtime/channel/publisher.rb +5 -0
- data/lib/ably/realtime/client/incoming_message_dispatcher.rb +14 -6
- data/lib/ably/realtime/connection.rb +5 -2
- data/lib/ably/rest/channel.rb +8 -1
- data/lib/ably/rest/client.rb +11 -11
- data/lib/ably/version.rb +1 -13
- data/spec/acceptance/realtime/auth_spec.rb +1 -1
- data/spec/acceptance/realtime/channel_history_spec.rb +25 -0
- data/spec/acceptance/realtime/channel_spec.rb +14 -0
- data/spec/acceptance/realtime/connection_failures_spec.rb +3 -1
- data/spec/acceptance/realtime/connection_spec.rb +6 -27
- data/spec/acceptance/realtime/presence_history_spec.rb +3 -1
- data/spec/acceptance/realtime/presence_spec.rb +13 -158
- data/spec/acceptance/rest/channel_spec.rb +13 -0
- data/spec/acceptance/rest/client_spec.rb +23 -19
- data/spec/shared/model_behaviour.rb +1 -1
- data/spec/spec_helper.rb +11 -2
- data/spec/unit/models/message_spec.rb +59 -0
- data/spec/unit/models/presence_message_spec.rb +49 -0
- data/spec/unit/models/protocol_message_spec.rb +48 -0
- data/spec/unit/realtime/channel_spec.rb +1 -1
- data/spec/unit/realtime/incoming_message_dispatcher_spec.rb +38 -0
- data/spec/unit/rest/channel_spec.rb +10 -0
- data/spec/unit/rest/client_spec.rb +20 -0
- metadata +36 -21
@@ -19,7 +19,7 @@ shared_examples 'a model' do |shared_options = {}|
|
|
19
19
|
end
|
20
20
|
|
21
21
|
context '#attributes', :api_private do
|
22
|
-
let(:model_options) { { action: 5 } }
|
22
|
+
let(:model_options) { { action: 5, max_message_size: 65536, max_frame_size: 524288 } }
|
23
23
|
|
24
24
|
it 'provides access to #attributes' do
|
25
25
|
expect(model.attributes).to eq(model_options)
|
data/spec/spec_helper.rb
CHANGED
@@ -5,8 +5,17 @@ def console(message)
|
|
5
5
|
end
|
6
6
|
|
7
7
|
unless RUBY_VERSION.match(/^1\./)
|
8
|
-
require '
|
9
|
-
|
8
|
+
require 'simplecov'
|
9
|
+
|
10
|
+
SimpleCov.start do
|
11
|
+
require 'simplecov-lcov'
|
12
|
+
SimpleCov::Formatter::LcovFormatter.config do |c|
|
13
|
+
c.report_with_single_file = true
|
14
|
+
c.single_report_path = 'coverage/lcov.info'
|
15
|
+
end
|
16
|
+
formatter SimpleCov::Formatter::LcovFormatter
|
17
|
+
add_filter %w[vendor spec]
|
18
|
+
end
|
10
19
|
end
|
11
20
|
|
12
21
|
require 'webmock/rspec'
|
@@ -211,6 +211,65 @@ describe Ably::Models::Message do
|
|
211
211
|
end
|
212
212
|
end
|
213
213
|
|
214
|
+
describe '#size' do
|
215
|
+
let(:model) { subject.new({ name: name, data: data, client_id: client_id, extras: extras }, protocol_message: protocol_message) }
|
216
|
+
|
217
|
+
context 'String (#TO3l8a)' do
|
218
|
+
let(:data) { 'example string data' }
|
219
|
+
let(:client_id) { '1' }
|
220
|
+
let(:name) { 'My Name' }
|
221
|
+
let(:extras) { 'extras' }
|
222
|
+
|
223
|
+
it 'should return 33 bytes' do
|
224
|
+
expect(model.size).to eq(33)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
context 'Object (#TO3l8b)' do
|
229
|
+
let(:data) { Object.new }
|
230
|
+
let(:client_id) { String('10') }
|
231
|
+
let(:name) { 'John' }
|
232
|
+
let(:extras) { Hash.new }
|
233
|
+
|
234
|
+
it 'should return 38 bytes' do
|
235
|
+
expect(model.size).to eq(38)
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
context 'Array (#TO3l8b)' do
|
240
|
+
let(:data) { [1, 'two', :three] }
|
241
|
+
let(:client_id) { '2' }
|
242
|
+
let(:name) { 'Kate' }
|
243
|
+
let(:extras) { [] }
|
244
|
+
|
245
|
+
it 'should return 24 bytes' do
|
246
|
+
expect(model.size).to eq(24)
|
247
|
+
end
|
248
|
+
end
|
249
|
+
|
250
|
+
context 'extras (#TO3l8d)' do
|
251
|
+
let(:data) { { example: 'value', score: 1, hash: { test: true } } }
|
252
|
+
let(:client_id) { '3' }
|
253
|
+
let(:name) { 'John' }
|
254
|
+
let(:extras) { {} }
|
255
|
+
|
256
|
+
it 'should return 57 bytes' do
|
257
|
+
expect(model.size).to eq(57)
|
258
|
+
end
|
259
|
+
end
|
260
|
+
|
261
|
+
context 'nil (#TO3l8e)' do
|
262
|
+
let(:data) { nil }
|
263
|
+
let(:client_id) { '' }
|
264
|
+
let(:name) { '' }
|
265
|
+
let(:extras) { nil}
|
266
|
+
|
267
|
+
it 'should return 19 bytes' do
|
268
|
+
expect(model.size).to eq(0)
|
269
|
+
end
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
214
273
|
context 'from REST request with embedded fields', :api_private do
|
215
274
|
let(:id) { random_str }
|
216
275
|
let(:protocol_message_id) { random_str }
|
@@ -220,6 +220,55 @@ describe Ably::Models::PresenceMessage do
|
|
220
220
|
end
|
221
221
|
end
|
222
222
|
|
223
|
+
describe '#size' do
|
224
|
+
let(:model) { subject.new({ action: 'enter', data: data, client_id: client_id }, protocol_message: protocol_message) }
|
225
|
+
|
226
|
+
context 'String (#TO3l8a)' do
|
227
|
+
let(:data) { 'example string data' }
|
228
|
+
let(:client_id) { '1' }
|
229
|
+
|
230
|
+
it 'should return 20 bytes' do
|
231
|
+
expect(model.size).to eq(20)
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
235
|
+
context 'Object (#TO3l8b)' do
|
236
|
+
let(:data) { Object.new }
|
237
|
+
let(:client_id) { '10' }
|
238
|
+
|
239
|
+
it 'should return 32 bytes' do
|
240
|
+
expect(model.size).to eq(32)
|
241
|
+
end
|
242
|
+
end
|
243
|
+
|
244
|
+
context 'Array (#TO3l8b)' do
|
245
|
+
let(:data) { [1, 'two', :three] }
|
246
|
+
let(:client_id) { '2' }
|
247
|
+
|
248
|
+
it 'should return 18 bytes' do
|
249
|
+
expect(model.size).to eq(18)
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
context 'extras (#TO3l8d)' do
|
254
|
+
let(:data) { { example: 'value', score: 1, hash: { test: true } } }
|
255
|
+
let(:client_id) { '3' }
|
256
|
+
|
257
|
+
it 'should return 51 bytes' do
|
258
|
+
expect(model.size).to eq(51)
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'nil (#TO3l8e)' do
|
263
|
+
let(:data) { nil }
|
264
|
+
let(:client_id) { '4' }
|
265
|
+
|
266
|
+
it 'should return 1 bytes' do
|
267
|
+
expect(model.size).to eq(1)
|
268
|
+
end
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
223
272
|
context 'from REST request with embedded fields', :api_private do
|
224
273
|
let(:id) { random_str }
|
225
274
|
let(:message_time) { Time.now + 60 }
|
@@ -318,6 +318,54 @@ describe Ably::Models::ProtocolMessage do
|
|
318
318
|
end
|
319
319
|
end
|
320
320
|
|
321
|
+
context '#message_size (#TO3l8)' do
|
322
|
+
context 'on presence' do
|
323
|
+
let(:protocol_message) do
|
324
|
+
new_protocol_message(presence: [{ action: 1, data: 'test342343', client_id: 'sdf' }])
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'should return 13 bytes (sum in bytes: data and client_id)' do
|
328
|
+
expect(protocol_message.message_size).to eq(13)
|
329
|
+
end
|
330
|
+
end
|
331
|
+
|
332
|
+
context 'on message' do
|
333
|
+
let(:protocol_message) do
|
334
|
+
new_protocol_message(messages: [{ action: 1, unknown: 'test', data: 'test342343', client_id: 'sdf', name: 'sf23ewrew', extras: { time: Time.now, time_zone: 'UTC' } }])
|
335
|
+
end
|
336
|
+
|
337
|
+
it 'should return 76 bytes (sum in bytes: data, client_id, name, extras)' do
|
338
|
+
expect(protocol_message.message_size).to eq(76)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
context '#has_correct_message_size? (#TO3l8)' do
|
344
|
+
context 'on presence' do
|
345
|
+
it 'should return true when a message has correct size' do
|
346
|
+
protocol_message = new_protocol_message(presence: [{ action: 1, data: 'x' * 100 }])
|
347
|
+
expect(protocol_message.has_correct_message_size?).to eq(true)
|
348
|
+
end
|
349
|
+
|
350
|
+
it 'should return false when a message has not correct size' do
|
351
|
+
protocol_message = new_protocol_message(presence: [{ action: 1, data: 'x' * 65537 }])
|
352
|
+
expect(protocol_message.has_correct_message_size?).to eq(false)
|
353
|
+
end
|
354
|
+
end
|
355
|
+
|
356
|
+
context 'on message' do
|
357
|
+
it 'should return true when a message has correct size' do
|
358
|
+
protocol_message = new_protocol_message(messages: [{ name: 'x' * 100 }])
|
359
|
+
expect(protocol_message.has_correct_message_size?).to eq(true)
|
360
|
+
end
|
361
|
+
|
362
|
+
it 'should return false when a message has not correct size' do
|
363
|
+
protocol_message = new_protocol_message(messages: [{ name: 'x' * 65537 }])
|
364
|
+
expect(protocol_message.has_correct_message_size?).to eq(false)
|
365
|
+
end
|
366
|
+
end
|
367
|
+
end
|
368
|
+
|
321
369
|
context '#connection_details (#TR4o)' do
|
322
370
|
let(:connection_details) { protocol_message.connection_details }
|
323
371
|
|
@@ -68,7 +68,7 @@ describe Ably::Realtime::Channel do
|
|
68
68
|
|
69
69
|
describe '#publish name argument' do
|
70
70
|
let(:encoded_value) { random_str.encode(encoding) }
|
71
|
-
let(:message) { instance_double('Ably::Models::Message', client_id: nil) }
|
71
|
+
let(:message) { instance_double('Ably::Models::Message', client_id: nil, size: 0) }
|
72
72
|
|
73
73
|
before do
|
74
74
|
allow(subject).to receive(:create_message).and_return(message)
|
@@ -32,5 +32,43 @@ describe Ably::Realtime::Client::IncomingMessageDispatcher, :api_private do
|
|
32
32
|
expect(subject).to receive_message_chain(:logger, :warn)
|
33
33
|
msgbus.publish :protocol_message, Ably::Models::ProtocolMessage.new(:action => :attached, channel: 'unknown')
|
34
34
|
end
|
35
|
+
|
36
|
+
context 'TO3l8' do
|
37
|
+
context 'on action presence' do
|
38
|
+
let(:presence) { 101.times.map { { data: 'x' * 655 } } }
|
39
|
+
|
40
|
+
let(:protocol_message) do
|
41
|
+
Ably::Models::ProtocolMessage.new(action: :presence, channel: 'default', presence: presence, connection_serial: 123123123)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should raise a protocol error when message size exceeded 65536 bytes' do
|
45
|
+
allow(connection).to receive(:serial).and_return(12312312)
|
46
|
+
allow(subject).to receive(:update_connection_recovery_info)
|
47
|
+
allow(subject).to receive_message_chain(:logger, :debug)
|
48
|
+
allow(subject).to receive_message_chain(:logger, :warn)
|
49
|
+
expect(subject).to receive_message_chain(:logger, :fatal)
|
50
|
+
|
51
|
+
msgbus.publish :protocol_message, protocol_message
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
context 'on action message' do
|
56
|
+
let(:messages) { 101.times.map { { data: 'x' * 655 } } }
|
57
|
+
|
58
|
+
let(:protocol_message) do
|
59
|
+
Ably::Models::ProtocolMessage.new(action: :message, channel: 'default', messages: messages, connection_serial: 123123123)
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'should raise a protocol error when message size exceeded 65536 bytes' do
|
63
|
+
allow(connection).to receive(:serial).and_return(12312312)
|
64
|
+
allow(subject).to receive(:update_connection_recovery_info)
|
65
|
+
allow(subject).to receive_message_chain(:logger, :debug)
|
66
|
+
allow(subject).to receive_message_chain(:logger, :warn)
|
67
|
+
expect(subject).to receive_message_chain(:logger, :fatal)
|
68
|
+
|
69
|
+
msgbus.publish :protocol_message, protocol_message
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
35
73
|
end
|
36
74
|
end
|
@@ -14,6 +14,10 @@ describe Ably::Rest::Channel do
|
|
14
14
|
|
15
15
|
subject { Ably::Rest::Channel.new(client, channel_name) }
|
16
16
|
|
17
|
+
it 'should return Ably::Rest::Channel::MAX_MESSAGE_SIZE equal 65536 (TO3l8)' do
|
18
|
+
expect(Ably::Rest::Channel::MAX_MESSAGE_SIZE).to eq(65536)
|
19
|
+
end
|
20
|
+
|
17
21
|
describe '#initializer' do
|
18
22
|
let(:channel_name) { random_str.encode(encoding) }
|
19
23
|
|
@@ -126,5 +130,11 @@ describe Ably::Rest::Channel do
|
|
126
130
|
expect { subject.publish(encoded_value, 'data') }.to raise_error ArgumentError, /must be a String/
|
127
131
|
end
|
128
132
|
end
|
133
|
+
|
134
|
+
context 'max message size exceeded' do
|
135
|
+
it 'should raise Ably::Exceptions::MaxMessageSizeExceeded' do
|
136
|
+
expect { subject.publish('x' * 65537, 'data') }.to raise_error Ably::Exceptions::MaxMessageSizeExceeded
|
137
|
+
end
|
138
|
+
end
|
129
139
|
end
|
130
140
|
end
|
@@ -38,6 +38,26 @@ describe Ably::Rest::Client do
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
+
context 'use agent' do
|
42
|
+
context 'set agent to non-default value' do
|
43
|
+
context 'default agent' do
|
44
|
+
let(:client_options) { { key: 'appid.keyuid:keysecret' } }
|
45
|
+
|
46
|
+
it 'should return default ably agent' do
|
47
|
+
expect(subject.agent).to eq(Ably::AGENT)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context 'custom agent' do
|
52
|
+
let(:client_options) { { key: 'appid.keyuid:keysecret', agent: 'example-gem/1.1.4 ably-ruby/1.1.5 ruby/3.0.0' } }
|
53
|
+
|
54
|
+
it 'should overwrite client.agent' do
|
55
|
+
expect(subject.agent).to eq('example-gem/1.1.4 ably-ruby/1.1.5 ruby/3.0.0')
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
41
61
|
context ':use_token_auth' do
|
42
62
|
context 'set to false' do
|
43
63
|
context 'with a key and :tls => false' do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ably
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.
|
4
|
+
version: 1.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Lewis Marshall
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2021-
|
12
|
+
date: 2021-08-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: eventmachine
|
@@ -45,14 +45,14 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - "~>"
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
version: '
|
48
|
+
version: '8.0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
53
|
- - "~>"
|
54
54
|
- !ruby/object:Gem::Version
|
55
|
-
version: '
|
55
|
+
version: '8.0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: faraday
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
@@ -143,14 +143,14 @@ dependencies:
|
|
143
143
|
requirements:
|
144
144
|
- - "~>"
|
145
145
|
- !ruby/object:Gem::Version
|
146
|
-
version: '
|
146
|
+
version: '13.0'
|
147
147
|
type: :development
|
148
148
|
prerelease: false
|
149
149
|
version_requirements: !ruby/object:Gem::Requirement
|
150
150
|
requirements:
|
151
151
|
- - "~>"
|
152
152
|
- !ruby/object:Gem::Version
|
153
|
-
version: '
|
153
|
+
version: '13.0'
|
154
154
|
- !ruby/object:Gem::Dependency
|
155
155
|
name: redcarpet
|
156
156
|
requirement: !ruby/object:Gem::Requirement
|
@@ -250,61 +250,75 @@ dependencies:
|
|
250
250
|
- !ruby/object:Gem::Version
|
251
251
|
version: '3.11'
|
252
252
|
- !ruby/object:Gem::Dependency
|
253
|
-
name:
|
253
|
+
name: simplecov
|
254
254
|
requirement: !ruby/object:Gem::Requirement
|
255
255
|
requirements:
|
256
|
-
- - "
|
256
|
+
- - "~>"
|
257
257
|
- !ruby/object:Gem::Version
|
258
|
-
version:
|
258
|
+
version: 0.21.2
|
259
259
|
type: :development
|
260
260
|
prerelease: false
|
261
261
|
version_requirements: !ruby/object:Gem::Requirement
|
262
262
|
requirements:
|
263
|
-
- - "
|
263
|
+
- - "~>"
|
264
264
|
- !ruby/object:Gem::Version
|
265
|
-
version:
|
265
|
+
version: 0.21.2
|
266
|
+
- !ruby/object:Gem::Dependency
|
267
|
+
name: simplecov-lcov
|
268
|
+
requirement: !ruby/object:Gem::Requirement
|
269
|
+
requirements:
|
270
|
+
- - "~>"
|
271
|
+
- !ruby/object:Gem::Version
|
272
|
+
version: 0.8.0
|
273
|
+
type: :development
|
274
|
+
prerelease: false
|
275
|
+
version_requirements: !ruby/object:Gem::Requirement
|
276
|
+
requirements:
|
277
|
+
- - "~>"
|
278
|
+
- !ruby/object:Gem::Version
|
279
|
+
version: 0.8.0
|
266
280
|
- !ruby/object:Gem::Dependency
|
267
281
|
name: parallel_tests
|
268
282
|
requirement: !ruby/object:Gem::Requirement
|
269
283
|
requirements:
|
270
284
|
- - "~>"
|
271
285
|
- !ruby/object:Gem::Version
|
272
|
-
version: '
|
286
|
+
version: '3.7'
|
273
287
|
type: :development
|
274
288
|
prerelease: false
|
275
289
|
version_requirements: !ruby/object:Gem::Requirement
|
276
290
|
requirements:
|
277
291
|
- - "~>"
|
278
292
|
- !ruby/object:Gem::Version
|
279
|
-
version: '
|
293
|
+
version: '3.7'
|
280
294
|
- !ruby/object:Gem::Dependency
|
281
295
|
name: pry
|
282
296
|
requirement: !ruby/object:Gem::Requirement
|
283
297
|
requirements:
|
284
|
-
- - "
|
298
|
+
- - "~>"
|
285
299
|
- !ruby/object:Gem::Version
|
286
|
-
version:
|
300
|
+
version: 0.14.1
|
287
301
|
type: :development
|
288
302
|
prerelease: false
|
289
303
|
version_requirements: !ruby/object:Gem::Requirement
|
290
304
|
requirements:
|
291
|
-
- - "
|
305
|
+
- - "~>"
|
292
306
|
- !ruby/object:Gem::Version
|
293
|
-
version:
|
307
|
+
version: 0.14.1
|
294
308
|
- !ruby/object:Gem::Dependency
|
295
309
|
name: pry-byebug
|
296
310
|
requirement: !ruby/object:Gem::Requirement
|
297
311
|
requirements:
|
298
|
-
- - "
|
312
|
+
- - "~>"
|
299
313
|
- !ruby/object:Gem::Version
|
300
|
-
version:
|
314
|
+
version: 3.8.0
|
301
315
|
type: :development
|
302
316
|
prerelease: false
|
303
317
|
version_requirements: !ruby/object:Gem::Requirement
|
304
318
|
requirements:
|
305
|
-
- - "
|
319
|
+
- - "~>"
|
306
320
|
- !ruby/object:Gem::Version
|
307
|
-
version:
|
321
|
+
version: 3.8.0
|
308
322
|
description: A Ruby client library for ably.io realtime messaging
|
309
323
|
email:
|
310
324
|
- lewis@lmars.net
|
@@ -328,6 +342,7 @@ files:
|
|
328
342
|
- SPEC.md
|
329
343
|
- ably.gemspec
|
330
344
|
- lib/ably.rb
|
345
|
+
- lib/ably/agent.rb
|
331
346
|
- lib/ably/auth.rb
|
332
347
|
- lib/ably/exceptions.rb
|
333
348
|
- lib/ably/logger.rb
|