message_bus 2.2.3 → 3.3.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of message_bus might be problematic. Click here for more details.
- checksums.yaml +4 -4
- data/.rubocop.yml +9 -1
- data/.travis.yml +1 -1
- data/CHANGELOG +30 -0
- data/Gemfile +8 -3
- data/Guardfile +1 -0
- data/README.md +62 -11
- data/Rakefile +1 -0
- data/assets/message-bus.js +64 -78
- data/examples/bench/config.ru +1 -0
- data/examples/bench/puma.rb +1 -0
- data/examples/bench/unicorn.conf.rb +1 -0
- data/examples/chat/Gemfile +1 -0
- data/examples/chat/chat.rb +2 -0
- data/examples/chat/config.ru +2 -0
- data/examples/diagnostics/Gemfile +1 -0
- data/examples/diagnostics/config.ru +1 -0
- data/examples/minimal/Gemfile +1 -0
- data/examples/minimal/config.ru +1 -0
- data/lib/message_bus.rb +33 -0
- data/lib/message_bus/client.rb +36 -8
- data/lib/message_bus/diagnostics.rb +1 -1
- data/lib/message_bus/em_ext.rb +1 -0
- data/lib/message_bus/http_client.rb +2 -1
- data/lib/message_bus/http_client/channel.rb +1 -0
- data/lib/message_bus/rack/diagnostics.rb +5 -4
- data/lib/message_bus/rack/middleware.rb +8 -4
- data/lib/message_bus/rails/railtie.rb +15 -13
- data/lib/message_bus/version.rb +1 -1
- data/package.json +20 -0
- data/spec/assets/message-bus.spec.js +0 -9
- data/spec/assets/support/jasmine_helper.rb +1 -0
- data/spec/fixtures/test/Gemfile +1 -0
- data/spec/fixtures/test/config.ru +1 -0
- data/spec/helpers.rb +1 -0
- data/spec/integration/http_client_spec.rb +2 -0
- data/spec/lib/fake_async_middleware.rb +3 -2
- data/spec/lib/message_bus/assets/asset_encoding_spec.rb +1 -0
- data/spec/lib/message_bus/backend_spec.rb +2 -0
- data/spec/lib/message_bus/client_spec.rb +208 -23
- data/spec/lib/message_bus/connection_manager_spec.rb +3 -1
- data/spec/lib/message_bus/distributed_cache_spec.rb +2 -0
- data/spec/lib/message_bus/multi_process_spec.rb +2 -0
- data/spec/lib/message_bus/rack/middleware_spec.rb +63 -0
- data/spec/lib/message_bus/timer_thread_spec.rb +2 -0
- data/spec/lib/message_bus_spec.rb +34 -0
- data/spec/performance/publish.rb +2 -0
- data/spec/spec_helper.rb +3 -1
- metadata +3 -2
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
# coding: utf-8
|
2
3
|
|
3
4
|
require_relative '../../../spec_helper'
|
@@ -7,11 +8,13 @@ require 'rack/test'
|
|
7
8
|
describe MessageBus::Rack::Middleware do
|
8
9
|
include Rack::Test::Methods
|
9
10
|
let(:extra_middleware) { nil }
|
11
|
+
let(:base_route) { nil }
|
10
12
|
|
11
13
|
before do
|
12
14
|
bus = @bus = MessageBus::Instance.new
|
13
15
|
@bus.configure(MESSAGE_BUS_CONFIG)
|
14
16
|
@bus.long_polling_enabled = false
|
17
|
+
@bus.base_route = base_route if base_route
|
15
18
|
|
16
19
|
e_m = extra_middleware
|
17
20
|
builder = Rack::Builder.new {
|
@@ -43,12 +46,27 @@ describe MessageBus::Rack::Middleware do
|
|
43
46
|
@bus.long_polling_enabled = true
|
44
47
|
end
|
45
48
|
|
49
|
+
describe "with altered base_route" do
|
50
|
+
let(:base_route) { "/base/route/" }
|
51
|
+
|
52
|
+
it "should respond as normal" do
|
53
|
+
post "/base/route/message-bus/ABC?dlp=t", '/foo1' => 0
|
54
|
+
@async_middleware.in_async?.must_equal false
|
55
|
+
last_response.ok?.must_equal true
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
46
59
|
it "should respond right away if dlp=t" do
|
47
60
|
post "/message-bus/ABC?dlp=t", '/foo1' => 0
|
48
61
|
@async_middleware.in_async?.must_equal false
|
49
62
|
last_response.ok?.must_equal true
|
50
63
|
end
|
51
64
|
|
65
|
+
it "should respond with a 404 if the client_id is missing" do
|
66
|
+
post "/message-bus/?dlp=t", '/foo1' => 0
|
67
|
+
last_response.not_found?.must_equal true
|
68
|
+
end
|
69
|
+
|
52
70
|
it "should respond right away to long polls that are polling on -1 with the last_id" do
|
53
71
|
post "/message-bus/ABC", '/foo' => -1
|
54
72
|
last_response.ok?.must_equal true
|
@@ -140,6 +158,19 @@ describe MessageBus::Rack::Middleware do
|
|
140
158
|
last_response.status.must_equal 200
|
141
159
|
end
|
142
160
|
|
161
|
+
describe "with an altered base_route" do
|
162
|
+
let(:base_route) { "/base/route/" }
|
163
|
+
|
164
|
+
it "should get a 200 with html for an authorized user" do
|
165
|
+
def @bus.is_admin_lookup
|
166
|
+
proc { |_| true }
|
167
|
+
end
|
168
|
+
|
169
|
+
get "/base/route/message-bus/_diagnostics"
|
170
|
+
last_response.status.must_equal 200
|
171
|
+
end
|
172
|
+
end
|
173
|
+
|
143
174
|
it "should get the script it asks for" do
|
144
175
|
|
145
176
|
def @bus.is_admin_lookup
|
@@ -242,6 +273,38 @@ describe MessageBus::Rack::Middleware do
|
|
242
273
|
parsed[1]["data"].must_equal "borbs"
|
243
274
|
end
|
244
275
|
|
276
|
+
it "should use the correct client ID" do
|
277
|
+
id = @bus.last_id('/foo')
|
278
|
+
|
279
|
+
client_id = "aBc123"
|
280
|
+
@bus.publish("/foo", "msg1", client_ids: [client_id])
|
281
|
+
@bus.publish("/foo", "msg2", client_ids: ["not_me#{client_id}"])
|
282
|
+
|
283
|
+
post "/message-bus/#{client_id}",
|
284
|
+
'/foo' => id
|
285
|
+
|
286
|
+
parsed = JSON.parse(last_response.body)
|
287
|
+
parsed.length.must_equal 2
|
288
|
+
parsed[0]["data"].must_equal("msg1")
|
289
|
+
parsed[1]["data"].wont_equal("msg2")
|
290
|
+
end
|
291
|
+
|
292
|
+
it "should use the correct client ID with additional path" do
|
293
|
+
id = @bus.last_id('/foo')
|
294
|
+
|
295
|
+
client_id = "aBc123"
|
296
|
+
@bus.publish("/foo", "msg1", client_ids: [client_id])
|
297
|
+
@bus.publish("/foo", "msg2", client_ids: ["not_me#{client_id}"])
|
298
|
+
|
299
|
+
post "/message-bus/#{client_id}/path/not/needed",
|
300
|
+
'/foo' => id
|
301
|
+
|
302
|
+
parsed = JSON.parse(last_response.body)
|
303
|
+
parsed.length.must_equal 2
|
304
|
+
parsed[0]["data"].must_equal("msg1")
|
305
|
+
parsed[1]["data"].wont_equal("msg2")
|
306
|
+
end
|
307
|
+
|
245
308
|
it "should have no cross talk" do
|
246
309
|
seq = 0
|
247
310
|
@bus.site_id_lookup do
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require_relative '../spec_helper'
|
2
4
|
require 'message_bus'
|
3
5
|
require 'redis'
|
@@ -35,6 +37,23 @@ describe MessageBus do
|
|
35
37
|
@bus.after_fork
|
36
38
|
end
|
37
39
|
|
40
|
+
describe "#base_route=" do
|
41
|
+
it "adds leading and trailing slashes" do
|
42
|
+
@bus.base_route = "my/base/route"
|
43
|
+
@bus.base_route.must_equal '/my/base/route/'
|
44
|
+
end
|
45
|
+
|
46
|
+
it "leaves existing leading and trailing slashes" do
|
47
|
+
@bus.base_route = "/my/base/route/"
|
48
|
+
@bus.base_route.must_equal '/my/base/route/'
|
49
|
+
end
|
50
|
+
|
51
|
+
it "removes duplicate slashes" do
|
52
|
+
@bus.base_route = "//my///base/route"
|
53
|
+
@bus.base_route.must_equal '/my/base/route/'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
38
57
|
it "can subscribe from a point in time" do
|
39
58
|
@bus.publish("/minion", "banana")
|
40
59
|
|
@@ -290,4 +309,19 @@ describe MessageBus do
|
|
290
309
|
|
291
310
|
data.must_equal(["pre-fork", "from-fork", "continuation"])
|
292
311
|
end
|
312
|
+
|
313
|
+
describe '#register_client_message_filter' do
|
314
|
+
it 'should register the message filter correctly' do
|
315
|
+
@bus.register_client_message_filter('/test')
|
316
|
+
|
317
|
+
@bus.client_message_filters.must_equal([])
|
318
|
+
|
319
|
+
@bus.register_client_message_filter('/test') { puts "hello world" }
|
320
|
+
|
321
|
+
channel, blk = @bus.client_message_filters[0]
|
322
|
+
|
323
|
+
blk.must_respond_to(:call)
|
324
|
+
channel.must_equal('/test')
|
325
|
+
end
|
326
|
+
end
|
293
327
|
end
|
data/spec/performance/publish.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
$: << File.dirname(__FILE__)
|
2
4
|
$: << File.join(File.dirname(__FILE__), '..', 'lib')
|
3
5
|
require 'thin'
|
@@ -5,7 +7,7 @@ require 'lib/fake_async_middleware'
|
|
5
7
|
require 'message_bus'
|
6
8
|
|
7
9
|
require 'minitest/autorun'
|
8
|
-
require 'minitest/
|
10
|
+
require 'minitest/global_expectations'
|
9
11
|
|
10
12
|
require_relative "helpers"
|
11
13
|
|
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:
|
4
|
+
version: 3.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sam Saffron
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-05-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|
@@ -113,6 +113,7 @@ files:
|
|
113
113
|
- lib/message_bus/timer_thread.rb
|
114
114
|
- lib/message_bus/version.rb
|
115
115
|
- message_bus.gemspec
|
116
|
+
- package.json
|
116
117
|
- spec/assets/SpecHelper.js
|
117
118
|
- spec/assets/message-bus.spec.js
|
118
119
|
- spec/assets/support/jasmine.yml
|