rpush 2.2.0 → 2.3.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +10 -0
  3. data/README.md +17 -9
  4. data/lib/generators/rpush_migration_generator.rb +1 -1
  5. data/lib/rpush.rb +4 -1
  6. data/lib/rpush/apns_feedback.rb +1 -1
  7. data/lib/rpush/cli.rb +25 -22
  8. data/lib/rpush/client/active_model/apns/app.rb +1 -1
  9. data/lib/rpush/client/active_model/apns/notification.rb +2 -2
  10. data/lib/rpush/client/active_model/wpns/notification.rb +7 -1
  11. data/lib/rpush/configuration.rb +32 -22
  12. data/lib/rpush/daemon.rb +18 -9
  13. data/lib/rpush/daemon/adm/delivery.rb +4 -1
  14. data/lib/rpush/daemon/apns/delivery.rb +3 -0
  15. data/lib/rpush/daemon/apns/feedback_receiver.rb +6 -2
  16. data/lib/rpush/daemon/app_runner.rb +11 -16
  17. data/lib/rpush/daemon/batch.rb +9 -0
  18. data/lib/rpush/daemon/delivery.rb +10 -2
  19. data/lib/rpush/daemon/delivery_error.rb +3 -3
  20. data/lib/rpush/daemon/dispatcher/apns_tcp.rb +11 -11
  21. data/lib/rpush/daemon/dispatcher/tcp.rb +2 -10
  22. data/lib/rpush/daemon/gcm/delivery.rb +13 -7
  23. data/lib/rpush/daemon/signal_handler.rb +5 -3
  24. data/lib/rpush/daemon/store/active_record.rb +14 -0
  25. data/lib/rpush/daemon/store/interface.rb +2 -1
  26. data/lib/rpush/daemon/store/redis.rb +3 -0
  27. data/lib/rpush/daemon/tcp_connection.rb +47 -17
  28. data/lib/rpush/daemon/wpns/delivery.rb +19 -10
  29. data/lib/rpush/logger.rb +30 -12
  30. data/lib/rpush/plugin.rb +44 -0
  31. data/lib/rpush/push.rb +1 -1
  32. data/lib/rpush/reflectable.rb +11 -0
  33. data/lib/rpush/{reflection.rb → reflection_collection.rb} +1 -9
  34. data/lib/rpush/reflection_public_methods.rb +9 -0
  35. data/lib/rpush/version.rb +1 -1
  36. data/lib/tasks/test.rake +6 -4
  37. data/spec/functional/adm_spec.rb +12 -0
  38. data/spec/functional/apns_spec.rb +61 -42
  39. data/spec/functional/gcm_spec.rb +9 -0
  40. data/spec/functional/retry_spec.rb +1 -1
  41. data/spec/functional/wpns_spec.rb +44 -11
  42. data/spec/spec_helper.rb +2 -0
  43. data/spec/unit/apns_feedback_spec.rb +2 -2
  44. data/spec/unit/client/active_record/apns/app_spec.rb +2 -2
  45. data/spec/unit/client/active_record/apns/notification_spec.rb +1 -2
  46. data/spec/unit/client/active_record/wpns/notification_spec.rb +9 -3
  47. data/spec/unit/configuration_spec.rb +1 -0
  48. data/spec/unit/daemon/adm/delivery_spec.rb +0 -1
  49. data/spec/unit/daemon/apns/feedback_receiver_spec.rb +0 -1
  50. data/spec/unit/daemon/app_runner_spec.rb +14 -9
  51. data/spec/unit/daemon/delivery_spec.rb +0 -1
  52. data/spec/unit/daemon/dispatcher/tcp_spec.rb +0 -7
  53. data/spec/unit/daemon/gcm/delivery_spec.rb +1 -1
  54. data/spec/unit/daemon/signal_handler_spec.rb +5 -1
  55. data/spec/unit/daemon/store/active_record_spec.rb +1 -1
  56. data/spec/unit/daemon/tcp_connection_spec.rb +18 -18
  57. data/spec/unit/daemon/wpns/delivery_spec.rb +1 -1
  58. data/spec/unit/daemon_spec.rb +10 -2
  59. data/spec/unit/logger_spec.rb +0 -1
  60. data/spec/unit/plugin_spec.rb +36 -0
  61. data/spec/unit/push_spec.rb +2 -2
  62. data/spec/unit/{daemon/reflectable_spec.rb → reflectable_spec.rb} +6 -6
  63. data/spec/unit/{reflection_spec.rb → reflection_collection_spec.rb} +4 -8
  64. metadata +16 -18
  65. data/lib/rpush/daemon/reflectable.rb +0 -11
  66. data/spec/integration/rpush_spec.rb +0 -13
  67. data/spec/integration/support/gcm_success_response.json +0 -1
  68. data/spec/support/install.sh +0 -68
