celluloid_pubsub_redis_adapter 0.3.0 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6c050f38bf54731c74e711dcdb33da27392d439d
4
- data.tar.gz: ec3e0cbbc2646a66ebbdb5f08b173146181e0483
3
+ metadata.gz: 73b79525e3545c65355fd561620dfb8cd8fad210
4
+ data.tar.gz: 6b24ec5729c9cb006128e8835ba5eb20e49db228
5
5
  SHA512:
6
- metadata.gz: 69caa7a39b0b49aaaa0aa3e8548bf7a90c0325b87b82ae5f0db8ce835517b4e514ce616825d433a76a48110748c6cf4454a773a11bf3971a3ee267368e120523
7
- data.tar.gz: 8e50eed11bc2298f5f9143f99e39df7334818692c1f96743e7da8d9dc68057f315930d63ffa588adb5652ab34e7374907ab4a03be319c965d4a799d1e76cf154
6
+ metadata.gz: 288599af4036a11117a08f7ba90e8967db0c0fd81480efd9d7b6715d468215767b25a59d9c1f5dc2443eddbf79c09d570f5cec72ca8a57961259560b8110ede0
7
+ data.tar.gz: b036226e8d2e32f5a907d7bc45670c02b0faf693c2a556720d8c49e9d149012f7f8918d66f60c76d95da142a11856c417e2d2e737630e3a1fe0af363273d36a2
data/.travis.yml CHANGED
@@ -1,15 +1,27 @@
1
+ language: ruby
1
2
  sudo: false
3
+
2
4
  cache: bundler
3
- language: ruby
5
+
6
+ bundler_args: --binstubs=./bin
7
+
4
8
  before_install:
5
9
  - "echo 'gem: --no-ri --no-rdoc' > ~/.gemrc"
6
10
  - gem install bundler
11
+ - gem update bundler
12
+
13
+ before_script:
14
+ - bundle update
15
+
16
+ install:
17
+ - bundle install --path vendor/bundle
18
+
19
+ script: bundle exec rake
20
+
7
21
  rvm:
8
- - 1.9.3
9
- - 2.0.0
10
- - 2.1.5
11
22
  - 2.2.2
12
- - 2.2.3
23
+ - 2.2.5
24
+ - 2.3.1
13
25
  env:
14
26
  - RAILS_ENV=test RACK_ENV=test
15
27
  notifications:
@@ -16,7 +16,7 @@ Gem::Specification.new do |s|
16
16
  s.test_files = s.files.grep(/^(spec)/)
17
17
  s.require_paths = ['lib']
18
18
 
19
- s.add_runtime_dependency 'celluloid_pubsub', '~> 1.0', '>= 1.0.1'
19
+ s.add_runtime_dependency 'celluloid_pubsub', '~> 1.0', '>= 1.0.3'
20
20
  s.add_runtime_dependency 'em-hiredis', '~> 0.3', '>= 0.3.0'
21
21
 
22
22
  s.add_development_dependency 'rspec', '~> 3.4', '>= 3.4'
@@ -28,7 +28,7 @@ module CelluloidPubsub
28
28
  # @return [void]
29
29
  #
30
30
  # @api public
31
- def unsubscribe(channel)
31
+ def unsubscribe(channel, data)
32
32
  super
33
33
  async.redis_action('unsubscribe', channel)
34
34
  end
@@ -61,7 +61,7 @@ module CelluloidPubsub
61
61
  # @return [void]
62
62
  #
63
63
  # @api public
64
- def unsubscribe_all
64
+ def unsubscribe_all(channel, data)
65
65
  info 'clearing connections'
66
66
  shutdown
67
67
  end
@@ -74,7 +74,7 @@ module CelluloidPubsub
74
74
  # @api public
75
75
  def shutdown
76
76
  @channels.dup.each do |channel|
77
- redis_action('unsubscribe', channel)
77
+ redis_action('unsubscribe', channel) unless ENV['RACK_ENV'] == 'test'
78
78
  end if @channels.present?
79
79
  super
