message_bus 0.9.5 → 0.9.6
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.
Potentially problematic release.
This version of message_bus might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/lib/message_bus/connection_manager.rb +24 -1
- data/lib/message_bus/version.rb +1 -1
- data/spec/lib/client_spec.rb +3 -3
- data/spec/lib/connection_manager_spec.rb +34 -0
- data/spec/spec_helper.rb +9 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f439c4637f8f2b6271244a4ed2e3ab2637ff6c79
|
4
|
+
data.tar.gz: a35a858e95c8b3b218ba29e0773296420bf9f69b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ad5513fdaaadb637035aab15cc4d8edf76e5c8bee0774cdf90a90e3f5eb725abb987de5a4072213ba447b77f600113755330772d7169c75104e9bba816a8f6e
|
7
|
+
data.tar.gz: 72e05629c7e15d6d19cd3bf78238a3def6cb96007668ca4031e930f0b6fbb66f19524c55028ce9fdbc16aa9a3bb8e47ded98434e70ba60445731e5e599fe82b1
|
@@ -1,6 +1,29 @@
|
|
1
1
|
require 'json' unless defined? ::JSON
|
2
2
|
|
3
3
|
class MessageBus::ConnectionManager
|
4
|
+
require 'monitor'
|
5
|
+
|
6
|
+
class SynchronizedSet
|
7
|
+
include MonitorMixin
|
8
|
+
|
9
|
+
def initialize
|
10
|
+
super
|
11
|
+
@set = Set.new
|
12
|
+
end
|
13
|
+
|
14
|
+
def self.synchronize(methods)
|
15
|
+
methods.each do |method|
|
16
|
+
define_method method do |*args, &blk|
|
17
|
+
synchronize do
|
18
|
+
@set.send method,*args,&blk
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
synchronize(Set.new.methods - Object.new.methods)
|
25
|
+
|
26
|
+
end
|
4
27
|
|
5
28
|
def initialize(bus = nil)
|
6
29
|
@clients = {}
|
@@ -75,7 +98,7 @@ class MessageBus::ConnectionManager
|
|
75
98
|
def subscribe_client(client,channel)
|
76
99
|
set = @subscriptions[client.site_id][channel]
|
77
100
|
unless set
|
78
|
-
set =
|
101
|
+
set = SynchronizedSet.new
|
79
102
|
@subscriptions[client.site_id][channel] = set
|
80
103
|
end
|
81
104
|
set << client.client_id
|
data/lib/message_bus/version.rb
CHANGED
data/spec/lib/client_spec.rb
CHANGED
@@ -31,18 +31,18 @@ describe MessageBus::Client do
|
|
31
31
|
|
32
32
|
it "denies users that are not members of group" do
|
33
33
|
@client.group_ids = [77,0,10]
|
34
|
-
@client.allowed?(@message).should
|
34
|
+
@client.allowed?(@message).should == false
|
35
35
|
end
|
36
36
|
|
37
37
|
it "allows users that are members of group" do
|
38
38
|
@client.group_ids = [1,2,3]
|
39
|
-
@client.allowed?(@message).should
|
39
|
+
@client.allowed?(@message).should == true
|
40
40
|
end
|
41
41
|
|
42
42
|
it "allows all users if groups not set" do
|
43
43
|
@message.group_ids = nil
|
44
44
|
@client.group_ids = [77,0,10]
|
45
|
-
@client.allowed?(@message).should
|
45
|
+
@client.allowed?(@message).should == true
|
46
46
|
end
|
47
47
|
end
|
48
48
|
end
|
@@ -6,6 +6,7 @@ class FakeAsync
|
|
6
6
|
attr_accessor :cleanup_timer
|
7
7
|
|
8
8
|
def <<(val)
|
9
|
+
sleep 0.01 # simulate IO
|
9
10
|
@sent ||= ""
|
10
11
|
@sent << val
|
11
12
|
end
|
@@ -79,6 +80,39 @@ describe MessageBus::ConnectionManager do
|
|
79
80
|
@manager.notify_clients(m)
|
80
81
|
@resp.sent.should == nil
|
81
82
|
end
|
83
|
+
end
|
84
|
+
|
85
|
+
describe MessageBus::ConnectionManager, "notifying and subscribing concurrently" do
|
86
|
+
|
87
|
+
it "is thread-safe" do
|
88
|
+
@bus = MessageBus
|
89
|
+
@manager = MessageBus::ConnectionManager.new(@bus)
|
82
90
|
|
91
|
+
client_threads = 10.times.map do |id|
|
92
|
+
Thread.new do
|
93
|
+
expect {
|
94
|
+
@client = MessageBus::Client.new(client_id: "xyz_#{id}", site_id: 10)
|
95
|
+
@resp = FakeAsync.new
|
96
|
+
@client.async_response = @resp
|
97
|
+
@client.subscribe("test", -1)
|
98
|
+
@manager.add_client(@client)
|
99
|
+
@client.cleanup_timer = FakeTimer.new
|
100
|
+
}.not_to raise_error
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
subscriber_threads = 10.times.map do |id|
|
105
|
+
Thread.new do
|
106
|
+
expect {
|
107
|
+
m = MessageBus::Message.new(1,id,"test","data_#{id}")
|
108
|
+
m.site_id = 10
|
109
|
+
@manager.notify_clients(m)
|
110
|
+
}.not_to raise_error
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
client_threads.each(&:join)
|
115
|
+
subscriber_threads.each(&:join)
|
116
|
+
end
|
83
117
|
|
84
118
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,6 +1,15 @@
|
|
1
1
|
require 'thin'
|
2
2
|
require 'lib/fake_async_middleware'
|
3
3
|
|
4
|
+
RSpec.configure do |config|
|
5
|
+
config.expect_with :rspec do |c|
|
6
|
+
c.syntax = [:should, :expect]
|
7
|
+
end
|
8
|
+
config.mock_with :rspec do |mocks|
|
9
|
+
mocks.syntax = :should
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
4
13
|
def wait_for(timeout_milliseconds)
|
5
14
|
timeout = (timeout_milliseconds + 0.0) / 1000
|
6
15
|
finish = Time.now + timeout
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: message_bus
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-
|
11
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|