@@ -7,7 +7,7 @@ describe 'Retries' do
7
7
  let(:http) { double(Net::HTTP::Persistent, request: response, shutdown: nil) }
8
8
 
9
9
  before do
10
- Rpush::Daemon.initialize_store
10
+ Rpush::Daemon.common_init
11
11
 
12
12
  app.name = 'test'
13
13
  app.auth_key = 'abc123'
@@ -2,7 +2,8 @@ require 'functional_spec_helper'
2
2
 
3
3
  describe 'WPNs' do
4
4
  let(:app) { Rpush::Wpns::App.new }
5
- let(:notification) { Rpush::Wpns::Notification.new }
5
+ let(:notification_with_data) { Rpush::Wpns::Notification.new }
6
+ let(:notification_with_alert) { Rpush::Wpns::Notification.new }
6
7
  let(:response) { double(Net::HTTPResponse, code: 200) }
7
8
  let(:http) { double(Net::HTTP::Persistent, request: response, shutdown: nil) }
8
9
 
@@ -10,29 +11,61 @@ describe 'WPNs' do
10
11
  app.name = 'test'
11
12
  app.save!
12
13
 
13
- notification.app = app
14
- notification.uri = 'http://sn1.notify.live.net/'
15
- notification.alert = 'test'
16
- notification.save!
14
+ notification_with_data.app = app
15
+ notification_with_data.uri = 'http://sn1.notify.live.net/'
16
+ notification_with_data.data = { title: "MyApp", body: "test", param: "new_user" }
17
+ notification_with_data.save!
18
+
19
+ notification_with_alert.app = app
20
+ notification_with_alert.uri = 'http://sn1.notify.live.net/'
21
+ notification_with_alert.alert = "Hello world!"
22
+ notification_with_alert.save!
17
23
 
18
24
  Net::HTTP::Persistent.stub(new: http)
19
25
  end
20
26
 
21
- it 'delivers a notification successfully' do
27
+ it 'delivers a notification with data successfully' do
22
28
  response.stub(to_hash: { 'x-notificationstatus' => ['Received'] })
23
29
 
24
30
  expect do
25
31
  Rpush.push
26
- notification.reload
27
- end.to change(notification, :delivered).to(true)
32
+ notification_with_data.reload
33
+ end.to change(notification_with_data, :delivered).to(true)
28
34
  end
29
35
 
30
- it 'fails to deliver a notification successfully' do
36
+ it 'fails to deliver a notification with data successfully' do
31
37
  response.stub(code: 400)
32
38
 
33
39
  expect do
34
40
  Rpush.push
