rpush 2.7.0 → 3.0.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +41 -0
  3. data/README.md +36 -15
  4. data/lib/generators/rpush_migration_generator.rb +1 -0
  5. data/lib/generators/templates/add_adm.rb +1 -1
  6. data/lib/generators/templates/add_alert_is_json_to_rapns_notifications.rb +1 -1
  7. data/lib/generators/templates/add_app_to_rapns.rb +1 -1
  8. data/lib/generators/templates/add_fail_after_to_rpush_notifications.rb +1 -1
  9. data/lib/generators/templates/add_gcm.rb +1 -1
  10. data/lib/generators/templates/add_rpush.rb +11 -11
  11. data/lib/generators/templates/add_wpns.rb +1 -1
  12. data/lib/generators/templates/create_rapns_apps.rb +1 -1
  13. data/lib/generators/templates/create_rapns_feedback.rb +1 -1
  14. data/lib/generators/templates/create_rapns_notifications.rb +1 -1
  15. data/lib/generators/templates/rename_rapns_to_rpush.rb +1 -1
  16. data/lib/generators/templates/rpush.rb +1 -1
  17. data/lib/generators/templates/rpush_2_0_0_updates.rb +1 -1
  18. data/lib/generators/templates/rpush_2_1_0_updates.rb +1 -1
  19. data/lib/generators/templates/rpush_2_6_0_updates.rb +1 -1
  20. data/lib/generators/templates/rpush_2_7_0_updates.rb +1 -1
  21. data/lib/generators/templates/rpush_3_0_0_updates.rb +11 -0
  22. data/lib/rpush.rb +2 -9
  23. data/lib/rpush/apns_feedback.rb +4 -0
  24. data/lib/rpush/cli.rb +2 -2
  25. data/lib/rpush/client/active_model.rb +3 -0
  26. data/lib/rpush/client/active_model/apns/notification.rb +11 -1
  27. data/lib/rpush/client/active_model/apns2/app.rb +15 -0
  28. data/lib/rpush/client/active_model/apns2/notification.rb +9 -0
  29. data/lib/rpush/client/active_record.rb +3 -0
  30. data/lib/rpush/client/active_record/apns/feedback.rb +0 -4
  31. data/lib/rpush/client/active_record/apns2/app.rb +11 -0
  32. data/lib/rpush/client/active_record/apns2/notification.rb +10 -0
  33. data/lib/rpush/client/active_record/app.rb +0 -4
  34. data/lib/rpush/client/active_record/notification.rb +0 -7
  35. data/lib/rpush/client/redis.rb +3 -0
  36. data/lib/rpush/client/redis/apns2/app.rb +11 -0
  37. data/lib/rpush/client/redis/apns2/notification.rb +11 -0
  38. data/lib/rpush/client/redis/notification.rb +1 -0
  39. data/lib/rpush/daemon.rb +5 -3
  40. data/lib/rpush/daemon/apns2.rb +10 -0
  41. data/lib/rpush/daemon/apns2/delivery.rb +127 -0
  42. data/lib/rpush/daemon/dispatcher/apns_http2.rb +50 -0
  43. data/lib/rpush/daemon/dispatcher/apns_tcp.rb +1 -1
  44. data/lib/rpush/daemon/dispatcher/http.rb +1 -1
  45. data/lib/rpush/daemon/gcm/delivery.rb +5 -5
  46. data/lib/rpush/daemon/service_config_methods.rb +4 -3
  47. data/lib/rpush/daemon/store/active_record/reconnectable.rb +11 -3
  48. data/lib/rpush/daemon/synchronizer.rb +14 -12
  49. data/lib/rpush/version.rb +12 -1
  50. data/spec/functional/apns2_spec.rb +232 -0
  51. data/spec/functional/apns_spec.rb +1 -2
  52. data/spec/functional/synchronization_spec.rb +29 -0
  53. data/spec/spec_helper.rb +0 -5
  54. data/spec/support/active_record_setup.rb +2 -1
  55. data/spec/unit/apns_feedback_spec.rb +9 -2
  56. data/spec/unit/client/active_record/apns/notification_spec.rb +34 -2
  57. data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +30 -0
  58. data/spec/unit_spec_helper.rb +2 -21
  59. metadata +256 -29
  60. data/lib/rpush/client/mongoid.rb +0 -36
  61. data/lib/rpush/client/mongoid/adm/app.rb +0 -14
  62. data/lib/rpush/client/mongoid/adm/notification.rb +0 -11
  63. data/lib/rpush/client/mongoid/apns/app.rb +0 -11
  64. data/lib/rpush/client/mongoid/apns/feedback.rb +0 -24
  65. data/lib/rpush/client/mongoid/apns/notification.rb +0 -15
  66. data/lib/rpush/client/mongoid/app.rb +0 -23
  67. data/lib/rpush/client/mongoid/gcm/app.rb +0 -11
  68. data/lib/rpush/client/mongoid/gcm/notification.rb +0 -11
  69. data/lib/rpush/client/mongoid/notification.rb +0 -51
  70. data/lib/rpush/client/mongoid/wns/app.rb +0 -14
  71. data/lib/rpush/client/mongoid/wns/badge_notification.rb +0 -15
  72. data/lib/rpush/client/mongoid/wns/notification.rb +0 -11
  73. data/lib/rpush/client/mongoid/wns/raw_notification.rb +0 -11
  74. data/lib/rpush/client/mongoid/wpns/app.rb +0 -11
  75. data/lib/rpush/client/mongoid/wpns/notification.rb +0 -11
  76. data/lib/rpush/daemon/store/mongoid.rb +0 -157
  77. data/spec/support/config/mongoid.yml +0 -69
  78. data/spec/support/mongoid_setup.rb +0 -10
  79. data/spec/unit/daemon/store/mongoid_spec.rb +0 -339
