message_bus 2.0.0.beta.2 → 2.0.0.beta.3

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.

@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative '../../spec_helper'
2
2
  require 'message_bus/timer_thread'
3
3
 
4
4
  describe MessageBus::TimerThread do
@@ -13,7 +13,7 @@ describe MessageBus::TimerThread do
13
13
  it "allows you to queue every jobs" do
14
14
  i = 0
15
15
  m = Mutex.new
16
- every = @timer.every(0.001){m.synchronize{i += 1}}
16
+ every = @timer.every(0.001){m.synchronize{i += 1 if i < 3}}
17
17
  # allow lots of time, cause in test mode stuff can be slow
18
18
  wait_for(1000) do
19
19
  m.synchronize do
@@ -22,14 +22,14 @@ describe MessageBus::TimerThread do
22
22
  end
23
23
  end
24
24
  sleep 0.002
25
- i.should == 3
25
+ i.must_equal 3
26
26
  end
27
27
 
28
28
  it "allows you to cancel timers" do
29
29
  success = true
30
30
  @timer.queue(0.005){success=false}.cancel
31
31
  sleep(0.006)
32
- success.should == true
32
+ success.must_equal true
33
33
  end
34
34
 
35
35
  it "queues jobs in the correct order" do
@@ -45,7 +45,7 @@ describe MessageBus::TimerThread do
45
45
  4 == results.length
46
46
  }
47
47
 
48
- results.should == [0,1,2,3]
48
+ results.must_equal [0,1,2,3]
49
49
  end
50
50
 
51
51
  it "should call the error callback if something goes wrong" do
@@ -67,7 +67,7 @@ describe MessageBus::TimerThread do
67
67
  error
68
68
  end
69
69
 
70
- error.class.should == NameError
70
+ error.class.must_equal NameError
71
71
  end
72
72
 
73
73
  end
@@ -1,4 +1,4 @@
1
- require 'spec_helper'
1
+ require_relative '../spec_helper'
2
2
  require 'message_bus'
3
3
  require 'redis'
4
4
 
@@ -10,7 +10,7 @@ describe MessageBus do
10
10
  @bus.site_id_lookup do
11
11
  "magic"
12
12
  end
13
- @bus.redis_config = {}
13
+ @bus.redis_config = MESSAGE_BUS_CONFIG
14
14
  end
15
15
 
16
16
  after do
@@ -29,7 +29,7 @@ describe MessageBus do
29
29
 
30
30
  wait_for(2000){ client_ids}
31
31
 
32
- client_ids.should == ['a', 'b']
32
+ client_ids.must_equal ['a', 'b']
33
33
 
34
34
  end
35
35
 
@@ -49,7 +49,7 @@ describe MessageBus do
49
49
 
50
50
  wait_for(2000){ data["yeager"]}
51
51
 
52
- data["yeager"].should == true
52
+ data["yeager"].must_equal true
53
53
 
54
54
  end
55
55
 
@@ -61,7 +61,7 @@ describe MessageBus do
61
61
  @bus.publish("/chuck", {:norris => true})
62
62
  wait_for(2000){ data }
63
63
 
64
- data["norris"].should == true
64
+ data["norris"].must_equal true
65
65
  end
66
66
 
67
67
  it "should get a message if it subscribes to it" do
@@ -78,10 +78,10 @@ describe MessageBus do
78
78
 
79
79
  wait_for(2000){data}
80
80
 
81
- data.should == 'norris'
82
- site_id.should == 'magic'
83
- channel.should == '/chuck'
84
- user_ids.should == [1,2,3]
81
+ data.must_equal 'norris'
82
+ site_id.must_equal 'magic'
83
+ channel.must_equal '/chuck'
84
+ user_ids.must_equal [1,2,3]
85
85
 
86
86
  end
87
87
 
@@ -99,9 +99,9 @@ describe MessageBus do
99
99
 
100
100
  wait_for(2000){data}
101
101
 
102
- data.should == 'norris'
103
- site_id.should == 'magic'
104
- channel.should == '/chuck'
102
+ data.must_equal 'norris'
103
+ site_id.must_equal 'magic'
104
+ channel.must_equal '/chuck'
105
105
 
106
106
  end
107
107
 
@@ -112,7 +112,7 @@ describe MessageBus do
112
112
 
113
113
  r = @bus.backlog("/chuck", id)
114
114
 
115
- r.map{|i| i.data}.to_a.should == ['foo', 'bar']
115
+ r.map{|i| i.data}.to_a.must_equal ['foo', 'bar']
116
116
  end
117
117
 