35
- notification.reload
36
- end.to_not change(notification, :delivered).to(true)
41
+ notification_with_data.reload
42
+ end.to_not change(notification_with_data, :delivered).to(true)
43
+ end
44
+
45
+ it 'delivers a notification with an alert successfully' do
46
+ response.stub(to_hash: { 'x-notificationstatus' => ['Received'] })
47
+
48
+ expect do
49
+ Rpush.push
50
+ notification_with_alert.reload
51
+ end.to change(notification_with_alert, :delivered).to(true)
52
+ end
53
+
54
+ it 'fails to deliver a notification with an alert successfully' do
55
+ response.stub(code: 400)
56
+
57
+ expect do
58
+ Rpush.push
59
+ notification_with_alert.reload
60
+ end.to_not change(notification_with_alert, :delivered).to(true)
61
+ end
62
+
63
+ it 'retries notification that fail due to a SocketError' do
64
+ expect(http).to receive(:request).and_raise(SocketError.new).twice
65
+ expect(notification_with_data.deliver_after).to be_nil
66
+ expect do
67
+ Rpush.push
68
+ notification_with_data.reload
69
+ end.to change(notification_with_data, :deliver_after).to(kind_of(Time))
37
70
  end
38
71
  end
@@ -46,6 +46,8 @@ def after_example_cleanup
46
46
  Rpush.config.set_defaults if Rpush.config.is_a?(Rpush::Configuration)
47
47
  Rpush.config.client = RPUSH_CLIENT
48
48
  end
49
+ Rpush.plugins.values.each(&:unload)
50
+ Rpush.instance_variable_set('@plugins', {})
49
51
  end
50
52
 
51
53
  RSpec.configure do |config|
@@ -8,8 +8,8 @@ describe Rpush, 'apns_feedback' do
8
8
  Rpush::Daemon::Apns::FeedbackReceiver.stub(new: receiver)
9
9
  end
10
10
 
11
- it 'initializes the store' do
12
- Rpush::Daemon.should_receive(:initialize_store)
11
+ it 'initializes the daemon' do
12
+ Rpush::Daemon.should_receive(:common_init)
13
13
  Rpush.apns_feedback
14
14
  end
15
15
 
@@ -4,7 +4,7 @@ describe Rpush::Client::ActiveRecord::App do
4
4
  it 'does not validate an app with an invalid certificate' do
5
5
  app = Rpush::Client::ActiveRecord::Apns::App.new(name: 'test', environment: 'development', certificate: 'foo')
6
6
  app.valid?
7
- app.errors[:certificate].should eq ['Certificate value must contain a certificate and a private key.']
7
+ app.errors[:certificate].should eq ['value must contain a certificate and a private key.']
8
8
  end
9
9
 
10
10
  it 'validates a certificate without a password' do
@@ -24,6 +24,6 @@ describe Rpush::Client::ActiveRecord::App do
24
24
  app = Rpush::Client::ActiveRecord::Apns::App.new name: 'test', environment: 'development',
25
25
  certificate: TEST_CERT_WITH_PASSWORD, password: 'incorrect'
26
26
  app.valid?
27
- app.errors[:certificate].should eq ["Certificate value must contain a certificate and a private key."]
27
+ app.errors[:certificate].should eq ['value must contain a certificate and a private key.']
28
28
  end
29
29
  end
@@ -76,7 +76,7 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, "as_json" do
76
76
  end
77
77
 
78
78
  it "should not include the sound key if the sound is not present" do
79
- notification = Rpush::Client::ActiveRecord::Apns::Notification.new(sound: false)
79
+ notification = Rpush::Client::ActiveRecord::Apns::Notification.new(sound: nil)
80
80
  notification.as_json["aps"].key?("sound").should be_false
81
81
  end
82
82
 
@@ -92,7 +92,6 @@ describe Rpush::Client::ActiveRecord::Apns::Notification, "as_json" do
92
92
  notification.data = { omg: { ilike: :hashes } }
93
93
  notification.as_json["omg"]["ilike"].should eq "hashes"
94
94
  end
95
-
96
95
  end
97
96
 
98
97
  describe Rpush::Client::ActiveRecord::Apns::Notification, 'MDM' do
