rapns_rails_2 3.5.1 → 3.6.1
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 +7 -0
- data/README.md +2 -0
- data/lib/rapns/daemon/gcm/delivery.rb +4 -3
- data/lib/rapns/version.rb +1 -1
- metadata +46 -163
- data/config/database.yml +0 -44
- data/spec/support/cert_with_password.pem +0 -90
- data/spec/support/cert_without_password.pem +0 -59
- data/spec/support/simplecov_helper.rb +0 -13
- data/spec/support/simplecov_quality_formatter.rb +0 -8
- data/spec/tmp/.gitkeep +0 -0
- data/spec/unit/apns/app_spec.rb +0 -29
- data/spec/unit/apns/feedback_spec.rb +0 -9
- data/spec/unit/apns/notification_spec.rb +0 -215
- data/spec/unit/apns_feedback_spec.rb +0 -21
- data/spec/unit/app_spec.rb +0 -16
- data/spec/unit/configuration_spec.rb +0 -55
- data/spec/unit/daemon/apns/app_runner_spec.rb +0 -45
- data/spec/unit/daemon/apns/certificate_expired_error_spec.rb +0 -11
- data/spec/unit/daemon/apns/connection_spec.rb +0 -287
- data/spec/unit/daemon/apns/delivery_handler_spec.rb +0 -59
- data/spec/unit/daemon/apns/delivery_spec.rb +0 -101
- data/spec/unit/daemon/apns/disconnection_error_spec.rb +0 -18
- data/spec/unit/daemon/apns/feedback_receiver_spec.rb +0 -134
- data/spec/unit/daemon/app_runner_shared.rb +0 -83
- data/spec/unit/daemon/app_runner_spec.rb +0 -170
- data/spec/unit/daemon/batch_spec.rb +0 -219
- data/spec/unit/daemon/delivery_error_spec.rb +0 -13
- data/spec/unit/daemon/delivery_handler_collection_spec.rb +0 -37
- data/spec/unit/daemon/delivery_handler_shared.rb +0 -45
- data/spec/unit/daemon/feeder_spec.rb +0 -89
- data/spec/unit/daemon/gcm/app_runner_spec.rb +0 -19
- data/spec/unit/daemon/gcm/delivery_handler_spec.rb +0 -44
- data/spec/unit/daemon/gcm/delivery_spec.rb +0 -289
- data/spec/unit/daemon/interruptible_sleep_spec.rb +0 -68
- data/spec/unit/daemon/reflectable_spec.rb +0 -27
- data/spec/unit/daemon/store/active_record/reconnectable_spec.rb +0 -114
- data/spec/unit/daemon/store/active_record_spec.rb +0 -281
- data/spec/unit/daemon_spec.rb +0 -157
- data/spec/unit/deprecatable_spec.rb +0 -32
- data/spec/unit/deprecation_spec.rb +0 -15
- data/spec/unit/embed_spec.rb +0 -50
- data/spec/unit/gcm/app_spec.rb +0 -4
- data/spec/unit/gcm/notification_spec.rb +0 -52
- data/spec/unit/logger_spec.rb +0 -180
- data/spec/unit/notification_shared.rb +0 -45
- data/spec/unit/notification_spec.rb +0 -4
- data/spec/unit/notifier_spec.rb +0 -52
- data/spec/unit/push_spec.rb +0 -44
- data/spec/unit/rapns_spec.rb +0 -9
- data/spec/unit/reflection_spec.rb +0 -30
- data/spec/unit/upgraded_spec.rb +0 -40
- data/spec/unit_spec_helper.rb +0 -137
@@ -1,59 +0,0 @@
|
|
1
|
-
require File.expand_path("spec/unit_spec_helper")
|
2
|
-
require File.dirname(__FILE__) + '/../delivery_handler_shared.rb'
|
3
|
-
|
4
|
-
describe Rapns::Daemon::Apns::DeliveryHandler do
|
5
|
-
it_should_behave_like 'an DeliveryHandler subclass'
|
6
|
-
|
7
|
-
let(:host) { 'gateway.push.apple.com' }
|
8
|
-
let(:port) { 2195 }
|
9
|
-
let(:certificate) { double }
|
10
|
-
let(:password) { double }
|
11
|
-
let(:app) { double(:password => password, :certificate => certificate, :name => 'MyApp', :environment => 'production')}
|
12
|
-
let(:delivery_handler) { Rapns::Daemon::Apns::DeliveryHandler.new(app) }
|
13
|
-
let(:connection) { double(:connection, :select => false, :write => nil, :reconnect => nil, :close => nil, :connect => nil) }
|
14
|
-
let(:notification) { double(:notification) }
|
15
|
-
let(:batch) { double(:batch, :notification_processed => nil) }
|
16
|
-
let(:http) { double(:http, :shutdown => nil)}
|
17
|
-
let(:queue) { Queue.new }
|
18
|
-
let(:delivery) { double(:perform => nil) }
|
19
|
-
|
20
|
-
before do
|
21
|
-
Rapns::Daemon::Apns::Connection.stub(:new => connection)
|
22
|
-
Rapns::Daemon::Apns::Delivery.stub(:new => delivery)
|
23
|
-
delivery_handler.queue = queue
|
24
|
-
queue.push([notification, batch])
|
25
|
-
end
|
26
|
-
|
27
|
-
def run_delivery_handler
|
28
|
-
delivery_handler.start
|
29
|
-
delivery_handler.stop
|
30
|
-
delivery_handler.wakeup
|
31
|
-
delivery_handler.wait
|
32
|
-
end
|
33
|
-
|
34
|
-
it "instantiates a new connection" do
|
35
|
-
Rapns::Daemon::Apns::Connection.should_receive(:new).with(app, host, port)
|
36
|
-
run_delivery_handler
|
37
|
-
end
|
38
|
-
|
39
|
-
it "connects the socket" do
|
40
|
-
connection.should_receive(:connect)
|
41
|
-
run_delivery_handler
|
42
|
-
end
|
43
|
-
|
44
|
-
it 'performs delivery of an notification' do
|
45
|
-
Rapns::Daemon::Apns::Delivery.should_receive(:new).with(app, connection, notification, batch).and_return(delivery)
|
46
|
-
delivery.should_receive(:perform)
|
47
|
-
run_delivery_handler
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'closes the connection stopped' do
|
51
|
-
connection.should_receive(:close)
|
52
|
-
run_delivery_handler
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'does not attempt to close the connection if the connection was not established' do
|
56
|
-
connection.should_not_receive(:close)
|
57
|
-
delivery_handler.stop
|
58
|
-
end
|
59
|
-
end
|
@@ -1,101 +0,0 @@
|
|
1
|
-
require File.expand_path("spec/unit_spec_helper")
|
2
|
-
|
3
|
-
describe Rapns::Daemon::Apns::Delivery do
|
4
|
-
let(:app) { double(:name => 'MyApp') }
|
5
|
-
let(:notification) { double(:id => 123).as_null_object }
|
6
|
-
let(:batch) { double(:mark_failed => nil, :mark_delivered => nil) }
|
7
|
-
let(:logger) { double(:error => nil, :info => nil) }
|
8
|
-
let(:config) { double(:check_for_errors => true) }
|
9
|
-
let(:connection) { double(:select => false, :write => nil, :reconnect => nil, :close => nil, :connect => nil) }
|
10
|
-
let(:delivery) { Rapns::Daemon::Apns::Delivery.new(app, connection, notification, batch) }
|
11
|
-
|
12
|
-
def perform
|
13
|
-
begin
|
14
|
-
delivery.perform
|
15
|
-
rescue Rapns::DeliveryError, Rapns::Apns::DisconnectionError
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
|
-
before do
|
20
|
-
Rapns.stub(:config => config, :logger => logger)
|
21
|
-
end
|
22
|
-
|
23
|
-
it "sends the binary version of the notification" do
|
24
|
-
notification.stub(:to_binary => "hi mom")
|
25
|
-
connection.should_receive(:write).with("hi mom")
|
26
|
-
perform
|
27
|
-
end
|
28
|
-
|
29
|
-
it "logs the notification delivery" do
|
30
|
-
notification.stub(:id => 666, :device_token => 'abc123')
|
31
|
-
logger.should_receive(:info).with("[MyApp] 666 sent to abc123")
|
32
|
-
perform
|
33
|
-
end
|
34
|
-
|
35
|
-
it "marks the notification as delivered" do
|
36
|
-
batch.should_receive(:mark_delivered).with(notification)
|
37
|
-
perform
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'does not check for errors if check_for_errors config option is false' do
|
41
|
-
config.stub(:check_for_errors => false)
|
42
|
-
delivery.should_not_receive(:check_for_error)
|
43
|
-
perform
|
44
|
-
end
|
45
|
-
|
46
|
-
describe "when delivery fails" do
|
47
|
-
before { connection.stub(:select => true, :read => [8, 4, 69].pack("ccN")) }
|
48
|
-
|
49
|
-
it "marks the notification as failed" do
|
50
|
-
batch.should_receive(:mark_failed).with(notification, 4, "Missing payload")
|
51
|
-
perform
|
52
|
-
end
|
53
|
-
|
54
|
-
it "logs the delivery error" do
|
55
|
-
# checking for the doublebed error doesn't work in jruby, but checking
|
56
|
-
# for the exception by class does.
|
57
|
-
|
58
|
-
#error = Rapns::DeliveryError.new(4, 12, "Missing payload")
|
59
|
-
#Rapns::DeliveryError.stub(:new => error)
|
60
|
-
#expect { delivery.perform }.to raise_error(error)
|
61
|
-
|
62
|
-
expect { delivery.perform }.to raise_error(Rapns::DeliveryError)
|
63
|
-
end
|
64
|
-
|
65
|
-
it "reads 6 bytes from the socket" do
|
66
|
-
connection.should_receive(:read).with(6).and_return(nil)
|
67
|
-
perform
|
68
|
-
end
|
69
|
-
|
70
|
-
it "does not attempt to read from the socket if the socket was not selected for reading after the timeout" do
|
71
|
-
connection.stub(:select => nil)
|
72
|
-
connection.should_not_receive(:read)
|
73
|
-
perform
|
74
|
-
end
|
75
|
-
|
76
|
-
it "reconnects the socket" do
|
77
|
-
connection.should_receive(:reconnect)
|
78
|
-
perform
|
79
|
-
end
|
80
|
-
|
81
|
-
it "logs that the connection is being reconnected" do
|
82
|
-
Rapns.logger.should_receive(:error).with("[MyApp] Error received, reconnecting...")
|
83
|
-
perform
|
84
|
-
end
|
85
|
-
|
86
|
-
context "when the APNs disconnects without returning an error" do
|
87
|
-
before do
|
88
|
-
connection.stub(:read => nil)
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'raises a DisconnectError error if the connection is closed without an error being returned' do
|
92
|
-
expect { delivery.perform }.to raise_error(Rapns::Apns::DisconnectionError)
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'marks the notification as failed' do
|
96
|
-
batch.should_receive(:mark_failed).with(notification, nil, "APNs disconnected without returning an error.")
|
97
|
-
perform
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
@@ -1,18 +0,0 @@
|
|
1
|
-
require File.expand_path("spec/unit_spec_helper")
|
2
|
-
|
3
|
-
describe Rapns::Apns::DisconnectionError do
|
4
|
-
let(:error) { Rapns::Apns::DisconnectionError.new }
|
5
|
-
|
6
|
-
it 'returns a nil error code' do
|
7
|
-
error.code.should be_nil
|
8
|
-
end
|
9
|
-
|
10
|
-
it 'contains an error description' do
|
11
|
-
error.description
|
12
|
-
end
|
13
|
-
|
14
|
-
it 'returns a message' do
|
15
|
-
error.message
|
16
|
-
error.to_s
|
17
|
-
end
|
18
|
-
end
|
@@ -1,134 +0,0 @@
|
|
1
|
-
require File.expand_path("spec/unit_spec_helper")
|
2
|
-
|
3
|
-
describe Rapns::Daemon::Apns::FeedbackReceiver, 'check_for_feedback' do
|
4
|
-
|
5
|
-
let(:host) { 'feedback.push.apple.com' }
|
6
|
-
let(:port) { 2196 }
|
7
|
-
let(:poll) { 60 }
|
8
|
-
let(:certificate) { double }
|
9
|
-
let(:password) { double }
|
10
|
-
let(:app) { double(:name => 'my_app', :password => password, :certificate => certificate, :environment => 'production') }
|
11
|
-
let(:connection) { double(:connect => nil, :read => nil, :close => nil) }
|
12
|
-
let(:logger) { double(:error => nil, :info => nil) }
|
13
|
-
let(:receiver) { Rapns::Daemon::Apns::FeedbackReceiver.new(app, poll) }
|
14
|
-
let(:feedback) { double }
|
15
|
-
|
16
|
-
before do
|
17
|
-
receiver.stub(:interruptible_sleep)
|
18
|
-
Rapns.stub(:logger => logger)
|
19
|
-
Rapns::Daemon::Apns::Connection.stub(:new => connection)
|
20
|
-
receiver.instance_variable_set("@stop", false)
|
21
|
-
Rapns::Daemon.stub(:store => double(:create_apns_feedback => feedback))
|
22
|
-
end
|
23
|
-
|
24
|
-
def double_connection_read_with_tuple
|
25
|
-
connection.unstub(:read)
|
26
|
-
|
27
|
-
def connection.read(bytes)
|
28
|
-
if !@called
|
29
|
-
@called = true
|
30
|
-
"N\xE3\x84\r\x00 \x83OxfU\xEB\x9F\x84aJ\x05\xAD}\x00\xAF1\xE5\xCF\xE9:\xC3\xEA\a\x8F\x1D\xA4M*N\xB0\xCE\x17"
|
31
|
-
end
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'instantiates a new connection' do
|
36
|
-
Rapns::Daemon::Apns::Connection.should_receive(:new).with(app, host, port)
|
37
|
-
receiver.check_for_feedback
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'connects to the feeback service' do
|
41
|
-
connection.should_receive(:connect)
|
42
|
-
receiver.check_for_feedback
|
43
|
-
end
|
44
|
-
|
45
|
-
it 'closes the connection' do
|
46
|
-
connection.should_receive(:close)
|
47
|
-
receiver.check_for_feedback
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'reads from the connection' do
|
51
|
-
connection.should_receive(:read).with(38)
|
52
|
-
receiver.check_for_feedback
|
53
|
-
end
|
54
|
-
|
55
|
-
it 'logs the feedback' do
|
56
|
-
double_connection_read_with_tuple
|
57
|
-
Rapns.logger.should_receive(:info).with("[my_app] [FeedbackReceiver] Delivery failed at 2011-12-10 16:08:45 UTC for 834f786655eb9f84614a05ad7d00af31e5cfe93ac3ea078f1da44d2a4eb0ce17.")
|
58
|
-
receiver.check_for_feedback
|
59
|
-
end
|
60
|
-
|
61
|
-
it 'creates the feedback' do
|
62
|
-
Rapns::Daemon.store.should_receive(:create_apns_feedback).with(Time.at(1323533325), '834f786655eb9f84614a05ad7d00af31e5cfe93ac3ea078f1da44d2a4eb0ce17', app)
|
63
|
-
double_connection_read_with_tuple
|
64
|
-
receiver.check_for_feedback
|
65
|
-
end
|
66
|
-
|
67
|
-
it 'logs errors' do
|
68
|
-
error = StandardError.new('bork!')
|
69
|
-
connection.stub(:read).and_raise(error)
|
70
|
-
Rapns.logger.should_receive(:error).with(error)
|
71
|
-
receiver.check_for_feedback
|
72
|
-
end
|
73
|
-
|
74
|
-
it 'sleeps for the feedback poll period' do
|
75
|
-
receiver.stub(:check_for_feedback)
|
76
|
-
sleeper = double(Rapns::Daemon::InterruptibleSleep, :sleep => false)
|
77
|
-
sleeper.should_receive(:sleep).with(60).at_least(:once)
|
78
|
-
receiver.stub :interruptible_sleep => sleeper
|
79
|
-
Thread.stub(:new).and_yield
|
80
|
-
receiver.stub(:loop).and_yield
|
81
|
-
receiver.start
|
82
|
-
end
|
83
|
-
|
84
|
-
it 'checks for feedback when started' do
|
85
|
-
sleeper = double(Rapns::Daemon::InterruptibleSleep, :sleep => false)
|
86
|
-
receiver.stub :interruptible_sleep => sleeper
|
87
|
-
receiver.should_receive(:check_for_feedback).at_least(:once)
|
88
|
-
Thread.stub(:new).and_yield
|
89
|
-
receiver.stub(:loop).and_yield
|
90
|
-
receiver.start
|
91
|
-
end
|
92
|
-
|
93
|
-
it 'interrupts sleep when stopped' do
|
94
|
-
sleeper = double(Rapns::Daemon::InterruptibleSleep, :sleep => false)
|
95
|
-
receiver.stub :interruptible_sleep => sleeper
|
96
|
-
receiver.stub(:check_for_feedback)
|
97
|
-
sleeper.should_receive(:interrupt_sleep)
|
98
|
-
receiver.stop
|
99
|
-
end
|
100
|
-
|
101
|
-
it 'reflects feedback was received' do
|
102
|
-
double_connection_read_with_tuple
|
103
|
-
receiver.should_receive(:reflect).with(:apns_feedback, feedback)
|
104
|
-
receiver.check_for_feedback
|
105
|
-
end
|
106
|
-
|
107
|
-
it 'calls the apns_feedback_callback when feedback is received and the callback is set' do
|
108
|
-
double_connection_read_with_tuple
|
109
|
-
Rapns.config.apns_feedback_callback = Proc.new {}
|
110
|
-
Rapns.config.apns_feedback_callback.should_receive(:call).with(feedback)
|
111
|
-
receiver.check_for_feedback
|
112
|
-
end
|
113
|
-
|
114
|
-
it 'catches exceptions in the apns_feedback_callback' do
|
115
|
-
error = StandardError.new('bork!')
|
116
|
-
double_connection_read_with_tuple
|
117
|
-
callback = Proc.new { raise error }
|
118
|
-
Rapns::Deprecation.muted do
|
119
|
-
Rapns.config.on_apns_feedback &callback
|
120
|
-
end
|
121
|
-
lambda { receiver.check_for_feedback }.should_not raise_error
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'logs an exception from the apns_feedback_callback' do
|
125
|
-
error = StandardError.new('bork!')
|
126
|
-
double_connection_read_with_tuple
|
127
|
-
callback = Proc.new { raise error }
|
128
|
-
Rapns.logger.should_receive(:error).with(error)
|
129
|
-
Rapns::Deprecation.muted do
|
130
|
-
Rapns.config.on_apns_feedback &callback
|
131
|
-
end
|
132
|
-
receiver.check_for_feedback
|
133
|
-
end
|
134
|
-
end
|
@@ -1,83 +0,0 @@
|
|
1
|
-
shared_examples_for "an AppRunner subclass" do
|
2
|
-
let(:queue) { double(:push => nil) }
|
3
|
-
|
4
|
-
before { Queue.stub(:new => queue) }
|
5
|
-
after { Rapns::Daemon::AppRunner.runners.clear }
|
6
|
-
|
7
|
-
describe 'start' do
|
8
|
-
it 'starts a delivery handler for each connection' do
|
9
|
-
handler.should_receive(:start)
|
10
|
-
runner.start
|
11
|
-
end
|
12
|
-
|
13
|
-
it 'adds the delivery handler to the collection' do
|
14
|
-
handler_collection.should_receive(:push).with(handler)
|
15
|
-
runner.start
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'assigns the queue to the handler' do
|
19
|
-
handler.should_receive(:queue=).with(queue)
|
20
|
-
runner.start
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
describe 'enqueue' do
|
25
|
-
let(:notification) { double }
|
26
|
-
let(:batch) { double(:notifications => [notification]) }
|
27
|
-
|
28
|
-
it 'enqueues the batch' do
|
29
|
-
queue.should_receive(:push).with([notification, batch])
|
30
|
-
runner.enqueue(batch)
|
31
|
-
end
|
32
|
-
|
33
|
-
it 'reflects the notification has been enqueued' do
|
34
|
-
runner.should_receive(:reflect).with(:notification_enqueued, notification)
|
35
|
-
runner.enqueue(batch)
|
36
|
-
end
|
37
|
-
end
|
38
|
-
|
39
|
-
describe 'stop' do
|
40
|
-
before { runner.start }
|
41
|
-
|
42
|
-
it 'stops the delivery handlers' do
|
43
|
-
handler_collection.should_receive(:stop)
|
44
|
-
runner.stop
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
describe 'idle?' do
|
49
|
-
it 'is idle if all notifications have been processed' do
|
50
|
-
runner.batch = double(:complete? => true)
|
51
|
-
runner.idle?.should be_true
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'is idle if the runner has no associated batch' do
|
55
|
-
runner.batch = nil
|
56
|
-
runner.idle?.should be_true
|
57
|
-
end
|
58
|
-
|
59
|
-
it 'is not idle if not all notifications have been processed' do
|
60
|
-
runner.batch = double(:complete? => false)
|
61
|
-
runner.idle?.should be_false
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
describe 'sync' do
|
66
|
-
before { runner.start }
|
67
|
-
|
68
|
-
it 'reduces the number of handlers if needed' do
|
69
|
-
handler_collection.should_receive(:pop)
|
70
|
-
new_app = app_class.new
|
71
|
-
new_app.stub(:connections => app.connections - 1)
|
72
|
-
runner.sync(new_app)
|
73
|
-
end
|
74
|
-
|
75
|
-
it 'increases the number of handlers if needed' do
|
76
|
-
runner.should_receive(:start_handler).and_return(handler)
|
77
|
-
handler_collection.should_receive(:push).with(handler)
|
78
|
-
new_app = app_class.new
|
79
|
-
new_app.stub(:connections => app.connections + 1)
|
80
|
-
runner.sync(new_app)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
@@ -1,170 +0,0 @@
|
|
1
|
-
require File.expand_path("spec/unit_spec_helper")
|
2
|
-
|
3
|
-
describe Rapns::Daemon::AppRunner, 'stop' do
|
4
|
-
let(:runner) { double }
|
5
|
-
before { Rapns::Daemon::AppRunner.runners['app'] = runner }
|
6
|
-
after { Rapns::Daemon::AppRunner.runners.clear }
|
7
|
-
|
8
|
-
it 'stops all runners' do
|
9
|
-
runner.should_receive(:stop)
|
10
|
-
Rapns::Daemon::AppRunner.stop
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
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) }
|
19
|
-
|
20
|
-
before do
|
21
|
-
Rapns.stub(:logger => logger)
|
22
|
-
Rapns::Daemon::AppRunner.runners[1] = runner
|
23
|
-
end
|
24
|
-
|
25
|
-
after { Rapns::Daemon::AppRunner.runners.clear }
|
26
|
-
|
27
|
-
it 'batches notifications by app' do
|
28
|
-
batch = double
|
29
|
-
batch.stub!(:describe)
|
30
|
-
Rapns::Daemon::Batch.stub(:new => batch)
|
31
|
-
Rapns::Daemon::Batch.should_receive(:new).with([notification1])
|
32
|
-
Rapns::Daemon::Batch.should_receive(:new).with([notification2])
|
33
|
-
Rapns::Daemon::AppRunner.enqueue([notification1, notification2])
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'enqueues each batch' do
|
37
|
-
runner.should_receive(:enqueue).with(kind_of(Rapns::Daemon::Batch))
|
38
|
-
Rapns::Daemon::AppRunner.enqueue([notification1])
|
39
|
-
end
|
40
|
-
|
41
|
-
it 'logs an error if there is no runner to deliver the notification' do
|
42
|
-
notification1.stub(:app_id => 2, :id => 123)
|
43
|
-
notification2.stub(:app_id => 2, :id => 456)
|
44
|
-
logger.should_receive(:error).with("No such app '#{notification1.app_id}' for notifications 123, 456.")
|
45
|
-
Rapns::Daemon::AppRunner.enqueue([notification1, notification2])
|
46
|
-
end
|
47
|
-
end
|
48
|
-
|
49
|
-
describe Rapns::Daemon::AppRunner, 'sync' do
|
50
|
-
let(:app) { Rapns::Apns::App.new }
|
51
|
-
let(:new_app) { Rapns::Apns::App.new }
|
52
|
-
let(:runner) { double(:sync => nil, :stop => nil, :start => nil) }
|
53
|
-
let(:logger) { double(:error => nil, :warn => nil) }
|
54
|
-
let(:queue) { Queue.new }
|
55
|
-
|
56
|
-
before do
|
57
|
-
app.stub(:id => 1)
|
58
|
-
new_app.stub(:id => 2)
|
59
|
-
Queue.stub(:new => queue)
|
60
|
-
Rapns::Daemon::AppRunner.runners[app.id] = runner
|
61
|
-
Rapns::App.stub(:all => [app])
|
62
|
-
Rapns.stub(:logger => logger)
|
63
|
-
end
|
64
|
-
|
65
|
-
after { Rapns::Daemon::AppRunner.runners.clear }
|
66
|
-
|
67
|
-
it 'loads all apps' do
|
68
|
-
Rapns::App.should_receive(:all)
|
69
|
-
Rapns::Daemon::AppRunner.sync
|
70
|
-
end
|
71
|
-
|
72
|
-
it 'instructs existing runners to sync' do
|
73
|
-
runner.should_receive(:sync).with(app)
|
74
|
-
Rapns::Daemon::AppRunner.sync
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'starts a runner for a new app' do
|
78
|
-
Rapns::App.stub(:all => [app, new_app])
|
79
|
-
new_runner = double
|
80
|
-
Rapns::Daemon::Apns::AppRunner.should_receive(:new).with(new_app).and_return(new_runner)
|
81
|
-
new_runner.should_receive(:start)
|
82
|
-
Rapns::Daemon::AppRunner.sync
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'deletes old apps' do
|
86
|
-
Rapns::App.stub(:all => [])
|
87
|
-
runner.should_receive(:stop)
|
88
|
-
Rapns::Daemon::AppRunner.sync
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'logs an error if the app could not be started' do
|
92
|
-
Rapns::App.stub(:all => [app, new_app])
|
93
|
-
new_runner = double
|
94
|
-
Rapns::Daemon::Apns::AppRunner.should_receive(:new).with(new_app).and_return(new_runner)
|
95
|
-
new_runner.stub(:start).and_raise(StandardError)
|
96
|
-
Rapns.logger.should_receive(:error)
|
97
|
-
Rapns::Daemon::AppRunner.sync
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'reflects errors if the app could not be started' do
|
101
|
-
Rapns::App.stub(:all => [app, new_app])
|
102
|
-
new_runner = double
|
103
|
-
Rapns::Daemon::Apns::AppRunner.should_receive(:new).with(new_app).and_return(new_runner)
|
104
|
-
e = StandardError.new
|
105
|
-
new_runner.stub(:start).and_raise(e)
|
106
|
-
Rapns::Daemon::AppRunner.should_receive(:reflect).with(:error, e)
|
107
|
-
Rapns::Daemon::AppRunner.sync
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe Rapns::Daemon::AppRunner, 'debug' do
|
112
|
-
let!(:app) { Rapns::Apns::App.create!(:name => 'test', :connections => 1,
|
113
|
-
:environment => 'development', :certificate => TEST_CERT) }
|
114
|
-
let(:logger) { double(:info => nil) }
|
115
|
-
|
116
|
-
before do
|
117
|
-
Rapns::Daemon.stub(:config => {})
|
118
|
-
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new => double.as_null_object)
|
119
|
-
Rapns::Daemon::Apns::Connection.stub(:new => double.as_null_object)
|
120
|
-
Rapns.stub(:logger => logger)
|
121
|
-
Rapns::Daemon::AppRunner.sync
|
122
|
-
end
|
123
|
-
|
124
|
-
after { Rapns::Daemon::AppRunner.runners.clear }
|
125
|
-
|
126
|
-
it 'prints debug app states to the log' do
|
127
|
-
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")
|
128
|
-
Rapns::Daemon::AppRunner.debug
|
129
|
-
end
|
130
|
-
end
|
131
|
-
|
132
|
-
describe Rapns::Daemon::AppRunner, 'idle' do
|
133
|
-
let!(:app) { Rapns::Apns::App.create!(:name => 'test', :connections => 1,
|
134
|
-
:environment => 'development', :certificate => TEST_CERT) }
|
135
|
-
let(:logger) { double(:info => nil) }
|
136
|
-
|
137
|
-
before do
|
138
|
-
Rapns.stub(:logger => logger)
|
139
|
-
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new => double.as_null_object)
|
140
|
-
Rapns::Daemon::Apns::Connection.stub(:new => double.as_null_object)
|
141
|
-
Rapns::Daemon::AppRunner.sync
|
142
|
-
end
|
143
|
-
|
144
|
-
after { Rapns::Daemon::AppRunner.runners.clear }
|
145
|
-
|
146
|
-
it 'returns idle runners' do
|
147
|
-
runner = Rapns::Daemon::AppRunner.runners[app.id]
|
148
|
-
Rapns::Daemon::AppRunner.idle.should == [runner]
|
149
|
-
end
|
150
|
-
end
|
151
|
-
|
152
|
-
describe Rapns::Daemon::AppRunner, 'wait' do
|
153
|
-
let!(:app) { Rapns::Apns::App.create!(:name => 'test', :connections => 1,
|
154
|
-
:environment => 'development', :certificate => TEST_CERT) }
|
155
|
-
let(:logger) { double(:info => nil) }
|
156
|
-
|
157
|
-
before do
|
158
|
-
Rapns.stub(:logger => logger)
|
159
|
-
Rapns::Daemon::Apns::FeedbackReceiver.stub(:new => double.as_null_object)
|
160
|
-
Rapns::Daemon::Apns::Connection.stub(:new => double.as_null_object)
|
161
|
-
Rapns::Daemon::AppRunner.sync
|
162
|
-
end
|
163
|
-
|
164
|
-
after { Rapns::Daemon::AppRunner.runners.clear }
|
165
|
-
|
166
|
-
it 'waits until all runners are idle' do
|
167
|
-
Rapns::Daemon::AppRunner.runners.count.should == 1
|
168
|
-
Timeout.timeout(5) { Rapns::Daemon::AppRunner.wait }
|
169
|
-
end
|
170
|
-
end
|