@@ -1,69 +0,0 @@
1
- development:
2
- # Configure available database sessions. (required)
3
- sessions:
4
- # Defines the default session. (required)
5
- default:
6
- # Defines the name of the default database that Mongoid can connect to.
7
- # (required).
8
- database: rpush_development
9
- # Provides the hosts the default session can connect to. Must be an array
10
- # of host:port pairs. (required)
11
- hosts:
12
- - localhost:27017
13
- options:
14
- # Change the default write concern. (default = { w: 1 })
15
- # write:
16
- # w: 1
17
-
18
- # Change the default consistency model to primary, secondary.
19
- # 'secondary' will send reads to secondaries, 'primary' sends everything
20
- # to master. (default: primary)
21
- # read: secondary_preferred
22
-
23
- # How many times Moped should attempt to retry an operation after
24
- # failure. (default: The number of nodes in the cluster)
25
- # max_retries: 20
26
-
27
- # The time in seconds that Moped should wait before retrying an
28
- # operation on failure. (default: 0.25)
29
- # retry_interval: 0.25
30
- # Configure Mongoid specific options. (optional)
31
- options:
32
- # Includes the root model name in json serialization. (default: false)
33
- # include_root_in_json: false
34
-
35
- # Include the _type field in serialization. (default: false)
36
- # include_type_for_serialization: false
37
-
38
- # Preload all models in development, needed when models use
39
- # inheritance. (default: false)
40
- # preload_models: false
41
-
42
- # Protect id and type from mass assignment. (default: true)
43
- # protect_sensitive_fields: true
44
-
45
- # Raise an error when performing a #find and the document is not found.
46
- # (default: true)
47
- # raise_not_found_error: true
48
-
49
- # Raise an error when defining a scope with the same name as an
50
- # existing method. (default: false)
51
- # scope_overwrite_exception: false
52
-
53
- # Use Active Support's time zone in conversions. (default: true)
54
- # use_activesupport_time_zone: true
55
-
56
- # Ensure all times are UTC in the app side. (default: false)
57
- # use_utc: false
58
- test:
59
- sessions:
60
- default:
61
- database: rpush_test
62
- hosts:
63
- - localhost:27017
64
- options:
65
- read: primary
66
- # In the test environment we lower the retries and retry interval to
67
- # low amounts for fast failures.
68
- max_retries: 1
69
- retry_interval: 0
@@ -1,10 +0,0 @@
1
- require 'mongoid'
2
-
3
- mongoid_yml = File.expand_path("config/mongoid.yml", File.dirname(__FILE__))
4
- Mongoid.load!(mongoid_yml)
5
-
6
- RSpec.configure do |config|
7
- config.before(:each) do
8
- Mongoid.purge!
9
- end
10
- end
@@ -1,339 +0,0 @@
1
- require 'unit_spec_helper'
2
- require 'rpush/daemon/store/mongoid'
3
-
4
- describe Rpush::Daemon::Store::Mongoid do
5
- let(:app) { Rpush::Client::Mongoid::Apns::App.create!(name: 'my_app', environment: 'development', certificate: TEST_CERT) }
6
- let(:notification) { Rpush::Client::Mongoid::Apns::Notification.create!(device_token: "a" * 64, app: app) }
7
- let(:store) { Rpush::Daemon::Store::Mongoid.new }
8
- let(:time) { Time.now.utc }
9
- let(:logger) { double(Rpush::Logger, error: nil, internal_logger: nil) }
10
-
11
- before do
12
- allow(Rpush).to receive_messages(logger: logger)
13
- allow(Time).to receive_messages(now: time)
14
- end
15
-
16
- it 'updates an notification' do
17
- expect(notification).to receive(:save!)
18
- store.update_notification(notification)
19
- end
20
-
21
- it 'updates an app' do
22
- expect(app).to receive(:save!)
23
- store.update_app(app)
24
- end
25
-
26
- it 'finds an app by ID' do
27
- expect(store.app(app.id)).to eq(app)
28
- end
29
-
30
- it 'finds all apps' do
31
- expect(store.all_apps).to eq([app])
32
- end
33
-
34
- it 'translates an Integer notification ID' do
35
- expect(store.translate_integer_notification_id(notification.integer_id)).to eq(notification.id)
36
- end
37
-
38
- it 'returns the pending notification count' do
39
- notification
40
- expect(store.pending_delivery_count).to eq(1)
41
- end
42
-
43
- describe 'deliverable_notifications' do
44
- it 'loads notifications in batches' do
45
- Rpush.config.batch_size = 5000
46
- relation = double.as_null_object
47
- expect(relation).to receive(:limit).with(5000)
48
- allow(relation).to receive_messages(to_a: [])
49
- allow(store).to receive_messages(ready_for_delivery: relation)
50
- store.deliverable_notifications(Rpush.config.batch_size)
51
- end
52
-
53
- it 'loads an undelivered notification without deliver_after set' do
54
- notification.update_attributes!(delivered: false, deliver_after: nil)
55
- expect(store.deliverable_notifications(Rpush.config.batch_size)).to eq [notification]
56
- end
57
-
58
- it 'loads an notification with a deliver_after time in the past' do
59
- notification.update_attributes!(delivered: false, deliver_after: 1.hour.ago)
60
- expect(store.deliverable_notifications(Rpush.config.batch_size)).to eq [notification]
61
- end
62
-
63
- it 'does not load an notification with a deliver_after time in the future' do
64
- notification.update_attributes!(delivered: false, deliver_after: 1.hour.from_now)
65
- expect(store.deliverable_notifications(Rpush.config.batch_size)).to be_empty
66
- end
67
-
68
- it 'does not load a previously delivered notification' do
69
- notification.update_attributes!(delivered: true, delivered_at: time)
70
- expect(store.deliverable_notifications(Rpush.config.batch_size)).to be_empty
71
- end
72
-
73
- it "does not enqueue a notification that has previously failed delivery" do
74
- notification.update_attributes!(delivered: false, failed: true)
75
- expect(store.deliverable_notifications(Rpush.config.batch_size)).to be_empty
76
- end
77
- end
78
-
79
- describe 'mark_retryable' do
80
- it 'increments the retry count' do
81
- expect do
82
- store.mark_retryable(notification, time)
83
- end.to change(notification, :retries).by(1)
84
- end
85
-
86
- it 'sets the deliver after timestamp' do
87
- deliver_after = time + 10.seconds
88
- expect do
89
- store.mark_retryable(notification, deliver_after)
90
- end.to change(notification, :deliver_after).to(deliver_after)
91
- end
92
-
93
- it 'saves the notification without validation' do
94
- expect(notification).to receive(:save!).with(validate: false)
95
- store.mark_retryable(notification, time)
96
- end
97
-
98
- it 'does not save the notification if persist: false' do
99
- expect(notification).not_to receive(:save!)
100
- store.mark_retryable(notification, time, persist: false)
101
- end
102
- end
103
-
104
- describe 'mark_batch_retryable' do
105
- let(:deliver_after) { time + 10.seconds }
106
-
107
- it 'sets the attributes on the object for use in reflections' do
108
- store.mark_batch_retryable([notification], deliver_after)
109
- expect(notification.deliver_after).to eq deliver_after
110
- expect(notification.retries).to eq 1
111
- end
112
-
113
- it 'increments the retired count' do
114
- expect do
115
- store.mark_batch_retryable([notification], deliver_after)
116
- notification.reload
117
- end.to change(notification, :retries).by(1)
118
- end
119
-
120
- it 'sets the deliver after timestamp' do
121
- expect do
122
- store.mark_batch_retryable([notification], deliver_after)
123
- notification.reload
124
- end.to change { notification.deliver_after.try(:utc).to_s }.to(deliver_after.utc.to_s)
125
- end
126
- end
127
-
128
- describe 'mark_delivered' do
129
- it 'marks the notification as delivered' do
130
- expect do
131
- store.mark_delivered(notification, time)
132
- end.to change(notification, :delivered).to(true)
133
- end
134
-
135
- it 'sets the time the notification was delivered' do
136
- expect do
137
- store.mark_delivered(notification, time)
138
- notification.reload
139
- end.to change { notification.delivered_at.try(:utc).to_s }.to(time.to_s)
140
- end
141
-
142
- it 'saves the notification without validation' do
143
- expect(notification).to receive(:save!).with(validate: false)
144
- store.mark_delivered(notification, time)
145
- end
146
-
147
- it 'does not save the notification if persist: false' do
148
- expect(notification).not_to receive(:save!)
149
- store.mark_delivered(notification, time, persist: false)
150
- end
151
- end
152
-
153
- describe 'mark_batch_delivered' do
154
- it 'sets the attributes on the object for use in reflections' do
155
- store.mark_batch_delivered([notification])
156
- expect(notification.delivered_at).to eq time
157
- expect(notification.delivered).to be_truthy
158
- end
159
-
160
- it 'marks the notifications as delivered' do
161
- expect do
162
- store.mark_batch_delivered([notification])
163
- notification.reload
164
- end.to change(notification, :delivered).to(true)
165
- end
166
-
167
- it 'sets the time the notifications were delivered' do
168
- expect do
169
- store.mark_batch_delivered([notification])
170
- notification.reload
171
- end.to change { notification.delivered_at.try(:utc).to_s }.to(time.to_s)
172
- end
173
- end
174
-
175
- describe 'mark_failed' do
176
- it 'marks the notification as not delivered' do
177
- store.mark_failed(notification, nil, '', time)
178
- expect(notification.delivered).to eq(false)
179
- end
180
-
181
- it 'marks the notification as failed' do
182
- expect do
183
- store.mark_failed(notification, nil, '', time)
184
- notification.reload
185
- end.to change(notification, :failed).to(true)
186
- end
187
-
188
- it 'sets the time the notification delivery failed' do
189
- expect do
190
- store.mark_failed(notification, nil, '', time)
191
- notification.reload
192
- end.to change { notification.failed_at.try(:utc).to_s }.to(time.to_s)
193
- end
194
-
195
- it 'sets the error code' do
196
- expect do
197
- store.mark_failed(notification, 42, '', time)
198
- end.to change(notification, :error_code).to(42)
199
- end
200
-
201
- it 'sets the error description' do
202
- expect do
203
- store.mark_failed(notification, 42, 'Weeee', time)
204
- end.to change(notification, :error_description).to('Weeee')
205
- end
206
-
207
- it 'saves the notification without validation' do
208
- expect(notification).to receive(:save!).with(validate: false)
209
- store.mark_failed(notification, nil, '', time)
210
- end
211
-
212
- it 'does not save the notification if persist: false' do
213
- expect(notification).not_to receive(:save!)
214
- store.mark_failed(notification, nil, '', time, persist: false)
215
- end
216
- end
217
-
218
- describe 'mark_batch_failed' do
219
- it 'sets the attributes on the object for use in reflections' do
220
- store.mark_batch_failed([notification], 123, 'an error')
221
- expect(notification.failed_at).to eq time
222
- expect(notification.delivered_at).to be_nil
223
- expect(notification.delivered).to eq(false)
224
- expect(notification.failed).to be_truthy
225
- expect(notification.error_code).to eq 123
226
- expect(notification.error_description).to eq 'an error'
227
- end
228
-
229
- it 'marks the notification as not delivered' do
230
- store.mark_batch_failed([notification], nil, '')
231
- notification.reload
232
- expect(notification.delivered).to be_falsey
233
- end
234
-
235
- it 'marks the notification as failed' do
236
- expect do
237
- store.mark_batch_failed([notification], nil, '')
238
- notification.reload
239
- end.to change(notification, :failed).to(true)
240
- end
241
-
242
- it 'sets the time the notification delivery failed' do
243
- expect do
244
- store.mark_batch_failed([notification], nil, '')
245
- notification.reload
246
- end.to change { notification.failed_at.try(:utc).to_s }.to(time.to_s)
247
- end
248
-
249
- it 'sets the error code' do
250
- expect do
251
- store.mark_batch_failed([notification], 42, '')
252
- notification.reload
253
- end.to change(notification, :error_code).to(42)
254
- end
255
-
256
- it 'sets the error description' do
257
- expect do
258
- store.mark_batch_failed([notification], 42, 'Weeee')
259
- notification.reload
260
- end.to change(notification, :error_description).to('Weeee')
261
- end
262
- end
263
-
264
- describe 'create_apns_feedback' do
265
- it 'creates the Feedback record' do
266
- expect(Rpush::Client::Mongoid::Apns::Feedback).to receive(:create!).with(
267
- failed_at: time, device_token: 'ab' * 32, app: app)
268
- store.create_apns_feedback(time, 'ab' * 32, app)
269
- end
270
- end
271
-
272
- describe 'create_gcm_notification' do
273
- let(:data) { { data: true } }
274
- let(:attributes) { { device_token: 'ab' * 32 } }
275
- let(:registration_ids) { %w(123 456) }
276
- let(:deliver_after) { time + 10.seconds }
277
- let(:args) { [attributes, data, registration_ids, deliver_after, app] }
278
-
279
- it 'sets the given attributes' do
280
- new_notification = store.create_gcm_notification(*args)
281
- expect(new_notification.device_token).to eq 'ab' * 32
282
- end
283
-
284
- it 'sets the given data' do
285
- new_notification = store.create_gcm_notification(*args)
286
- expect(new_notification.data).to eq(data: true)
287
- end
288
-
289
- it 'sets the given registration IDs' do
290
- new_notification = store.create_gcm_notification(*args)
291
- expect(new_notification.registration_ids).to eq registration_ids
292
- end
293
-
294
- it 'sets the deliver_after timestamp' do
295
- new_notification = store.create_gcm_notification(*args)
296
- expect(new_notification.deliver_after.utc.to_s).to eq deliver_after.to_s
297
- end
298
-
299
- it 'saves the new notification' do
300
- new_notification = store.create_gcm_notification(*args)
301
- expect(new_notification.new_record?).to be_falsey
302
- end
303
- end
304
-
305
- describe 'create_adm_notification' do
306
- let(:data) { { data: true } }
307
- let(:attributes) { { app_id: app.id, collapse_key: 'ckey', delay_while_idle: true } }
308
- let(:registration_ids) { %w(123 456) }
309
- let(:deliver_after) { time + 10.seconds }
310
- let(:args) { [attributes, data, registration_ids, deliver_after, app] }
311
-
312
- it 'sets the given attributes' do
313
- new_notification = store.create_adm_notification(*args)
314
- expect(new_notification.app_id).to eq app.id
315
- expect(new_notification.collapse_key).to eq 'ckey'
316
- expect(new_notification.delay_while_idle).to be_truthy
317
- end
318
-
319
- it 'sets the given data' do
320
- new_notification = store.create_adm_notification(*args)
321
- expect(new_notification.data).to eq(data: true)
322
- end
323
-
324
- it 'sets the given registration IDs' do
325
- new_notification = store.create_adm_notification(*args)
326
- expect(new_notification.registration_ids).to eq registration_ids
327
- end
328
-
329
- it 'sets the deliver_after timestamp' do
330
- new_notification = store.create_adm_notification(*args)
331
- expect(new_notification.deliver_after.utc.to_s).to eq deliver_after.to_s
332
- end
333
-
334
- it 'saves the new notification' do
335
- new_notification = store.create_adm_notification(*args)
336
- expect(new_notification.new_record?).to be_falsey
337
- end
338
- end
339
- end if mongoid?