80
80
  end
@@ -84,7 +84,7 @@ module CelluloidPubsub
84
84
  # @return [void]
85
85
  #
86
86
  # @api public
87
- def publish_event(topic, data)
87
+ def server_pusblish_event(topic, data)
88
88
  return if topic.blank? || data.blank?
89
89
  connect_to_redis do |connection|
90
90
  connection.publish(topic, data)
@@ -15,7 +15,7 @@ module CelluloidPubsubRedisAdapter
15
15
  # major release version
16
16
  MAJOR = 0
17
17
  # minor release version
18
- MINOR = 3
18
+ MINOR = 4
19
19
  # tiny release version
20
20
  TINY = 0
21
21
  # prelease version ( set this only if it is a prelease)
@@ -5,6 +5,7 @@ require 'spec_helper'
5
5
  describe CelluloidPubsub::RedisReactor do
6
6
  let(:websocket) { mock }
7
7
  let(:server) { mock }
8
+ let(:mutex) { mock }
8
9
 
9
10
  before(:each) do
10
11
  subject.stubs(:async).returns(subject)
@@ -13,6 +14,7 @@ describe CelluloidPubsub::RedisReactor do
13
14
  server.stubs(:handle_dispatched_message)
14
15
  server.stubs(:subscribers).returns({})
15
16
  server.stubs(:redis_enabled?).returns(false)
17
+ server.stubs(:adapter).returns(CelluloidPubsub::RedisReactor)
16
18
  websocket.stubs(:read)
17
19
  websocket.stubs(:url)
18
20
  websocket.stubs(:close)
@@ -22,6 +24,8 @@ describe CelluloidPubsub::RedisReactor do
22
24
  subject.stubs(:run)
23
25
  subject.work(websocket, server)
24
26
  subject.stubs(:unsubscribe_from_channel).returns(true)
27
+ server.stubs(:mutex).returns(mutex)
28
+ mutex.stubs(:synchronize).yields(server)
25
29
  Celluloid::Actor.stubs(:kill).returns(true)
26
30
  end
27
31
 
@@ -76,47 +80,46 @@ describe CelluloidPubsub::RedisReactor do
76
80
 
77
81
  describe '#handle_parsed_websocket_message' do
78
82
  it 'handle_websocket_message with a hash' do
79
- data = { 'client_action' => 'b' }
83
+ data = { 'client_action' => 'subscribe' }
80
84
  data.expects(:stringify_keys).returns(data)
81
85
  subject.expects(:delegate_action).with(data)
82
86
  subject.handle_parsed_websocket_message(data)
83
87
  end
84
88
 
85
89
  it 'handle_websocket_message with something else than a hash' do
86
- data = 'some message'
87
- subject.expects(:handle_unknown_action).with(data)
90
+ data = { 'message'=> 'some message' }
91
+ subject.expects(:handle_unknown_action).with(data['channel'], data)
88
92
  subject.handle_parsed_websocket_message(data)
89
93
  end
90
94
  end
91
95
 
92
96
  describe '#delegate_action' do
97
+ before(:each) do
98
+ subject.stubs(:unsubscribe_clients).returns(true)
99
+ subject.stubs(:shutdown).returns(true)
100
+ end
101
+
93
102
  it 'unsubscribes all' do
94
- data = { 'client_action' => 'unsubscribe_all' }
95
- subject.expects(:unsubscribe_all).returns('bla')
103
+ data = { 'client_action' => 'unsubscribe_all', 'channel' => '' }
104
+ subject.expects(:send).with(data['client_action'], data['channel'], data).returns('bla')
96
105
  subject.delegate_action(data)
97
106
  end
98
107
 
99
108
  it 'unsubscribes all' do
100
109
  data = { 'client_action' => 'unsubscribe', 'channel' => 'some channel' }
101
- subject.expects(:unsubscribe).with(data['channel'])
110
+ subject.expects(:send).with(data['client_action'], data['channel'], data)
102
111
  subject.delegate_action(data)
103
112
  end
