rapns 3.3.2-java → 3.4.0-java
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.
- data/CHANGELOG.md +7 -0
- data/README.md +19 -21
- data/bin/rapns +14 -13
- data/lib/generators/templates/rapns.rb +8 -4
- data/lib/rapns.rb +7 -0
- data/lib/rapns/TODO +3 -0
- data/lib/rapns/apns/feedback.rb +4 -2
- data/lib/rapns/app.rb +3 -1
- data/lib/rapns/configuration.rb +8 -1
- data/lib/rapns/daemon.rb +3 -1
- data/lib/rapns/daemon/apns/app_runner.rb +3 -2
- data/lib/rapns/daemon/apns/certificate_expired_error.rb +20 -0
- data/lib/rapns/daemon/apns/connection.rb +26 -0
- data/lib/rapns/daemon/apns/delivery.rb +2 -1
- data/lib/rapns/daemon/apns/delivery_handler.rb +2 -2
- data/lib/rapns/daemon/app_runner.rb +50 -28
- data/lib/rapns/daemon/batch.rb +100 -0
- data/lib/rapns/daemon/delivery.rb +6 -10
- data/lib/rapns/daemon/delivery_handler.rb +14 -12
- data/lib/rapns/daemon/delivery_handler_collection.rb +33 -0
- data/lib/rapns/daemon/feeder.rb +3 -5
- data/lib/rapns/daemon/gcm/delivery.rb +5 -4
- data/lib/rapns/daemon/gcm/delivery_handler.rb +2 -2
- data/lib/rapns/daemon/store/active_record.rb +23 -2
- data/lib/rapns/deprecation.rb +7 -6
- data/lib/rapns/logger.rb +1 -1
- data/lib/rapns/notification.rb +5 -3
- data/lib/rapns/reflection.rb +1 -1
- data/lib/rapns/version.rb +1 -1
- data/lib/tasks/cane.rake +1 -1
- data/lib/tasks/test.rake +8 -3
- data/spec/unit/apns/app_spec.rb +4 -4
- data/spec/unit/apns_feedback_spec.rb +1 -1
- data/spec/unit/configuration_spec.rb +12 -6
- data/spec/unit/daemon/apns/app_runner_spec.rb +6 -4
- data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +11 -0
- data/spec/unit/daemon/apns/connection_spec.rb +46 -10
- data/spec/unit/daemon/apns/delivery_handler_spec.rb +24 -18
- data/spec/unit/daemon/apns/delivery_spec.rb +11 -12
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +16 -16
- data/spec/unit/daemon/app_runner_shared.rb +27 -10
- data/spec/unit/daemon/app_runner_spec.rb +48 -28
- data/spec/unit/daemon/batch_spec.rb +160 -0
- data/spec/unit/daemon/delivery_handler_collection_spec.rb +37 -0
- data/spec/unit/daemon/delivery_handler_shared.rb +20 -11
- data/spec/unit/daemon/feeder_spec.rb +12 -12
- data/spec/unit/daemon/gcm/app_runner_spec.rb +4 -2
- data/spec/unit/daemon/gcm/delivery_handler_spec.rb +18 -10
- data/spec/unit/daemon/gcm/delivery_spec.rb +47 -17
- data/spec/unit/daemon/interruptible_sleep_spec.rb +3 -3
- data/spec/unit/daemon/reflectable_spec.rb +1 -1
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +1 -1
- data/spec/unit/daemon/store/active_record_spec.rb +87 -10
- data/spec/unit/daemon_spec.rb +6 -6
- data/spec/unit/deprecation_spec.rb +2 -2
- data/spec/unit/logger_spec.rb +33 -17
- data/spec/unit/notification_shared.rb +7 -3
- data/spec/unit/upgraded_spec.rb +8 -14
- data/spec/unit_spec_helper.rb +9 -1
- metadata +53 -44
- data/lib/rapns/daemon/delivery_queue.rb +0 -42
- data/lib/rapns/daemon/delivery_queue_18.rb +0 -44
- data/lib/rapns/daemon/delivery_queue_19.rb +0 -42
- data/spec/acceptance/gcm_upgrade_spec.rb +0 -34
- data/spec/acceptance_spec_helper.rb +0 -85
- data/spec/unit/daemon/delivery_queue_spec.rb +0 -29
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'unit_spec_helper'
|
2
2
|
|
3
3
|
describe Rapns::Daemon::AppRunner, 'stop' do
|
4
|
-
let(:runner) {
|
4
|
+
let(:runner) { double }
|
5
5
|
before { Rapns::Daemon::AppRunner.runners['app'] = runner }
|
6
6
|
after { Rapns::Daemon::AppRunner.runners.clear }
|
7
7
|
|
@@ -11,10 +11,11 @@ describe Rapns::Daemon::AppRunner, 'stop' do
|
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
|
-
describe Rapns::Daemon::AppRunner, '
|
15
|
-
let(:runner) {
|
16
|
-
let(:
|
17
|
-
let(:
|
14
|
+
describe Rapns::Daemon::AppRunner, 'enqueue' do
|
15
|
+
let(:runner) { double(:enqueue => nil) }
|
16
|
+
let(:notification1) { double(:app_id => 1) }
|
17
|
+
let(:notification2) { double(:app_id => 2) }
|
18
|
+
let(:logger) { double(:error => nil) }
|
18
19
|
|
19
20
|
before do
|
20
21
|
Rapns.stub(:logger => logger)
|
@@ -23,29 +24,38 @@ describe Rapns::Daemon::AppRunner, 'deliver' do
|
|
23
24
|
|
24
25
|
after { Rapns::Daemon::AppRunner.runners.clear }
|
25
26
|
|
26
|
-
it '
|
27
|
-
|
28
|
-
Rapns::Daemon::
|
27
|
+
it 'batches notifications by app' do
|
28
|
+
batch = double.as_null_object
|
29
|
+
Rapns::Daemon::Batch.stub(:new => batch)
|
30
|
+
Rapns::Daemon::Batch.should_receive(:new).with([notification1])
|
31
|
+
Rapns::Daemon::Batch.should_receive(:new).with([notification2])
|
32
|
+
Rapns::Daemon::AppRunner.enqueue([notification1, notification2])
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'enqueues each batch' do
|
36
|
+
runner.should_receive(:enqueue).with(kind_of(Rapns::Daemon::Batch))
|
37
|
+
Rapns::Daemon::AppRunner.enqueue([notification1])
|
29
38
|
end
|
30
39
|
|
31
40
|
it 'logs an error if there is no runner to deliver the notification' do
|
32
|
-
|
33
|
-
|
34
|
-
|
41
|
+
notification1.stub(:app_id => 2, :id => 123)
|
42
|
+
notification2.stub(:app_id => 2, :id => 456)
|
43
|
+
logger.should_receive(:error).with("No such app '#{notification1.app_id}' for notifications 123, 456.")
|
44
|
+
Rapns::Daemon::AppRunner.enqueue([notification1, notification2])
|
35
45
|
end
|
36
46
|
end
|
37
47
|
|
38
48
|
describe Rapns::Daemon::AppRunner, 'sync' do
|
39
49
|
let(:app) { Rapns::Apns::App.new }
|
40
50
|
let(:new_app) { Rapns::Apns::App.new }
|
41
|
-
let(:runner) {
|
42
|
-
let(:logger) {
|
43
|
-
let(:queue) {
|
51
|
+
let(:runner) { double(:sync => nil, :stop => nil, :start => nil) }
|
52
|
+
let(:logger) { double(:error => nil, :warn => nil) }
|
53
|
+
let(:queue) { Queue.new }
|
44
54
|
|
45
55
|
before do
|
46
56
|
app.stub(:id => 1)
|
47
57
|
new_app.stub(:id => 2)
|
48
|
-
|
58
|
+
Queue.stub(:new => queue)
|
49
59
|
Rapns::Daemon::AppRunner.runners[app.id] = runner
|
50
60
|
Rapns::App.stub(:all => [app])
|
51
61
|
Rapns.stub(:logger => logger)
|
@@ -65,7 +75,7 @@ describe Rapns::Daemon::AppRunner, 'sync' do
|
|
65
75
|
|
66
76
|
it 'starts a runner for a new app' do
|
67
77
|
Rapns::App.stub(:all => [app, new_app])
|
68
|
-
new_runner =
|
78
|
+
new_runner = double
|
69
79
|
Rapns::Daemon::Apns::AppRunner.should_receive(:new).with(new_app).and_return(new_runner)
|
70
80
|
new_runner.should_receive(:start)
|
71
81
|
Rapns::Daemon::AppRunner.sync
|
@@ -79,10 +89,20 @@ describe Rapns::Daemon::AppRunner, 'sync' do
|
|
79
89
|
|
80
90
|
it 'logs an error if the app could not be started' do
|
81
91
|
Rapns::App.stub(:all => [app, new_app])
|
82
|
-
new_runner =
|
92
|
+
new_runner = double
|
83
93
|
Rapns::Daemon::Apns::AppRunner.should_receive(:new).with(new_app).and_return(new_runner)
|
84
94
|
new_runner.stub(:start).and_raise(StandardError)
|
85
|
-
Rapns.logger.should_receive(:error)
|
95
|
+
Rapns.logger.should_receive(:error)
|
96
|
+
Rapns::Daemon::AppRunner.sync
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'reflects errors if the app could not be started' do
|
100
|
+
Rapns::App.stub(:all => [app, new_app])
|
101
|
+
new_runner = double
|
102
|
+
Rapns::Daemon::Apns::AppRunner.should_receive(:new).with(new_app).and_return(new_runner)
|
103
|
+
e = StandardError.new
|
104
|
+
new_runner.stub(:start).and_raise(e)
|
105
|
+
Rapns::Daemon::AppRunner.should_receive(:reflect).with(:error, e)
|
86
106
|
Rapns::Daemon::AppRunner.sync
|
87
107
|
end
|
88
108
|
end
|
@@ -90,12 +110,12 @@ end
|
|
90
110
|
describe Rapns::Daemon::AppRunner, 'debug' do
|
91
111
|
let!(:app) { Rapns::Apns::App.create!(:name => 'test', :connections => 1,
|
92
112
|
:environment => 'development', :certificate => TEST_CERT) }
|
93
|
-
let(:logger) {
|
113
|
+
let(:logger) { double(:info => nil) }
|
94
114
|
|
95
115
|
before do
|
96
116
|
Rapns::Daemon.stub(:config => {})
|
97
|
-
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new =>
|
98
|
-
Rapns::Daemon::Apns::Connection.stub(:new =>
|
117
|
+
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new => double.as_null_object)
|
118
|
+
Rapns::Daemon::Apns::Connection.stub(:new => double.as_null_object)
|
99
119
|
Rapns.stub(:logger => logger)
|
100
120
|
Rapns::Daemon::AppRunner.sync
|
101
121
|
end
|
@@ -103,7 +123,7 @@ describe Rapns::Daemon::AppRunner, 'debug' do
|
|
103
123
|
after { Rapns::Daemon::AppRunner.runners.clear }
|
104
124
|
|
105
125
|
it 'prints debug app states to the log' do
|
106
|
-
Rapns.logger.should_receive(:info).with("\ntest:\n handlers: 1\n queued: 0\n idle: true\n")
|
126
|
+
Rapns.logger.should_receive(:info).with("\ntest:\n handlers: 1\n queued: 0\n batch size: 0\n batch processed: 0\n idle: true\n")
|
107
127
|
Rapns::Daemon::AppRunner.debug
|
108
128
|
end
|
109
129
|
end
|
@@ -111,12 +131,12 @@ end
|
|
111
131
|
describe Rapns::Daemon::AppRunner, 'idle' do
|
112
132
|
let!(:app) { Rapns::Apns::App.create!(:name => 'test', :connections => 1,
|
113
133
|
:environment => 'development', :certificate => TEST_CERT) }
|
114
|
-
let(:logger) {
|
134
|
+
let(:logger) { double(:info => nil) }
|
115
135
|
|
116
136
|
before do
|
117
137
|
Rapns.stub(:logger => logger)
|
118
|
-
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new =>
|
119
|
-
Rapns::Daemon::Apns::Connection.stub(:new =>
|
138
|
+
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new => double.as_null_object)
|
139
|
+
Rapns::Daemon::Apns::Connection.stub(:new => double.as_null_object)
|
120
140
|
Rapns::Daemon::AppRunner.sync
|
121
141
|
end
|
122
142
|
|
@@ -131,12 +151,12 @@ end
|
|
131
151
|
describe Rapns::Daemon::AppRunner, 'wait' do
|
132
152
|
let!(:app) { Rapns::Apns::App.create!(:name => 'test', :connections => 1,
|
133
153
|
:environment => 'development', :certificate => TEST_CERT) }
|
134
|
-
let(:logger) {
|
154
|
+
let(:logger) { double(:info => nil) }
|
135
155
|
|
136
156
|
before do
|
137
157
|
Rapns.stub(:logger => logger)
|
138
|
-
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new =>
|
139
|
-
Rapns::Daemon::Apns::Connection.stub(:new =>
|
158
|
+
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new => double.as_null_object)
|
159
|
+
Rapns::Daemon::Apns::Connection.stub(:new => double.as_null_object)
|
140
160
|
Rapns::Daemon::AppRunner.sync
|
141
161
|
end
|
142
162
|
|
@@ -0,0 +1,160 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rapns::Daemon::Batch do
|
4
|
+
let(:notification1) { double(:id => 1) }
|
5
|
+
let(:notification2) { double(:id => 2) }
|
6
|
+
let(:batch) { Rapns::Daemon::Batch.new([notification1, notification2]) }
|
7
|
+
let(:store) { double.as_null_object }
|
8
|
+
|
9
|
+
before do
|
10
|
+
Rapns::Daemon.stub(:store => store)
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'exposes the notifications' do
|
14
|
+
batch.notifications.should eq [notification1, notification2]
|
15
|
+
end
|
16
|
+
|
17
|
+
it 'exposes the number notifications' do
|
18
|
+
batch.num_notifications.should eq 2
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'exposes the number notifications processed' do
|
22
|
+
batch.num_processed.should eq 0
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'increments the processed notifications count' do
|
26
|
+
expect { batch.notification_processed }.to change(batch, :num_processed).to(1)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'completes the batch when all notifications have been processed' do
|
30
|
+
batch.should_receive(:complete)
|
31
|
+
2.times { batch.notification_processed }
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'can be described' do
|
35
|
+
batch.describe.should eq '1, 2'
|
36
|
+
end
|
37
|
+
|
38
|
+
describe 'mark_delivered' do
|
39
|
+
it 'marks the notification as delivered immediately if batching is disabled' do
|
40
|
+
Rapns.config.batch_storage_updates = false
|
41
|
+
store.should_receive(:mark_delivered).with(notification1)
|
42
|
+
batch.mark_delivered(notification1)
|
43
|
+
end
|
44
|
+
|
45
|
+
it 'defers marking the notification as delivered until the batch is complete' do
|
46
|
+
Rapns.config.batch_storage_updates = true
|
47
|
+
batch.mark_delivered(notification1)
|
48
|
+
batch.delivered.should eq [notification1]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'mark_failed' do
|
53
|
+
it 'marks the notification as failed immediately if batching is disabled' do
|
54
|
+
Rapns.config.batch_storage_updates = false
|
55
|
+
store.should_receive(:mark_failed).with(notification1, 1, 'an error')
|
56
|
+
batch.mark_failed(notification1, 1, 'an error')
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'defers marking the notification as failed until the batch is complete' do
|
60
|
+
Rapns.config.batch_storage_updates = true
|
61
|
+
batch.mark_failed(notification1, 1, 'an error')
|
62
|
+
batch.failed.should eq({[1, 'an error'] => [notification1]})
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
describe 'mark_retryable' do
|
67
|
+
let(:time) { Time.now }
|
68
|
+
|
69
|
+
it 'marks the notification as retryable immediately if batching is disabled' do
|
70
|
+
Rapns.config.batch_storage_updates = false
|
71
|
+
store.should_receive(:mark_retryable).with(notification1, time)
|
72
|
+
batch.mark_retryable(notification1, time)
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'defers marking the notification as retryable until the batch is complete' do
|
76
|
+
Rapns.config.batch_storage_updates = true
|
77
|
+
batch.mark_retryable(notification1, time)
|
78
|
+
batch.retryable.should eq({time => [notification1]})
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe 'complete' do
|
83
|
+
before do
|
84
|
+
Rapns.config.batch_storage_updates = true
|
85
|
+
Rapns.stub(:logger => double.as_null_object)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'clears the notifications' do
|
89
|
+
expect do
|
90
|
+
2.times { batch.notification_processed }
|
91
|
+
end.to change(batch, :notifications).to([])
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'identifies as complete' do
|
95
|
+
expect do
|
96
|
+
2.times { batch.notification_processed }
|
97
|
+
end.to change(batch, :complete?).to(be_true)
|
98
|
+
end
|
99
|
+
|
100
|
+
it 'reflects errors raised during completion' do
|
101
|
+
e = StandardError.new
|
102
|
+
batch.stub(:complete_delivered).and_raise(e)
|
103
|
+
batch.should_receive(:reflect).with(:error, e)
|
104
|
+
2.times { batch.notification_processed }
|
105
|
+
end
|
106
|
+
|
107
|
+
describe 'delivered' do
|
108
|
+
it 'marks the batch as delivered' do
|
109
|
+
store.should_receive(:mark_batch_delivered).with([notification1, notification2])
|
110
|
+
[notification1, notification2].each do |n|
|
111
|
+
batch.mark_delivered(n)
|
112
|
+
batch.notification_processed
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'clears the delivered notifications' do
|
117
|
+
[notification1, notification2].each { |n| batch.mark_delivered(n) }
|
118
|
+
expect do
|
119
|
+
2.times { batch.notification_processed }
|
120
|
+
end.to change(batch, :delivered).to([])
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
describe 'failed' do
|
125
|
+
it 'marks the batch as failed' do
|
126
|
+
store.should_receive(:mark_batch_failed).with([notification1, notification2], 1, 'an error')
|
127
|
+
[notification1, notification2].each do |n|
|
128
|
+
batch.mark_failed(n, 1, 'an error')
|
129
|
+
batch.notification_processed
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
it 'clears the failed notifications' do
|
134
|
+
[notification1, notification2].each { |n| batch.mark_failed(n, 1, 'an error') }
|
135
|
+
expect do
|
136
|
+
2.times { batch.notification_processed }
|
137
|
+
end.to change(batch, :failed).to({})
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
describe 'retryable' do
|
142
|
+
let(:time) { Time.now }
|
143
|
+
|
144
|
+
it 'marks the batch as retryable' do
|
145
|
+
store.should_receive(:mark_batch_retryable).with([notification1, notification2], time)
|
146
|
+
[notification1, notification2].each do |n|
|
147
|
+
batch.mark_retryable(n, time)
|
148
|
+
batch.notification_processed
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
it 'clears the retyable notifications' do
|
153
|
+
[notification1, notification2].each { |n| batch.mark_retryable(n, time) }
|
154
|
+
expect do
|
155
|
+
2.times { batch.notification_processed }
|
156
|
+
end.to change(batch, :retryable).to({})
|
157
|
+
end
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'unit_spec_helper'
|
2
|
+
|
3
|
+
describe Rapns::Daemon::DeliveryHandlerCollection do
|
4
|
+
let(:handler) { double.as_null_object }
|
5
|
+
let(:collection) { Rapns::Daemon::DeliveryHandlerCollection.new }
|
6
|
+
|
7
|
+
it 'returns the size of the collection' do
|
8
|
+
collection.push(handler)
|
9
|
+
collection.size.should eq 1
|
10
|
+
end
|
11
|
+
|
12
|
+
it 'pops a handler from the collection' do
|
13
|
+
collection.push(handler)
|
14
|
+
handler.should_receive(:stop)
|
15
|
+
handler.should_receive(:wakeup)
|
16
|
+
handler.should_receive(:wait)
|
17
|
+
collection.pop
|
18
|
+
collection.size.should eq 0
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'wakes up all handlers when popping a single handler' do
|
22
|
+
collection.push(handler)
|
23
|
+
handler2 = double.as_null_object
|
24
|
+
collection.push(handler2)
|
25
|
+
handler.should_receive(:wakeup)
|
26
|
+
handler2.should_receive(:wakeup)
|
27
|
+
collection.pop
|
28
|
+
end
|
29
|
+
|
30
|
+
it 'stops all handlers' do
|
31
|
+
collection.push(handler)
|
32
|
+
handler.should_receive(:stop)
|
33
|
+
handler.should_receive(:wakeup)
|
34
|
+
handler.should_receive(:wait)
|
35
|
+
collection.stop
|
36
|
+
end
|
37
|
+
end
|
@@ -1,34 +1,43 @@
|
|
1
1
|
shared_examples_for 'an DeliveryHandler subclass' do
|
2
|
+
def run_delivery_handler
|
3
|
+
delivery_handler.start
|
4
|
+
delivery_handler.stop
|
5
|
+
delivery_handler.wakeup
|
6
|
+
delivery_handler.wait
|
7
|
+
end
|
8
|
+
|
2
9
|
it 'logs all delivery errors' do
|
3
|
-
logger =
|
10
|
+
logger = double
|
4
11
|
Rapns.stub(:logger => logger)
|
5
12
|
error = StandardError.new
|
6
13
|
delivery_handler.stub(:deliver).and_raise(error)
|
7
14
|
Rapns.logger.should_receive(:error).with(error)
|
8
|
-
|
15
|
+
run_delivery_handler
|
9
16
|
end
|
10
17
|
|
11
18
|
it 'reflects an exception' do
|
12
|
-
Rapns.stub(:logger =>
|
19
|
+
Rapns.stub(:logger => double(:error => nil))
|
13
20
|
error = StandardError.new
|
14
21
|
delivery_handler.stub(:deliver).and_raise(error)
|
15
22
|
delivery_handler.should_receive(:reflect).with(:error, error)
|
16
|
-
|
23
|
+
run_delivery_handler
|
24
|
+
end
|
25
|
+
|
26
|
+
it 'instructs the batch that the notification has been processed' do
|
27
|
+
batch.should_receive(:notification_processed)
|
28
|
+
run_delivery_handler
|
17
29
|
end
|
18
30
|
|
19
31
|
it "instructs the queue to wakeup the thread when told to stop" do
|
20
|
-
|
21
|
-
|
22
|
-
queue.should_receive(:wakeup).with(thread)
|
23
|
-
delivery_handler.start
|
24
|
-
delivery_handler.stop
|
32
|
+
queue.should_receive(:push).with(Rapns::Daemon::DeliveryHandler::WAKEUP).and_call_original
|
33
|
+
run_delivery_handler
|
25
34
|
end
|
26
35
|
|
27
36
|
describe "when being stopped" do
|
28
37
|
before { queue.pop }
|
29
38
|
|
30
|
-
it "does not attempt to deliver a notification when a
|
31
|
-
queue.stub(:pop).
|
39
|
+
it "does not attempt to deliver a notification when a WAKEUP is dequeued" do
|
40
|
+
queue.stub(:pop).and_return(Rapns::Daemon::DeliveryHandler::WAKEUP)
|
32
41
|
delivery_handler.should_not_receive(:deliver)
|
33
42
|
delivery_handler.send(:handle_next_notification)
|
34
43
|
end
|
@@ -1,17 +1,17 @@
|
|
1
1
|
require "unit_spec_helper"
|
2
2
|
|
3
3
|
describe Rapns::Daemon::Feeder do
|
4
|
-
let(:config) {
|
4
|
+
let(:config) { double(:batch_size => 5000, :push_poll => 0, :embedded => false,
|
5
5
|
:push => false) }
|
6
6
|
let!(:app) { Rapns::Apns::App.create!(:name => 'my_app', :environment => 'development', :certificate => TEST_CERT) }
|
7
7
|
let(:notification) { Rapns::Apns::Notification.create!(:device_token => "a" * 64, :app => app) }
|
8
|
-
let(:logger) {
|
8
|
+
let(:logger) { double }
|
9
9
|
|
10
10
|
before do
|
11
11
|
Rapns.stub(:config => config,:logger => logger)
|
12
|
-
Rapns::Daemon.stub(:store =>
|
12
|
+
Rapns::Daemon.stub(:store => double(:deliverable_notifications => [notification]))
|
13
13
|
Rapns::Daemon::Feeder.stub(:stop? => true)
|
14
|
-
Rapns::Daemon::AppRunner.stub(:enqueue => nil, :idle => [
|
14
|
+
Rapns::Daemon::AppRunner.stub(:enqueue => nil, :idle => [double(:app => app)])
|
15
15
|
end
|
16
16
|
|
17
17
|
def start
|
@@ -30,6 +30,12 @@ describe Rapns::Daemon::Feeder do
|
|
30
30
|
start
|
31
31
|
end
|
32
32
|
|
33
|
+
it 'does not attempt to load deliverable notifications if there are no idle runners' do
|
34
|
+
Rapns::Daemon::AppRunner.stub(:idle => [])
|
35
|
+
Rapns::Daemon.store.should_not_receive(:deliverable_notifications)
|
36
|
+
start
|
37
|
+
end
|
38
|
+
|
33
39
|
it 'enqueues notifications without looping if in push mode' do
|
34
40
|
config.stub(:push => true)
|
35
41
|
Rapns::Daemon::Feeder.should_not_receive(:feed_forever)
|
@@ -37,14 +43,8 @@ describe Rapns::Daemon::Feeder do
|
|
37
43
|
start
|
38
44
|
end
|
39
45
|
|
40
|
-
it "enqueues the
|
41
|
-
Rapns::Daemon::AppRunner.should_receive(:enqueue).with(notification)
|
42
|
-
start
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'reflects the notification has been enqueued' do
|
46
|
-
Rapns::Daemon::AppRunner.stub(:enqueue)
|
47
|
-
Rapns::Daemon::Feeder.should_receive(:reflect).with(:notification_enqueued, notification)
|
46
|
+
it "enqueues the notifications" do
|
47
|
+
Rapns::Daemon::AppRunner.should_receive(:enqueue).with([notification])
|
48
48
|
start
|
49
49
|
end
|
50
50
|
|