@@ -13,9 +13,15 @@ describe Rpush::Client::ActiveRecord::Wpns::Notification do
13
13
  notification.errors[:uri].include?("is invalid").should be_true
14
14
  end
15
15
 
16
- it "should be invalid if there's no message" do
17
- notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(alert: "")
16
+ it "should be invalid if there's no data" do
17
+ notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(data: {})
18
18
  notification.valid?
19
- notification.errors[:alert].include?("can't be blank").should be_true
19
+ notification.errors[:data].include?("can't be blank").should be_true
20
+ end
21
+
22
+ it "should be invalid if there's no alert" do
23
+ notification = Rpush::Client::ActiveRecord::Wpns::Notification.new(alert: nil)
24
+ notification.valid?
25
+ notification.errors[:data].include?("can't be blank").should be_true
20
26
  end
21
27
  end
@@ -39,6 +39,7 @@ describe Rpush::Configuration do
39
39
  end
40
40
 
41
41
  it 'delegate redis_options to Modis' do
42
+ Rpush.config.client = :redis
42
43
  Rpush.config.redis_options = { hi: :mom }
43
44
  Modis.redis_options.should eq(hi: :mom)
44
45
  end
@@ -87,7 +87,6 @@ describe Rpush::Daemon::Adm::Delivery do
87
87
  delivery.should_receive(:reflect).with(:adm_failed_to_recipient, notification, '1', 'Unregistered')
88
88
  expect { perform }.to raise_error
89
89
  end
90
-
91
90
  end
92
91
 
93
92
  describe 'a 401 (Unauthorized) response' do
@@ -2,7 +2,6 @@ require 'unit_spec_helper'
2
2
  require 'rpush/daemon/store/active_record'
3
3
 
4
4
  describe Rpush::Daemon::Apns::FeedbackReceiver, 'check_for_feedback' do
5
-
6
5
  let(:host) { 'feedback.push.apple.com' }
7
6
  let(:port) { 2196 }
8
7
  let(:poll) { 60 }
@@ -34,7 +34,7 @@ end
34
34
  describe Rpush::Daemon::AppRunner, 'enqueue' do
35
35
  let(:app) { double(id: 1, name: 'Test', connections: 1) }
36
36
  let(:notification) { double(app_id: 1) }
37
- let(:runner) { double(Rpush::Daemon::AppRunner, enqueue: nil, start: nil, stop: nil) }
37
+ let(:runner) { double(Rpush::Daemon::AppRunner, enqueue: nil, start_dispatchers: nil, start_loops: nil, stop: nil) }
38
38
  let(:logger) { double(Rpush::Logger, error: nil, info: nil) }
39
39
 
40
40
  before do
@@ -62,7 +62,7 @@ end
62
62
 
63
63
  describe Rpush::Daemon::AppRunner, 'start_app' do
64
64
  let(:app) { double(id: 1, name: 'test', connections: 1) }
65
- let(:runner) { double(Rpush::Daemon::AppRunner, enqueue: nil, start: nil, stop: nil) }
65
+ let(:runner) { double(Rpush::Daemon::AppRunner, enqueue: nil, start_dispatchers: nil, stop: nil) }
66
66
  let(:logger) { double(Rpush::Logger, error: nil, info: nil) }
67
67
 
68
68
  before do
@@ -71,7 +71,7 @@ describe Rpush::Daemon::AppRunner, 'start_app' do
71
71
 
72
72
  it 'logs an error if the runner could not be started' do
73
73
  Rpush::Daemon::AppRunner.should_receive(:new).with(app).and_return(runner)
74
- runner.stub(:start).and_raise(StandardError)
74
+ runner.stub(:start_dispatchers).and_raise(StandardError)
75
75
  Rpush.logger.should_receive(:error)
76
76
  Rpush::Daemon::AppRunner.start_app(app)
77
77
  end
@@ -80,7 +80,8 @@ end
80
80
  describe Rpush::Daemon::AppRunner, 'debug' do