118
118
  it "should correctly get full backlog of a channel" do
@@ -120,18 +120,18 @@ describe MessageBus do
120
120
  @bus.publish("/chuck", "foo")
121
121
  @bus.publish("/chuckles", "bar")
122
122
 
123
- @bus.backlog("/chuck").map{|i| i.data}.to_a.should == ['norris', 'foo']
123
+ @bus.backlog("/chuck").map{|i| i.data}.to_a.must_equal ['norris', 'foo']
124
124
 
125
125
  end
126
126
 
127
127
  it "allows you to look up last_message" do
128
128
  @bus.publish("/bob", "dylan")
129
129
  @bus.publish("/bob", "marley")
130
- @bus.last_message("/bob").data.should == "marley"
131
- @bus.last_message("/nothing").should == nil
130
+ @bus.last_message("/bob").data.must_equal "marley"
131
+ @bus.last_message("/nothing").must_equal nil
132
132
  end
133
133
 
134
- context "global subscriptions" do
134
+ describe "global subscriptions" do
135
135
  before do
136
136
  seq = 0
137
137
  @bus.site_id_lookup do
@@ -141,7 +141,7 @@ describe MessageBus do
141
141
 
142
142
  it "can get last_message" do
143
143
  @bus.publish("/global/test", "test")
144
- @bus.last_message("/global/test").data.should == "test"
144
+ @bus.last_message("/global/test").data.must_equal "test"
145
145
  end
146
146
 
147
147
  it "can subscribe globally" do
@@ -154,7 +154,7 @@ describe MessageBus do
154
154
  @bus.publish("/global/test", "test")
155
155
  wait_for(1000){ data }
156
156
 
157
- data.should == "test"
157
+ data.must_equal "test"
158
158
  end
159
159
 
160
160
  it "can subscribe to channel" do
@@ -167,19 +167,19 @@ describe MessageBus do
167
167
  @bus.publish("/global/test", "test")
168
168
  wait_for(1000){ data }
169
169
 
170
- data.should == "test"
170
+ data.must_equal "test"
171
171
  end
172
172
 
173
173
  it "should exception if publishing restricted messages to user" do
174
174
  lambda do
175
175
  @bus.publish("/global/test", "test", user_ids: [1])
176
- end.should raise_error(MessageBus::InvalidMessage)
176
+ end.must_raise(MessageBus::InvalidMessage)
177
177
  end
178
178
 
179
179
  it "should exception if publishing restricted messages to group" do
180
180
  lambda do
181
181
  @bus.publish("/global/test", "test", user_ids: [1])
182
- end.should raise_error(MessageBus::InvalidMessage)
182
+ end.must_raise(MessageBus::InvalidMessage)
183
183
  end
184
184
 
185
185
  end
@@ -198,22 +198,23 @@ describe MessageBus do
198
198
  wait_for(2000) { data == "ready" }
199
199
  @bus.publish("/hello", "world1")
200
200
  wait_for(2000) { data == "got it" }
201
- data.should == "got it"
201
+ data.must_equal "got it"
202
202
  Process.wait(child)
203
203
  else
204
- @bus.after_fork
205
- @bus.publish("/hello", "ready")
206
- wait_for(2000) { data == "world1" }
207
- if(data=="world1")
208
- @bus.publish("/hello", "got it")
204
+ begin
205
+ @bus.after_fork
206
+ @bus.publish("/hello", "ready")
207
+ wait_for(2000) { data == "world1" }
208
+ if(data=="world1")
209
+ @bus.publish("/hello", "got it")
210
+ end
211
+
212
+ $stdout.reopen("/dev/null", "w")
213
+ $stderr.reopen("/dev/null", "w")
214
+
215
+ ensure
216
+ exit!(0)
209
217
  end
210
-
211
- $stdout.reopen("/dev/null", "w")
212
- $stderr.reopen("/dev/null", "w")
213
-
214
- # having some issues with exit here
215
- # TODO find and fix
216
- Process.kill "KILL", Process.pid
217
218
  end
218
219
 
219
220
  end
data/spec/spec_helper.rb CHANGED
@@ -1,34 +1,29 @@
1
+ $: << File.dirname(__FILE__)
2
+ $: << File.join(File.dirname(__FILE__), '..', 'lib')
1
3
  require 'thin'
2
4
  require 'lib/fake_async_middleware'
5
+ require 'message_bus'
3
6
 
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
7
+ require 'minitest/autorun'
8
+ require 'minitest/spec'
11
9
 
