message_bus 3.3.3 → 3.3.7

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.
Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.eslintrc.js +21 -0
  3. data/.github/workflows/ci.yml +71 -0
  4. data/.gitignore +2 -0
  5. data/.rubocop.yml +3 -1
  6. data/CHANGELOG +36 -8
  7. data/DEV.md +7 -0
  8. data/Gemfile +0 -25
  9. data/LICENSE +1 -1
  10. data/README.md +34 -15
  11. data/Rakefile +13 -8
  12. data/assets/message-bus-ajax.js +4 -10
  13. data/assets/message-bus.js +69 -76
  14. data/bench/codecs/all_codecs.rb +39 -0
  15. data/bench/codecs/marshal.rb +11 -0
  16. data/bench/codecs/packed_string.rb +67 -0
  17. data/bench/codecs/string_hack.rb +47 -0
  18. data/bench/codecs_large_user_list.rb +29 -0
  19. data/bench/codecs_standard_message.rb +29 -0
  20. data/examples/bench/bench.lua +2 -2
  21. data/lib/message_bus/backends/base.rb +3 -5
  22. data/lib/message_bus/backends/memory.rb +0 -2
  23. data/lib/message_bus/backends/postgres.rb +7 -5
  24. data/lib/message_bus/backends/redis.rb +3 -5
  25. data/lib/message_bus/client.rb +3 -7
  26. data/lib/message_bus/codec/base.rb +18 -0
  27. data/lib/message_bus/codec/json.rb +15 -0
  28. data/lib/message_bus/codec/oj.rb +21 -0
  29. data/lib/message_bus/connection_manager.rb +1 -1
  30. data/lib/message_bus/distributed_cache.rb +2 -1
  31. data/lib/message_bus/http_client.rb +2 -2
  32. data/lib/message_bus/rack/diagnostics.rb +30 -8
  33. data/lib/message_bus/rack/middleware.rb +22 -16
  34. data/lib/message_bus/rack/thin_ext.rb +1 -1
  35. data/lib/message_bus/version.rb +1 -1
  36. data/lib/message_bus.rb +38 -23
  37. data/message_bus.gemspec +20 -5
  38. data/package-lock.json +3744 -0
  39. data/package.json +14 -4
  40. data/spec/assets/SpecHelper.js +6 -5
  41. data/spec/assets/message-bus.spec.js +9 -6
  42. data/spec/helpers.rb +17 -6
  43. data/spec/integration/http_client_spec.rb +1 -1
  44. data/spec/lib/message_bus/backend_spec.rb +12 -44
  45. data/spec/lib/message_bus/client_spec.rb +6 -6
  46. data/spec/lib/message_bus/distributed_cache_spec.rb +5 -7
  47. data/spec/lib/message_bus/multi_process_spec.rb +1 -1
  48. data/spec/lib/message_bus/rack/middleware_spec.rb +16 -5
  49. data/spec/lib/message_bus_spec.rb +18 -7
  50. data/spec/spec_helper.rb +8 -9
  51. data/spec/support/jasmine-browser.json +16 -0
  52. metadata +230 -13
  53. data/.travis.yml +0 -17
  54. data/lib/message_bus/em_ext.rb +0 -6
  55. data/spec/assets/support/jasmine.yml +0 -126
  56. data/spec/assets/support/jasmine_helper.rb +0 -11
  57. data/vendor/assets/javascripts/message-bus-ajax.js +0 -44
  58. data/vendor/assets/javascripts/message-bus.js +0 -556
data/package.json CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "message-bus-client",
3
- "version": "3.3.0",
3
+ "version": "3.3.5",
4
4
  "description": "A message bus client in Javascript",
5
5
  "main": "assets/message-bus.js",
6
- "keywords": "es6, modules",
7
- "files": ["assets/message-bus.js"],
6
+ "keywords": [
7
+ "es6",
8
+ "modules"
9
+ ],
10
+ "files": [
11
+ "assets/message-bus.js"
12
+ ],
8
13
  "jsnext:main": "assets/message-bus.js",
9
14
  "module": "assets/message-bus.js",