81
81
  let(:app) do
82
82
  double(Rpush::AppRunnerSpecService::App, id: 1, name: 'test', connections: 1,
83
- environment: 'development', certificate: TEST_CERT, service_name: 'app_runner_spec_service')
83
+ environment: 'development', certificate: TEST_CERT,
84
+ service_name: 'app_runner_spec_service')
84
85
  end
85
86
  let(:logger) { double(Rpush::Logger, info: nil) }
86
87
  let(:store) { double(all_apps: [app], release_connection: nil) }
@@ -102,7 +103,8 @@ end
102
103
  describe Rpush::Daemon::AppRunner do
103
104
  let(:app) do
104
105
  double(Rpush::AppRunnerSpecService::App, environment: :sandbox,
105
- connections: 1, service_name: 'app_runner_spec_service', name: 'test')
106
+ connections: 1, service_name: 'app_runner_spec_service',
107
+ name: 'test')
106
108
  end
107
109
  let(:runner) { Rpush::Daemon::AppRunner.new(app) }
108
110
  let(:logger) { double(Rpush::Logger, info: nil) }
@@ -122,18 +124,18 @@ describe Rpush::Daemon::AppRunner do
122
124
  describe 'start' do
123
125
  it 'starts a delivery dispatcher for each connection' do
124
126
  app.stub(connections: 2)
125
- runner.start
127
+ runner.start_dispatchers
126
128
  runner.num_dispatcher_loops.should eq 2
127
129
  end
128
130
 
129
131
  it 'starts the dispatcher loop' do
130
132
  dispatcher_loop.should_receive(:start)
131
- runner.start
133
+ runner.start_dispatchers
132
134
  end
133
135
 
134
136
  it 'starts the loops' do
135
137
  service_loop.should_receive(:start)
136
- runner.start
138
+ runner.start_loops
137
139
  end
138
140
  end
139
141
 
@@ -169,7 +171,10 @@ describe Rpush::Daemon::AppRunner do
169
171
  end
170
172
 
171
173
  describe 'stop' do
172
- before { runner.start }
174
+ before do
175
+ runner.start_dispatchers
176
+ runner.start_loops
177
+ end
173
178
 
174
179
  it 'stops the delivery dispatchers' do
175
180
  dispatcher_loop.should_receive(:stop)
@@ -1,7 +1,6 @@
1
1
  require 'unit_spec_helper'
2
2
 
3
3
  describe Rpush::Daemon::Delivery do
4
-
5
4
  class DeliverySpecDelivery < Rpush::Daemon::Delivery
6
5
  def initialize(batch)
7
6
  @batch = batch
@@ -16,12 +16,6 @@ describe Rpush::Daemon::Dispatcher::Tcp do
16
16
  before { Rpush::Daemon::TcpConnection.stub(new: connection) }
17
17
 
18
18
  describe 'dispatch' do
19
- it 'lazily connects the socket' do
20
- Rpush::Daemon::TcpConnection.should_receive(:new).with(app, host, port).and_return(connection)
21
- connection.should_receive(:connect)
22
- dispatcher.dispatch(queue_payload)
23
- end
24
-
25
19
  it 'delivers the notification' do
26
20
  delivery_class.should_receive(:new).with(app, connection, notification, batch).and_return(delivery)
27
21
  delivery.should_receive(:perform)
@@ -31,7 +25,6 @@ describe Rpush::Daemon::Dispatcher::Tcp do
31
25
 
32
26
  describe 'cleanup' do
33
27
  it 'closes the connection' do
34
- dispatcher.dispatch(queue_payload) # lazily initialize connection
35
28
  connection.should_receive(:close)
36
29
  dispatcher.cleanup
37
30
  end
@@ -291,7 +291,7 @@ describe Rpush::Daemon::Gcm::Delivery do
291
291
  it 'logs a warning that the notification has been re-queued.' do
292
292
  notification.retries = 3