104
-
113
+ #
105
114
  it 'subscribes to channell' do
106
115
  data = { 'client_action' => 'subscribe', 'channel' => 'some channel' }
107
- subject.expects(:start_subscriber).with(data['channel'], data)
116
+ subject.expects(:send).with(data['client_action'], data['channel'], data)
108
117
  subject.delegate_action(data)
109
118
  end
110
119
 
111
120
  it 'publish' do
112
121
  data = { 'client_action' => 'publish', 'channel' => 'some channel', 'data' => 'some data' }
113
- subject.expects(:publish_event).with(data['channel'], data['data'].to_json)
114
- subject.delegate_action(data)
115
- end
116
-
117
- it 'handles unknown' do
118
- data = { 'client_action' => 'some action', 'channel' => 'some channel' }
119
- subject.expects(:handle_unknown_action).with(data)
122
+ subject.expects(:send).with(data['client_action'], data['channel'], data)
120
123
  subject.delegate_action(data)
121
124
  end
122
125
  end
@@ -124,41 +127,67 @@ describe CelluloidPubsub::RedisReactor do
124
127
  describe '#handle_unknown_action' do
125
128
  it 'handles unknown' do
126
129
  data = 'some data'
130
+ channel = "some_channel"
127
131
  server.expects(:handle_dispatched_message)
128
- subject.handle_unknown_action(data)
132
+ subject.handle_unknown_action(channel, data)
129
133
  end
130
134
  end
131
135
 
132
136
  describe '#unsubscribe_client' do
133
137
  let(:channel) { 'some channel' }
138
+ let(:data) { {'client_action' => 'unsubscribe', 'channel' => channel } }
139
+
140
+ before(:each) do
141
+ subject.stubs(:redis_action).returns(nil)
142
+ end
143
+
134
144
  it 'returns nil' do
135
- act = subject.unsubscribe('')
145
+
146
+ act = subject.unsubscribe('', data)
136
147
  expect(act).to eq(nil)
137
148
  end
138
149
 
139
150
  it 'unsubscribes' do
140
- subject.channels.stubs(:blank?).returns(false)
141
- subject.channels.expects(:delete).with(channel)
142
- act = subject.unsubscribe(channel)
143
- expect(act).to eq([])
151
+ channel.stubs(:present?).returns(true)
152
+ subject.expects(:forget_channel).with(channel)
153
+ subject.expects(:delete_server_subscribers).with(channel)
154
+ act = subject.unsubscribe(channel, data)
155
+ expect(act).to eq(nil)
156
+ end
157
+ end
158
+
159
+ describe '#delete_server_subscribers' do
160
+ let(:channel) { 'some channel' }
161
+
162
+ before(:each) do
163
+ server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
144
164
  end
145
165
 
166
+ it 'unsubscribes' do
167
+ act = subject.delete_server_subscribers(channel)
168
+ expect(server.subscribers[channel]).to eq([])
169
+ end
170
+ end
171
+
172
+ describe '#forget_channel' do
173
+ let(:channel) { 'some channel' }
174
+
146
175
  it 'unsubscribes' do
147
176
  subject.channels.stubs(:blank?).returns(true)
148
177
  subject.websocket.expects(:close)
149
- act = subject.unsubscribe(channel)
150
- expect(act).to eq([])
178
+ act = subject.forget_channel(channel)
179
+ expect(act).to eq(nil)
151
180
  end
152
181
 
153
182
  it 'unsubscribes' do
154
183
  subject.channels.stubs(:blank?).returns(false)
155
- subject.channels.stubs(:delete)
156
- server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
157
- subject.unsubscribe(channel)
158
- expect(server.subscribers[channel]).to eq([])
184
+ subject.channels.expects(:delete).with(channel)
185
+ # server.stubs(:subscribers).returns("#{channel}" => [{ reactor: subject }])
186
+ subject.forget_channel(channel)
187
+ # expect(server.subscribers[channel]).to eq([])
159
188
  end
160
189
  end
161
-
190
+ #
162
191
  describe '#shutdown' do