12
- # to debug hanging tests
13
- # config.before :each do |x|
14
- # $start = Time.now
15
- # puts "Start: #{x.metadata[:location]}"
16
- # end
17
- #
18
- # config.after :each do |x|
19
- # puts "#{x.metadata[:location]} #{Time.now - $start}"
20
- # end
10
+ backend = (ENV['MESSAGE_BUS_BACKEND'] || :redis).to_sym
11
+ MESSAGE_BUS_CONFIG = {:backend=>backend}
12
+ require "message_bus/backends/#{backend}"
13
+ PUB_SUB_CLASS = MessageBus::BACKENDS.fetch(backend)
14
+ if backend == :postgres
15
+ MESSAGE_BUS_CONFIG.merge!(:backend_options=>{:user=>ENV['PGUSER'] || ENV['USER'], :dbname=>ENV['PGDATABASE'] || 'message_bus_test'})
21
16
  end
17
+ puts "Running with backend: #{backend}"
22
18
 
23
19
  def wait_for(timeout_milliseconds)
24
20
  timeout = (timeout_milliseconds + 0.0) / 1000
25
21
  finish = Time.now + timeout
26
- t = Thread.new do
22
+
23
+ Thread.new do
27
24
  while Time.now < finish && !yield
28
25
  sleep(0.001)
29
26
  end
30
- end
31
- t.join
32
- end
33
-
27
+ end.join
34
28
 
29
+ end
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: 2.0.0.beta.2
4
+ version: 2.0.0.beta.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Saffron
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-06 00:00:00.000000000 Z
11
+ date: 2016-02-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -31,7 +31,21 @@ dependencies:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :runtime
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pg
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
@@ -72,6 +86,8 @@ files:
72
86
  - examples/minimal/Gemfile
73
87
  - examples/minimal/config.ru
74
88
  - lib/message_bus.rb
89
+ - lib/message_bus/backends/postgres.rb
90
+ - lib/message_bus/backends/redis.rb
75
91
  - lib/message_bus/client.rb
76
92
  - lib/message_bus/connection_manager.rb
77
93
  - lib/message_bus/diagnostics.rb
@@ -81,17 +97,17 @@ files:
81
97
  - lib/message_bus/rack/middleware.rb
82
98
  - lib/message_bus/rack/thin_ext.rb
83
99
  - lib/message_bus/rails/railtie.rb
84
- - lib/message_bus/redis/reliable_pub_sub.rb
85
100
  - lib/message_bus/timer_thread.rb
86
101
  - lib/message_bus/version.rb
87
102
  - message_bus.gemspec
88
103
  - spec/lib/fake_async_middleware.rb
89
104
  - spec/lib/message_bus/assets/asset_encoding_spec.rb
105
+ - spec/lib/message_bus/backends/postgres_spec.rb
106
+ - spec/lib/message_bus/backends/redis_spec.rb
90
107
  - spec/lib/message_bus/client_spec.rb
91
108
  - spec/lib/message_bus/connection_manager_spec.rb
92
109
  - spec/lib/message_bus/multi_process_spec.rb
93
110
  - spec/lib/message_bus/rack/middleware_spec.rb
94
- - spec/lib/message_bus/redis/reliable_pub_sub_spec.rb
95
111
  - spec/lib/message_bus/timer_thread_spec.rb
96
112
  - spec/lib/message_bus_spec.rb
97
113
  - spec/spec_helper.rb
@@ -108,7 +124,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
108
124
  requirements:
109
125
  - - ">="
110
126
  - !ruby/object:Gem::Version
111
- version: '0'
127
+ version: 1.9.3
112
128
  required_rubygems_version: !ruby/object:Gem::Requirement
113
129
  requirements:
114
130
  - - ">"
@@ -123,11 +139,12 @@ summary: ''
123
139
  test_files:
124
140
  - spec/lib/fake_async_middleware.rb
125
141
  - spec/lib/message_bus/assets/asset_encoding_spec.rb
142
+ - spec/lib/message_bus/backends/postgres_spec.rb
143
+ - spec/lib/message_bus/backends/redis_spec.rb
126
144
  - spec/lib/message_bus/client_spec.rb
127
145
  - spec/lib/message_bus/connection_manager_spec.rb
128
146
  - spec/lib/message_bus/multi_process_spec.rb
129
147
  - spec/lib/message_bus/rack/middleware_spec.rb
130
- - spec/lib/message_bus/redis/reliable_pub_sub_spec.rb
131
148
  - spec/lib/message_bus/timer_thread_spec.rb
132
149
  - spec/lib/message_bus_spec.rb
133
150
  - spec/spec_helper.rb