293
293
  notification.deliver_after = now + 2**3
294
- Rpush.logger.should_receive(:warn).with("[MyApp] GCM responded with an Internal Error. Notification #{notification.id} will be retried after #{(now + 2**3).strftime("%Y-%m-%d %H:%M:%S")} (retry 3).")
294
+ Rpush.logger.should_receive(:warn).with("[MyApp] GCM responded with an Internal Error. Notification #{notification.id} will be retried after #{(now + 2**3).strftime('%Y-%m-%d %H:%M:%S')} (retry 3).")
295
295
  perform
296
296
  end
297
297
 
@@ -44,6 +44,7 @@ describe Rpush::Daemon::SignalHandler do
44
44
  before do
45
45
  Rpush::Daemon::Synchronizer.stub(:sync)
46
46
  Rpush::Daemon::Feeder.stub(:wakeup)
47
+ Rpush::Daemon.stub(store: double(reopen_log: nil))
47
48
  end
48
49
 
49
50
  it 'syncs' do
@@ -73,7 +74,10 @@ describe Rpush::Daemon::SignalHandler do
73
74
  describe 'error handing' do
74
75
  let(:error) { StandardError.new('test') }
75
76
 
76
- before { Rpush.stub(logger: double(error: nil, info: nil)) }
77
+ before do
78
+ Rpush.stub(logger: double(error: nil, info: nil, reopen: nil))
79
+ Rpush::Daemon.stub(store: double(reopen_log: nil))
80
+ end
77
81
 
78
82
  it 'logs errors received when handling a signal' do
79
83
  Rpush::Daemon::Synchronizer.stub(:sync).and_raise(error)
@@ -6,7 +6,7 @@ describe Rpush::Daemon::Store::ActiveRecord do
6
6
  let(:notification) { Rpush::Client::ActiveRecord::Apns::Notification.create!(device_token: "a" * 64, app: app) }
7
7
  let(:store) { Rpush::Daemon::Store::ActiveRecord.new }
8
8
  let(:time) { Time.now.utc }
9
- let(:logger) { double(Rpush::Logger, error: nil) }
9
+ let(:logger) { double(Rpush::Logger, error: nil, internal_logger: nil) }
10
10
 
11
11
  before do
12
12
  Rpush.stub(logger: logger)
@@ -72,12 +72,12 @@ describe Rpush::Daemon::TcpConnection do
72
72
  end
73
73
 
74
74
  it "sets the socket option TCP_NODELAY" do