10
15
  "repository": {
@@ -16,5 +21,10 @@
16
21
  "bugs": {
17
22
  "url": "https://github.com/discourse/message_bus/issues"
18
23
  },
19
- "homepage": "https://github.com/discourse/message_bus#readme"
24
+ "homepage": "https://github.com/discourse/message_bus#readme",
25
+ "devDependencies": {
26
+ "eslint": "^7.27.0",
27
+ "jasmine-browser-runner": "^0.10.0",
28
+ "jasmine-core": "^3.10.1"
29
+ }
20
30
  }
@@ -1,3 +1,5 @@
1
+ /* global beforeEach, afterEach, it, spyOn, MessageBus */
2
+
1
3
  var message_id = 1;
2
4
  var SEPARATOR = "\r\n|\r\n";
3
5
 
@@ -12,7 +14,7 @@ var encodeChunks = function(xhr, chunks) {
12
14
  }
13
15
  if (xhr.onprogress){ // using longPoll if onprogress is set
14
16
  var responses = []
15
- for (var i=0;i<chunks.length;i++) {
17
+ for (var j=0;j<chunks.length;j++) {
16
18
  responses.push( JSON.stringify([chunk]) );
17
19
  }
18
20
  return responses.join(SEPARATOR) + SEPARATOR;
@@ -26,7 +28,7 @@ beforeEach(function () {
26
28
 
27
29
  function MockedXMLHttpRequest(){
28
30
  this.headers = {};
29
- };
31
+ }
30
32
 
31
33
  MockedXMLHttpRequest.prototype.send = function(){
32
34
  this.readyState = 4
@@ -75,8 +77,8 @@ window.testMB = function(description, testFn, path, data){
75
77
  {channel: path || '/test', data: data || {password: 'MessageBusRocks!'}}
76
78
  ];
77
79
  it(description, function(done){
78
- spec = this;
79
- promisy = {
80
+ var spec = this;
81
+ var promisy = {
80
82
  finally: function(fn){
81
83
  this.resolve = fn;
82
84
  }
@@ -105,4 +107,3 @@ window.testMB = function(description, testFn, path, data){
105
107
  });
106
108
 
107
109
  }
108
-
@@ -1,3 +1,5 @@
1
+ /* global describe, it, spyOn, MessageBus, expect, jasmine, testMB */
2
+
1
3
  describe("Messagebus", function() {
2
4
 
3
5
  it("submits change requests", function(done){
@@ -6,10 +8,11 @@ describe("Messagebus", function() {
6
8
  MessageBus.subscribe('/test', function(){
7
9
  expect(spec.MockedXMLHttpRequest.prototype.send)
8
10
  .toHaveBeenCalled()
9
- var req = JSON.parse(spec.MockedXMLHttpRequest.prototype.send.calls.argsFor(0)[0]);
10
- expect(req['/test']).toEqual(-1)
11
- expect(req['__seq']).not.toBeUndefined();
12
- done()
11
+ var data = spec.MockedXMLHttpRequest.prototype.send.calls.argsFor(0)[0];
12
+ var params = new URLSearchParams(data);
13
+ expect(params.get("/test")).toEqual("-1");
14
+ expect(params.get("__seq")).toMatch(/\d+/);
15
+ done();
13
16
  });
14
17
  });
15
18
 
@@ -57,7 +60,7 @@ describe("Messagebus", function() {
57
60
  });
58
61
  });
59
62
 
60
- testMB('sets dlp paramater when longPolling is disabled', function(){
63
+ testMB('sets dlp parameter when longPolling is disabled', function(){
61
64
  MessageBus.enableLongPolling = false
62
65
  this.perform(function(message, xhr){
63
66
  expect(xhr.url).toMatch("dlp=t");
@@ -87,7 +90,7 @@ describe("Messagebus", function() {
87
90
  expect(xhr.headers).toEqual({
88
91
  'X-SILENCE-LOGGER': 'true',
89
92
  'X-MB-TEST-VALUE': '42',
90
- 'Content-Type': 'application/json'
93
+ 'Content-Type': 'application/x-www-form-urlencoded'
91
94
  });
92
95
  }).finally(function(){
93
96
  MessageBus.headers = {};
data/spec/helpers.rb CHANGED
@@ -1,15 +1,26 @@
1
1
  # frozen_string_literal: true
2
- def wait_for(timeout_milliseconds = 2000)
3
- timeout = (timeout_milliseconds + 0.0) / 1000
2
+
3
+ require 'logger'
4
+ require 'method_source'
5
+
6
+ def wait_for(timeout_milliseconds = 2000, &blk)
7
+ timeout = timeout_milliseconds / 1000.0
4
8
  finish = Time.now + timeout
9
+ result = nil
5
10
 
6
- Thread.new do
7
- sleep(0.001) while Time.now < finish && !yield
8
- end.join
11
+ while Time.now < finish && !(result = blk.call)
12
+ sleep(0.001)
13
+ end
14
+
15
+ flunk("wait_for timed out:\n#{blk.source}") if !result
9
16
  end
10
17
 
11
18
  def test_config_for_backend(backend)
12
- config = { backend: backend }
19
+ config = {
20
+ backend: backend,
21
+ logger: Logger.new(IO::NULL),
22
+ }
23
+
13
24
  case backend
14
25
  when :redis
15
26
  config[:url] = ENV['REDISURL']
@@ -71,7 +71,7 @@ describe MessageBus::HTTPClient do
71
71
  # that we sleep for the right interval after failure
72
72
  sleep 0.5
73
73
 
74
- assert_equal(1, fake.string.scan("Errno::ECONNREFUSED").size)
74
+ assert_match(/Errno::ECONNREFUSED|SocketError/, fake.string)
75
75
  ensure
76
76
  $stderr = original_stderr
77
77
  end
@@ -4,18 +4,17 @@ require_relative '../../spec_helper'
4
4
  require 'message_bus'
5
5
 
6
6
  describe PUB_SUB_CLASS do
7
- def new_test_bus
8
- PUB_SUB_CLASS.new(MESSAGE_BUS_CONFIG)
7
+ before do
8
+ @bus = PUB_SUB_CLASS.new(test_config_for_backend(CURRENT_BACKEND))
9
9
  end
10
10
 
11
- before do
12
- @bus = new_test_bus
11
+ after do
13
12
  @bus.reset!
14
13
  end
15
14
 
16
15
  describe "API parity" do
17
16
  it "has the same public methods as the base class" do
18
- @bus.public_methods.sort.must_equal MessageBus::Backends::Base.new(MESSAGE_BUS_CONFIG).public_methods.sort
17
+ @bus.public_methods.sort.must_equal MessageBus::Backends::Base.new(test_config_for_backend(CURRENT_BACKEND)).public_methods.sort
19
18
  end
20
19
  end
21
20
 
@@ -77,7 +76,7 @@ describe PUB_SUB_CLASS do
77
76
  end
78
77
 
79
78
  threads.each(&:join)
80
- @bus.backlog("/foo").length == 100
79
+ @bus.backlog("/foo").length.must_equal 100
81
80
  end
82
81
 
83
82
  it "should be able to encode and decode messages properly" do
@@ -91,37 +90,6 @@ describe PUB_SUB_CLASS do
91
90
  @bus.last_id("/foo").must_equal 1
92
91
  end
93
92
 
94
- describe "readonly" do
95
- after do
96
- @bus.pub_redis.slaveof "no", "one"
97
- end
98
-
99
- it "should be able to store messages in memory for a period while in read only" do
100
- test_only :redis
101
- skip "This spec changes redis behavior that in turn means other specs run slow"
102
-
103
- @bus.pub_redis.slaveof "127.0.0.80", "666"
104
- @bus.max_in_memory_publish_backlog = 2
105
-
106
- current_threads = Thread.list
107
- current_threads_length = current_threads.count
108
-
109
- 3.times do
110
- result = @bus.publish "/foo", "bar"
111
- assert_nil result
112
- Thread.list.length.must_equal(current_threads_length + 1)
113
- end
114
-
115
- @bus.pub_redis.slaveof "no", "one"
116
- sleep 0.01
117
-
118
- (Thread.list - current_threads).each(&:join)
119
- Thread.list.length.must_equal current_threads_length
120
-
121
- @bus.backlog("/foo", 0).map(&:data).must_equal ["bar", "bar"]
122
- end
123
- end
124
-
125
93
  it "can set backlog age" do
126
94
  @bus.max_backlog_age = 1
127
95
 
@@ -137,7 +105,7 @@ describe PUB_SUB_CLASS do
137
105
  sleep 1.25 # Should now be at time =~ 1.25s. Our backlog should have expired by now.
138
106
  expected_backlog_size = 0
139
107
 
140
- case MESSAGE_BUS_CONFIG[:backend]
108
+ case CURRENT_BACKEND
141
109
  when :postgres
142
110
  # Force triggering backlog expiry: postgres backend doesn't expire backlogs on a timer, but at publication time.
143
111
  @bus.global_backlog.length.wont_equal expected_backlog_size
@@ -161,7 +129,7 @@ describe PUB_SUB_CLASS do
161
129
  @bus.publish "/foo", "baz" # Publish something else to ward off another expiry
162
130
  expected_backlog_size += 1
163
131
 
164
- case MESSAGE_BUS_CONFIG[:backend]
132
+ case CURRENT_BACKEND
165
133
  when :postgres
166
134
  # Postgres expires individual messages that have lived longer than the TTL, not whole backlogs
167
135
  expected_backlog_size -= 1
@@ -189,7 +157,7 @@ describe PUB_SUB_CLASS do
189
157
  sleep 1.25 # Should now be at time =~ 1.25s. Our backlog should have expired by now.
190
158
  expected_backlog_size = 0
191
159
 
192
- case MESSAGE_BUS_CONFIG[:backend]
160
+ case CURRENT_BACKEND
193
161
  when :postgres
194
162
  # Force triggering backlog expiry: postgres backend doesn't expire backlogs on a timer, but at publication time.
195
163
  @bus.global_backlog.length.wont_equal expected_backlog_size
@@ -204,7 +172,7 @@ describe PUB_SUB_CLASS do
204
172
 
205
173
  # for the time being we can give pg a pass here
206
174
  # TODO: make the implementation here consistent
207
- if MESSAGE_BUS_CONFIG[:backend] != :postgres
175
+ if CURRENT_BACKEND != :postgres
208
176
  # ids are not opaque we expect them to be reset on our channel if it
209
177
  # got cleared due to an expire, the reason for this is cause we will leak entries due to tracking
210
178
  # this in turn can bloat storage for the backend
@@ -222,7 +190,7 @@ describe PUB_SUB_CLASS do
222
190
  @bus.publish "/foo", "baz", max_backlog_age: 1 # Publish something else to ward off another expiry
223
191
  expected_backlog_size += 1
224
192
 
225
- case MESSAGE_BUS_CONFIG[:backend]
193
+ case CURRENT_BACKEND
226
194
  when :postgres
227
195
  # Postgres expires individual messages that have lived longer than the TTL, not whole backlogs
228
196
  expected_backlog_size -= 1
@@ -249,7 +217,7 @@ describe PUB_SUB_CLASS do
249
217
  @bus.publish "/foo", "baz"
250
218
  @bus.publish "/hello", "planet"
251
219
 
252
- expected_messages = case MESSAGE_BUS_CONFIG[:backend]
220
+ expected_messages = case CURRENT_BACKEND
253
221
  when :redis
254
222
  # Redis has channel-specific message IDs
255
223
  [
@@ -277,7 +245,7 @@ describe PUB_SUB_CLASS do
277
245
  @bus.publish "/bar", "a1"
278
246
  @bus.publish "/bar", "b1"
279
247
 
280
- expected_messages = case MESSAGE_BUS_CONFIG[:backend]
248
+ expected_messages = case CURRENT_BACKEND
281
249
  when :redis
282
250
  # Redis has channel-specific message IDs
283
251
  [
@@ -11,7 +11,7 @@ describe MessageBus::Client do
11
11
 
12
12
  before do
13
13
  @bus = MessageBus::Instance.new
14
- @bus.configure(MESSAGE_BUS_CONFIG)
14
+ @bus.configure(test_config_for_backend(CURRENT_BACKEND))
15
15
  @client = setup_client('abc')
16
16
  end
17
17
 
@@ -98,7 +98,7 @@ describe MessageBus::Client do
98
98
  chunk2.length.must_equal 0
99
99
  end
100
100
 
101
- it "does not bleed data accross sites" do
101
+ it "does not bleed data across sites" do
102
102
  @client.site_id = "test"
103
103
 
104
104
  @client.subscribe('/hello', nil)
@@ -107,7 +107,7 @@ describe MessageBus::Client do
107
107
  log.length.must_equal 0
108
108
  end
109
109
 
110
- it "does not bleed status accross sites" do
110
+ it "does not bleed status across sites" do
111
111
  @client.site_id = "test"
112
112
 
113
113
  @client.subscribe('/hello', -1)
@@ -190,7 +190,7 @@ describe MessageBus::Client do
190
190
  @client.allowed?(@message).must_equal true
191
191
  end
192
192
 
193
- describe 'targetted at user' do
193
+ describe 'targeted at user' do
194
194
  before do
195
195
  @message = MessageBus::Message.new(1, 2, '/test', 'hello')
196
196
  @message.user_ids = [1, 2, 3]
@@ -241,7 +241,7 @@ describe MessageBus::Client do
241
241
  end
242
242
  end
243
243
 
244
- describe "targetted at group" do
244
+ describe "targeted at group" do
245
245
  before do
246
246
  @message = MessageBus::Message.new(1, 2, '/test', 'hello')
247
247
  @message.group_ids = [1, 2, 3]
@@ -291,7 +291,7 @@ describe MessageBus::Client do
291
291
  end
292
292
  end
293
293
 
294
- describe 'targetted at group and user' do
294
+ describe 'targeted at group and user' do
295
295
  before do
296
296
  @message = MessageBus::Message.new(1, 2, '/test', 'hello')
297
297
  @message.group_ids = [1, 2, 3]
@@ -6,13 +6,16 @@ require 'message_bus'
6
6
  require 'message_bus/distributed_cache'
7
7
 
8
8
  describe MessageBus::DistributedCache do
9
- before :all do
9
+ before do
10
10
  @bus = MessageBus::Instance.new
11
11
  @bus.configure(backend: :memory)
12
12
  @manager = MessageBus::DistributedCache::Manager.new(@bus)
13
+ @cache1 = cache(cache_name)
14
+ @cache2 = cache(cache_name)
13
15
  end
14
16
 
15
- after :all do
17
+ after do
18
+ @bus.reset!
16
19
  @bus.destroy
17
20
  end
18
21
 
@@ -24,11 +27,6 @@ describe MessageBus::DistributedCache do
24
27
  SecureRandom.hex
25
28
  end
26
29
 
27
- before do
28
- @cache1 = cache(cache_name)
29
- @cache2 = cache(cache_name)
30
- end
31
-
32
30
  it 'supports arrays with hashes' do
33
31
  c1 = cache("test1")
34
32
  c2 = cache("test1")
@@ -13,7 +13,7 @@ describe PUB_SUB_CLASS do
13
13
  end
14
14
 
15
15
  def new_bus
16
- PUB_SUB_CLASS.new(MESSAGE_BUS_CONFIG.merge(db: 10))
16
+ PUB_SUB_CLASS.new(test_config_for_backend(CURRENT_BACKEND).merge(db: 10))
17
17
  end
18
18
 
19
19
  def work_it
@@ -12,7 +12,7 @@ describe MessageBus::Rack::Middleware do
12
12
 
13
13
  before do
14
14
  bus = @bus = MessageBus::Instance.new
15
- @bus.configure(MESSAGE_BUS_CONFIG)
15
+ @bus.configure(test_config_for_backend(CURRENT_BACKEND))
16
16
  @bus.long_polling_enabled = false
17
17
  @bus.base_route = base_route if base_route
18
18
 
@@ -26,7 +26,6 @@ describe MessageBus::Rack::Middleware do
26
26
 
27
27
  @async_middleware = builder.to_app
28
28
  @message_bus_middleware = @async_middleware.app
29
- @bus.reset!
30
29
  end
31
30
 
32
31
  after do
@@ -143,13 +142,12 @@ describe MessageBus::Rack::Middleware do
143
142
  end
144
143
 
145
144
  describe "diagnostics" do
146
- it "should return a 403 if a user attempts to get at the _diagnostics path" do
145
+ it "should return a 403 if an unauthorized user attempts to get at the _diagnostics path" do
147
146
  get "/message-bus/_diagnostics"
148
147
  last_response.status.must_equal 403
149
148
  end
150
149
 
151
150
  it "should get a 200 with html for an authorized user" do
152
-
153
151
  def @bus.is_admin_lookup
154
152
  proc { |_| true }
155
153
  end
@@ -172,7 +170,6 @@ describe MessageBus::Rack::Middleware do
172
170
  end
173
171
 
174
172
  it "should get the script it asks for" do
175
-
176
173
  def @bus.is_admin_lookup
177
174
  proc { |_| true }
178
175
  end
@@ -181,6 +178,15 @@ describe MessageBus::Rack::Middleware do
181
178
  last_response.status.must_equal 200
182
179
  last_response.content_type.must_equal "application/javascript;charset=UTF-8"
183
180
  end
181
+
182
+ it "should return 404 for invalid assets path" do
183
+ def @bus.is_admin_lookup
184
+ proc { |_| true }
185
+ end
186
+
187
+ get "/message-bus/_diagnostics/assets/../Gemfile"
188
+ last_response.status.must_equal 404
189
+ end
184
190
  end
185
191
 
186
192
  describe "polling" do
@@ -414,6 +420,11 @@ describe MessageBus::Rack::Middleware do
414
420
  JSON.parse(last_response.body).first["data"].must_equal('json' => true)
415
421
  end
416
422
 
423
+ it "should tell Rack to skip committing the session" do
424
+ post "/message-bus/1234", {}, { "rack.session.options" => {} }
425
+ last_request.env["rack.session.options"][:skip].must_equal true
426
+ end
427
+
417
428
  describe "on_middleware_error handling" do
418
429
  it "allows error handling of middleware failures" do
419
430
  @bus.on_middleware_error do |_env, err|
@@ -2,7 +2,6 @@
2
2
 
3
3
  require_relative '../spec_helper'
4
4
  require 'message_bus'
5
- require 'redis'
6
5
 
7
6
  describe MessageBus do
8
7
  before do
@@ -10,7 +9,7 @@ describe MessageBus do
10
9
  @bus.site_id_lookup do
11
10
  "magic"
12
11
  end
13
- @bus.configure(MESSAGE_BUS_CONFIG)
12
+ @bus.configure(test_config_for_backend(CURRENT_BACKEND))
14
13
  end
15
14
 
16
15
  after do
@@ -98,7 +97,7 @@ describe MessageBus do
98
97
  client_ids.must_equal ['a', 'b']
99
98
  end
100
99
 
101
- it "should recover from a redis flush" do
100
+ it "should recover from a reset" do
102
101
  data = nil
103
102
  @bus.subscribe("/chuck") do |msg|
104
103
  data = msg.data
@@ -162,7 +161,7 @@ describe MessageBus do
162
161
  data.must_equal 'norris'
163
162
  site_id.must_equal 'magic'
164
163
  channel.must_equal '/chuck'
165
- user_ids.must_equal [1, 2, 3]
164
+ user_ids.to_a.must_equal [1, 2, 3]
166
165
  end
167
166
 
168
167
  it "should get global messages if it subscribes to them" do
@@ -201,6 +200,13 @@ describe MessageBus do
201
200
  @bus.backlog("/chuck").map { |i| i.data }.to_a.must_equal ['norris', 'foo']
202
201
  end
203
202
 
203
+ it "should correctly restrict the backlog size of a channel" do
204
+ @bus.publish("/chuck", "norris")
205
+ @bus.publish("/chuck", "foo", max_backlog_size: 1)
206
+
207
+ @bus.backlog("/chuck").map { |i| i.data }.to_a.must_equal ['foo']
208
+ end
209
+
204
210
  it "allows you to look up last_message" do
205
211
  @bus.publish("/bob", "dylan")
206
212
  @bus.publish("/bob", "marley")
@@ -300,7 +306,7 @@ describe MessageBus do
300
306
  end
301
307
  end
302
308
 
303
- it "should support forking properly do" do
309
+ it "should support forking properly" do
304
310
  test_never :memory
305
311
 
306
312
  data = []
@@ -309,7 +315,7 @@ describe MessageBus do
309
315
  end
310
316
 
311
317
  @bus.publish("/hello", "pre-fork")
312
- wait_for(2000) { data.length > 0 }
318
+ wait_for(2000) { data.length == 1 }
313
319
 
314
320
  if child = Process.fork
315
321
  # The child was forked and we received its PID
@@ -321,6 +327,7 @@ describe MessageBus do
321
327
  else
322
328
  begin
323
329
  @bus.after_fork
330
+ GC.start
324
331
  @bus.publish("/hello", "from-fork")
325
332
  ensure
326
333
  exit!(0)
@@ -329,7 +336,11 @@ describe MessageBus do
329
336
 
330
337
  wait_for(2000) { data.length == 3 }
331
338
 
332
- data.must_equal(["pre-fork", "from-fork", "continuation"])
339
+ @bus.publish("/hello", "after-fork")
340
+
341
+ wait_for(2000) { data.length == 4 }
342
+
343
+ data.must_equal(["pre-fork", "from-fork", "continuation", "after-fork"])
333
344
  end
334
345
 
335
346
  describe '#register_client_message_filter' do
data/spec/spec_helper.rb CHANGED
@@ -11,18 +11,17 @@ require 'minitest/global_expectations'
11
11
 
12
12
  require_relative "helpers"
13
13
 
14
- backend = (ENV['MESSAGE_BUS_BACKEND'] || :redis).to_sym
15
- MESSAGE_BUS_CONFIG = test_config_for_backend(backend)
16
- require "message_bus/backends/#{backend}"
17
- PUB_SUB_CLASS = MessageBus::BACKENDS.fetch(backend)
18
- puts "Running with backend: #{backend}"
14
+ CURRENT_BACKEND = (ENV['MESSAGE_BUS_BACKEND'] || :redis).to_sym
15
+
16
+ require "message_bus/backends/#{CURRENT_BACKEND}"
17
+ PUB_SUB_CLASS = MessageBus::BACKENDS.fetch(CURRENT_BACKEND)
18
+
19
+ puts "Running with backend: #{CURRENT_BACKEND}"
19
20
 
20
21
  def test_only(*backends)
21
- backend = MESSAGE_BUS_CONFIG[:backend]
22
- skip "Test doesn't apply to #{backend}" unless backends.include?(backend)
22
+ skip "Test doesn't apply to #{CURRENT_BACKEND}" unless backends.include?(CURRENT_BACKEND)
23
23
  end
24
24
 
25
25
  def test_never(*backends)
26
- backend = MESSAGE_BUS_CONFIG[:backend]
27
- skip "Test doesn't apply to #{backend}" if backends.include?(backend)
26
+ skip "Test doesn't apply to #{CURRENT_BACKEND}" if backends.include?(CURRENT_BACKEND)
28
27
  end
@@ -0,0 +1,16 @@
1
+ {
2
+ "srcDir": "assets",
3
+ "srcFiles": [
4
+ "message-bus.js",
5
+ "message-bus-ajax.js"
6
+ ],
7
+ "specDir": "spec/assets",
8
+ "specFiles": [
9
+ "message-bus.spec.js"
10
+ ],
11
+ "helpers": [
12
+ "SpecHelper.js"
13
+ ],
14
+ "random": true,
15
+ "browser": "headlessChrome"
16
+ }