163
192
  it 'shutdowns' do
164
193
  subject.expects(:terminate)
@@ -171,26 +200,15 @@ describe CelluloidPubsub::RedisReactor do
171
200
  let(:message) { { a: 'b' } }
172
201
 
173
202
  it 'subscribes ' do
174
- act = subject.start_subscriber('', message)
203
+ act = subject.subscribe('', message)
175
204
  expect(act).to eq(nil)
176
205
  end
177
206
 
178
207
  it 'subscribes ' do
179
208
  subject.stubs(:add_subscriber_to_channel).with(channel, message)
180
- server.stubs(:redis_enabled?).returns(false)
181
- subject.websocket.expects(:<<).with(message.merge('client_action' => 'successful_subscription', 'channel' => channel).to_json)
182
- subject.start_subscriber(channel, message)
209
+ subject.subscribe(channel, message)
183
210
  end
184
211
 
185
- # it 'raises error' do
186
- # subject.stubs(:add_subscriber_to_channel).raises(StandardError)
187
- #
188
- # expect do
189
- # subject.start_subscriber(channel, message)
190
- # end.to raise_error(StandardError) { |e|
191
- # expect(e.message).to include(channel)
192
- # }
193
- # end
194
212
  end
195
213
 
196
214
  describe '#add_subscriber_to_channel' do
@@ -198,6 +216,10 @@ describe CelluloidPubsub::RedisReactor do
198
216
  let(:message) { { a: 'b' } }
199
217
  let(:subscribers) { mock }
200
218
 
219
+ before(:each) do
220
+ subject.stubs(:redis_action).returns(nil)
221
+ end
222
+
201
223
  it 'adds subscribed' do
202
224
  CelluloidPubsub::Registry.channels.stubs(:include?).with(channel).returns(false)
203
225
  CelluloidPubsub::Registry.channels.expects(:<<).with(channel)
@@ -213,9 +235,10 @@ describe CelluloidPubsub::RedisReactor do
213
235
  let(:message) { { a: 'b' } }
214
236
 
215
237
  it 'adds subscribed' do
238
+ subject.stubs(:shutdown).returns(true)
216
239
  CelluloidPubsub::Registry.stubs(:channels).returns([channel])
217
- subject.expects(:unsubscribe_from_channel).with(channel)
218
- subject.unsubscribe_all
240
+ # subject.expects(:unsubscribe_clients)
241
+ subject.unsubscribe_all(channel, message)
219
242
  end
220
243
  end
221
244
  end
data/spec/spec_helper.rb CHANGED
@@ -14,7 +14,7 @@ formatters << Coveralls::SimpleCov::Formatter # if ENV['TRAVIS']
14
14
  SimpleCov.formatter = SimpleCov::Formatter::MultiFormatter[*formatters]
15
15
 
16
16
  Coveralls.wear!
17
- SimpleCov.start 'rails' do
17
+ SimpleCov.start do
18
18
  add_filter 'spec'
19
19
 
20
20
  at_exit {}
@@ -45,3 +45,15 @@ RSpec.configure do |config|
45
45
  end
46
46
  end
47
47
  end
48
+
49
+ unless defined?(silence_stream) # Rails 5
50
+ def silence_stream(stream)
51
+ old_stream = stream.dup
52
+ stream.reopen(RbConfig::CONFIG['host_os'] =~ /mswin|mingw/ ? 'NUL:' : '/dev/null')
53
+ stream.sync = true
54
+ yield
55
+ ensure
56
+ stream.reopen(old_stream)
57
+ old_stream.close
58
+ end
59
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: celluloid_pubsub_redis_adapter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - bogdanRada
@@ -19,7 +19,7 @@ dependencies:
19
19
  version: '1.0'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 1.0.1
22
+ version: 1.0.3
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
@@ -29,7 +29,7 @@ dependencies:
29
29
  version: '1.0'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 1.0.1
32
+ version: 1.0.3
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: em-hiredis
35
35
  requirement: !ruby/object:Gem::Requirement