75
- tcp_socket.should_receive(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
75
+ tcp_socket.should_receive(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, true)
76
76
  connection.connect
77
77
  end
78
78
 
79
79
  it "sets the socket option SO_KEEPALIVE" do
80
- tcp_socket.should_receive(:setsockopt).with(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, 1)
80
+ tcp_socket.should_receive(:setsockopt).with(Socket::SOL_SOCKET, Socket::SO_KEEPALIVE, true)
81
81
  connection.connect
82
82
  end
83
83
 
@@ -122,12 +122,12 @@ describe Rpush::Daemon::TcpConnection do
122
122
 
123
123
  it 'reflects that the certificate has been revoked' do
124
124
  connection.should_receive(:reflect).with(:ssl_certificate_revoked, app, cert_revoked_error)
125
- expect { connection.connect }.to raise_error(cert_revoked_error)
125
+ expect { connection.connect }.to raise_error(Rpush::Daemon::TcpConnectionError, 'OpenSSL::SSL::SSLError, certificate revoked')
126
126
  end
127
127
 
128
128
  it 'logs that the certificate has been revoked' do
129
129
  logger.should_receive(:warn).with('[Connection 0] Certificate has been revoked.')
130
- expect { connection.connect }.to raise_error(cert_revoked_error)
130
+ expect { connection.connect }.to raise_error(Rpush::Daemon::TcpConnectionError, 'OpenSSL::SSL::SSLError, certificate revoked')
131
131
  end
132
132
  end
133
133
  end
@@ -170,16 +170,16 @@ describe Rpush::Daemon::TcpConnection do
170
170
  before do
171
171
  connection.stub(:sleep)
172
172
  connection.connect
173
- ssl_socket.stub(:write).and_raise(error_type)
173
+ ssl_socket.stub(:write).and_raise(error)
174
174
  end
175
175
 
176
176
  it 'reflects the connection has been lost' do
177
- connection.should_receive(:reflect).with(:tcp_connection_lost, app, kind_of(error_type))
177
+ connection.should_receive(:reflect).with(:tcp_connection_lost, app, kind_of(error.class))
178
178
  expect { connection.write(nil) }.to raise_error(Rpush::Daemon::TcpConnectionError)
179
179
  end
180
180
 
181
181
  it "logs that the connection has been lost once only" do
182
- logger.should_receive(:error).with("[Connection 0] Lost connection to gateway.push.apple.com:2195 (#{error_type.name}), reconnecting...").once
182
+ logger.should_receive(:error).with("[Connection 0] Lost connection to gateway.push.apple.com:2195 (#{error.class.name}, #{error.message}), reconnecting...").once
183
183
  expect { connection.write(nil) }.to raise_error(Rpush::Daemon::TcpConnectionError)
184
184
  end
185
185
 
@@ -191,7 +191,7 @@ describe Rpush::Daemon::TcpConnection do
191
191
  it "raises a TcpConnectionError after 3 attempts at reconnecting" do
192
192
  expect do
193
193
  connection.write(nil)
194
- end.to raise_error(Rpush::Daemon::TcpConnectionError, "Connection 0 tried 3 times to reconnect but failed (#{error_type.name}).")
194
+ end.to raise_error(Rpush::Daemon::TcpConnectionError, "Connection 0 tried 3 times to reconnect but failed (#{error.class.name}, #{error.message}).")
195
195
  end
196
196
 
197
197
  it "sleeps 1 second before retrying the connection" do
@@ -203,32 +203,32 @@ describe Rpush::Daemon::TcpConnection do
203
203
  describe "when write raises an Errno::EPIPE" do
204
204
  it_should_behave_like "when the write fails"
205
205
 
206
- def error_type
207
- Errno::EPIPE
206
+ def error
207
+ Errno::EPIPE.new('an message')
208
208
  end
209
209
  end
210
210
 
211
211
  describe "when write raises an Errno::ETIMEDOUT" do
212
212
  it_should_behave_like "when the write fails"
213
213
 
214
- def error_type
215
- Errno::ETIMEDOUT
214
+ def error
215
+ Errno::ETIMEDOUT.new('an message')
216
216
  end
217
217
  end
218
218
 
219
219
  describe "when write raises an OpenSSL::SSL::SSLError" do
220
220
  it_should_behave_like "when the write fails"
221
221
 
222
- def error_type
223
- OpenSSL::SSL::SSLError
222
+ def error
223
+ OpenSSL::SSL::SSLError.new('an message')
224
224
  end
225
225
  end
226
226
 
227
227
  describe "when write raises an IOError" do
228
228
  it_should_behave_like "when the write fails"
229
229
 
230
- def error_type
231
- IOError
230
+ def error
231
+ IOError.new('an message')
232
232
  end
233
233
  end
234
234
 
@@ -270,11 +270,11 @@ describe Rpush::Daemon::TcpConnection do
270
270
  connection.write('blah')
271
271
  end
272
272
 
273
- it 'resets the last write time' do
273
+ it 'resets the last touch time' do
274
274
  now = Time.now
275
275
  Time.stub(now: now)
276
276
  connection.write('blah')
277
- connection.last_write.should eq now
277
+ connection.last_touch.should eq now
278
278
  end
279
279
 
280
280
  it 'does not reconnect if the connection has not been idle for more than the defined period' do