pubsubstub 0.1.0 → 0.2.1
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 +5 -5
- data/.travis.yml +7 -1
- data/Gemfile +3 -2
- data/Rakefile +20 -0
- data/example/config.ru +0 -1
- data/gemfiles/Gemfile.rack-1.x +12 -0
- data/gemfiles/Gemfile.rack-1.x.lock +57 -0
- data/gemfiles/Gemfile.rack-2.x +12 -0
- data/gemfiles/Gemfile.rack-2.x.lock +57 -0
- data/lib/pubsubstub.rb +5 -3
- data/lib/pubsubstub/application.rb +19 -3
- data/lib/pubsubstub/publish_action.rb +9 -5
- data/lib/pubsubstub/stream.rb +25 -0
- data/lib/pubsubstub/stream_action.rb +24 -29
- data/lib/pubsubstub/subscriber.rb +1 -1
- data/lib/pubsubstub/version.rb +1 -1
- data/pubsubstub.gemspec +3 -3
- data/spec/channel_spec.rb +1 -1
- data/spec/event_spec.rb +1 -1
- data/spec/publish_action_spec.rb +1 -1
- data/spec/spec_helper.rb +6 -1
- data/spec/stream_action_spec.rb +27 -12
- data/spec/subscriber_spec.rb +8 -3
- data/spec/subscription_spec.rb +1 -1
- data/spec/support/http_helpers.rb +1 -1
- metadata +22 -19
- data/lib/pubsubstub/action.rb +0 -13
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 115205de6d2987f1c983becef16c87452d844b33001a335105eb96f9a945ba74
|
|
4
|
+
data.tar.gz: d32a258717cb23cecc7d81e954938c499ffa6d8a9fdd68340a9e62cecbcffb17
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f92c6a3acf01542564683a9adf952ac0660bbc82612f294d34ba15864aac95d22b0ac9d778a7474101612528c6948e528a3291286c65e410a42394cbc5d9d2a3
|
|
7
|
+
data.tar.gz: 3caa10c0cebbe247632faf75d1259e4cba5fdfa8504b594f10826d8e6840ca560bb3d037c11d0e51acc65186ae73e1597199180a2d0880aea11d587fabc8feeb
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
|
@@ -3,10 +3,11 @@ source 'https://rubygems.org'
|
|
|
3
3
|
# Specify your gem's dependencies in pubsubstub.gemspec
|
|
4
4
|
gemspec
|
|
5
5
|
|
|
6
|
-
gem
|
|
6
|
+
gem 'rspec', '~> 3.8'
|
|
7
7
|
gem "pry-byebug"
|
|
8
|
+
gem "byebug", '~> 10.0'
|
|
8
9
|
gem "puma", "~> 3.4"
|
|
9
10
|
gem "thin", "~> 1.6"
|
|
10
11
|
gem "rack-test"
|
|
11
12
|
gem "timecop"
|
|
12
|
-
gem "rake"
|
|
13
|
+
gem "rake"
|
data/Rakefile
CHANGED
|
@@ -4,3 +4,23 @@ require 'rspec/core/rake_task'
|
|
|
4
4
|
RSpec::Core::RakeTask.new(:spec)
|
|
5
5
|
|
|
6
6
|
task default: :spec
|
|
7
|
+
|
|
8
|
+
namespace :spec do
|
|
9
|
+
task :all do
|
|
10
|
+
Dir['gemfiles/*'].reject { |p| p.end_with?('.lock') }.each do |gemfile|
|
|
11
|
+
command = %(BUNDLE_GEMFILE=#{gemfile} bundle exec rspec)
|
|
12
|
+
puts command
|
|
13
|
+
system(command)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
namespace :gemfiles do
|
|
19
|
+
task :update do
|
|
20
|
+
Dir['gemfiles/*'].reject { |p| p.end_with?('.lock') }.each do |gemfile|
|
|
21
|
+
command = %(BUNDLE_GEMFILE=#{gemfile} bundle update)
|
|
22
|
+
puts command
|
|
23
|
+
system(command)
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
data/example/config.ru
CHANGED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
byebug (10.0.2)
|
|
5
|
+
coderay (1.1.2)
|
|
6
|
+
daemons (1.3.1)
|
|
7
|
+
diff-lcs (1.3)
|
|
8
|
+
eventmachine (1.2.7)
|
|
9
|
+
method_source (0.9.2)
|
|
10
|
+
pry (0.12.2)
|
|
11
|
+
coderay (~> 1.1.0)
|
|
12
|
+
method_source (~> 0.9.0)
|
|
13
|
+
pry-byebug (3.6.0)
|
|
14
|
+
byebug (~> 10.0)
|
|
15
|
+
pry (~> 0.10)
|
|
16
|
+
puma (3.12.1)
|
|
17
|
+
rack (1.6.11)
|
|
18
|
+
rack-test (1.1.0)
|
|
19
|
+
rack (>= 1.0, < 3)
|
|
20
|
+
rake (12.3.3)
|
|
21
|
+
redis (4.1.2)
|
|
22
|
+
rspec (3.8.0)
|
|
23
|
+
rspec-core (~> 3.8.0)
|
|
24
|
+
rspec-expectations (~> 3.8.0)
|
|
25
|
+
rspec-mocks (~> 3.8.0)
|
|
26
|
+
rspec-core (3.8.2)
|
|
27
|
+
rspec-support (~> 3.8.0)
|
|
28
|
+
rspec-expectations (3.8.4)
|
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
30
|
+
rspec-support (~> 3.8.0)
|
|
31
|
+
rspec-mocks (3.8.1)
|
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
33
|
+
rspec-support (~> 3.8.0)
|
|
34
|
+
rspec-support (3.8.2)
|
|
35
|
+
thin (1.7.2)
|
|
36
|
+
daemons (~> 1.0, >= 1.0.9)
|
|
37
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
|
38
|
+
rack (>= 1, < 3)
|
|
39
|
+
timecop (0.9.1)
|
|
40
|
+
|
|
41
|
+
PLATFORMS
|
|
42
|
+
ruby
|
|
43
|
+
|
|
44
|
+
DEPENDENCIES
|
|
45
|
+
byebug (~> 10.0)
|
|
46
|
+
pry-byebug
|
|
47
|
+
puma (~> 3.4)
|
|
48
|
+
rack (< 2)
|
|
49
|
+
rack-test
|
|
50
|
+
rake
|
|
51
|
+
redis (~> 4.0)
|
|
52
|
+
rspec (~> 3.8)
|
|
53
|
+
thin (~> 1.6)
|
|
54
|
+
timecop
|
|
55
|
+
|
|
56
|
+
BUNDLED WITH
|
|
57
|
+
1.17.3
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
GEM
|
|
2
|
+
remote: https://rubygems.org/
|
|
3
|
+
specs:
|
|
4
|
+
byebug (10.0.2)
|
|
5
|
+
coderay (1.1.2)
|
|
6
|
+
daemons (1.3.1)
|
|
7
|
+
diff-lcs (1.3)
|
|
8
|
+
eventmachine (1.2.7)
|
|
9
|
+
method_source (0.9.2)
|
|
10
|
+
pry (0.12.2)
|
|
11
|
+
coderay (~> 1.1.0)
|
|
12
|
+
method_source (~> 0.9.0)
|
|
13
|
+
pry-byebug (3.6.0)
|
|
14
|
+
byebug (~> 10.0)
|
|
15
|
+
pry (~> 0.10)
|
|
16
|
+
puma (3.12.1)
|
|
17
|
+
rack (2.0.7)
|
|
18
|
+
rack-test (1.1.0)
|
|
19
|
+
rack (>= 1.0, < 3)
|
|
20
|
+
rake (12.3.3)
|
|
21
|
+
redis (4.1.2)
|
|
22
|
+
rspec (3.8.0)
|
|
23
|
+
rspec-core (~> 3.8.0)
|
|
24
|
+
rspec-expectations (~> 3.8.0)
|
|
25
|
+
rspec-mocks (~> 3.8.0)
|
|
26
|
+
rspec-core (3.8.2)
|
|
27
|
+
rspec-support (~> 3.8.0)
|
|
28
|
+
rspec-expectations (3.8.4)
|
|
29
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
30
|
+
rspec-support (~> 3.8.0)
|
|
31
|
+
rspec-mocks (3.8.1)
|
|
32
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
33
|
+
rspec-support (~> 3.8.0)
|
|
34
|
+
rspec-support (3.8.2)
|
|
35
|
+
thin (1.7.2)
|
|
36
|
+
daemons (~> 1.0, >= 1.0.9)
|
|
37
|
+
eventmachine (~> 1.0, >= 1.0.4)
|
|
38
|
+
rack (>= 1, < 3)
|
|
39
|
+
timecop (0.9.1)
|
|
40
|
+
|
|
41
|
+
PLATFORMS
|
|
42
|
+
ruby
|
|
43
|
+
|
|
44
|
+
DEPENDENCIES
|
|
45
|
+
byebug (~> 10.0)
|
|
46
|
+
pry-byebug
|
|
47
|
+
puma (~> 3.4)
|
|
48
|
+
rack (~> 2.0)
|
|
49
|
+
rack-test
|
|
50
|
+
rake
|
|
51
|
+
redis (~> 4.0)
|
|
52
|
+
rspec (~> 3.8)
|
|
53
|
+
thin (~> 1.6)
|
|
54
|
+
timecop
|
|
55
|
+
|
|
56
|
+
BUNDLED WITH
|
|
57
|
+
1.17.3
|
data/lib/pubsubstub.rb
CHANGED
|
@@ -3,7 +3,7 @@ require "mutex_m"
|
|
|
3
3
|
require "json"
|
|
4
4
|
require "set"
|
|
5
5
|
|
|
6
|
-
require "
|
|
6
|
+
require "rack/request"
|
|
7
7
|
require "redis"
|
|
8
8
|
require "pubsubstub/version"
|
|
9
9
|
require "pubsubstub/logging"
|
|
@@ -11,7 +11,7 @@ require "pubsubstub/channel"
|
|
|
11
11
|
require "pubsubstub/subscriber"
|
|
12
12
|
require "pubsubstub/subscription"
|
|
13
13
|
require "pubsubstub/event"
|
|
14
|
-
require "pubsubstub/
|
|
14
|
+
require "pubsubstub/stream"
|
|
15
15
|
require "pubsubstub/stream_action"
|
|
16
16
|
require "pubsubstub/publish_action"
|
|
17
17
|
require "pubsubstub/application"
|
|
@@ -21,7 +21,8 @@ module Pubsubstub
|
|
|
21
21
|
|
|
22
22
|
class << self
|
|
23
23
|
attr_accessor :heartbeat_frequency, :redis_url, :channels_scrollback_size,
|
|
24
|
-
:channels_scrollback_ttl, :logger, :reconnect_timeout, :error_handler
|
|
24
|
+
:channels_scrollback_ttl, :logger, :reconnect_timeout, :error_handler,
|
|
25
|
+
:use_persistent_connections
|
|
25
26
|
|
|
26
27
|
def publish(channel_name, *args)
|
|
27
28
|
Channel.new(channel_name).publish(Event.new(*args))
|
|
@@ -69,6 +70,7 @@ module Pubsubstub
|
|
|
69
70
|
self.channels_scrollback_size = 1000
|
|
70
71
|
self.channels_scrollback_ttl = 24 * 60 * 60
|
|
71
72
|
self.reconnect_timeout = 10_000
|
|
73
|
+
self.use_persistent_connections = true
|
|
72
74
|
|
|
73
75
|
# Deprecated. Use Pubsubstub.publish instead
|
|
74
76
|
module RedisPubSub
|
|
@@ -1,6 +1,22 @@
|
|
|
1
1
|
module Pubsubstub
|
|
2
|
-
class Application
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
class Application
|
|
3
|
+
def initialize(*)
|
|
4
|
+
@publish = PublishAction.new
|
|
5
|
+
@stream = StreamAction.new
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def self.call(env)
|
|
9
|
+
@instance ||= new
|
|
10
|
+
@instance.call(env)
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
def call(env)
|
|
14
|
+
request = Rack::Request.new(env)
|
|
15
|
+
if request.get?
|
|
16
|
+
@stream.call(env)
|
|
17
|
+
else
|
|
18
|
+
@publish.call(env)
|
|
19
|
+
end
|
|
20
|
+
end
|
|
5
21
|
end
|
|
6
22
|
end
|
|
@@ -1,10 +1,14 @@
|
|
|
1
1
|
module Pubsubstub
|
|
2
|
-
class PublishAction
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
2
|
+
class PublishAction
|
|
3
|
+
def initialize(*)
|
|
4
|
+
end
|
|
5
|
+
|
|
6
|
+
def call(env)
|
|
7
|
+
request = Rack::Request.new(env)
|
|
8
|
+
channels = (request.params['channels'] || [:default]).each do |channel_name|
|
|
9
|
+
Pubsubstub.publish(channel_name, request.params['data'], name: request.params['event'])
|
|
6
10
|
end
|
|
7
|
-
|
|
11
|
+
[200, {}, ['']]
|
|
8
12
|
end
|
|
9
13
|
end
|
|
10
14
|
end
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
class Stream
|
|
2
|
+
def initialize(&callback)
|
|
3
|
+
@callback = callback
|
|
4
|
+
@closed = false
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
def close
|
|
8
|
+
@closed = true
|
|
9
|
+
end
|
|
10
|
+
|
|
11
|
+
def each(&front)
|
|
12
|
+
@front = front
|
|
13
|
+
@callback.call(self)
|
|
14
|
+
close
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def <<(data)
|
|
18
|
+
@front.call(data.to_s)
|
|
19
|
+
self
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def closed?
|
|
23
|
+
@closed
|
|
24
|
+
end
|
|
25
|
+
end
|
|
@@ -1,60 +1,55 @@
|
|
|
1
1
|
module Pubsubstub
|
|
2
|
-
class StreamAction
|
|
2
|
+
class StreamAction
|
|
3
|
+
HEADERS = {
|
|
4
|
+
'Content-Type' => 'text/event-stream',
|
|
5
|
+
'Cache-Control' => 'no-cache',
|
|
6
|
+
'X-Accel-Buffering' => 'no',
|
|
7
|
+
'Connection' => 'keep-alive',
|
|
8
|
+
}.freeze
|
|
3
9
|
include Logging
|
|
4
10
|
|
|
5
11
|
def initialize(*)
|
|
6
|
-
super
|
|
7
12
|
@subscriptions = Set.new
|
|
8
13
|
@mutex = Mutex.new
|
|
9
14
|
end
|
|
10
15
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
'Connection' => 'keep-alive',
|
|
17
|
-
})
|
|
16
|
+
def call(env)
|
|
17
|
+
spawn_helper_threads
|
|
18
|
+
last_event_id = env['HTTP_LAST_EVENT_ID']
|
|
19
|
+
request = Rack::Request.new(env)
|
|
20
|
+
channels = (request.params['channels'] || [:default]).map(&Channel.method(:new))
|
|
18
21
|
|
|
19
|
-
if
|
|
20
|
-
|
|
22
|
+
stream = if use_persistent_connections?
|
|
23
|
+
subscribe_connection(channels, last_event_id)
|
|
21
24
|
else
|
|
22
|
-
|
|
25
|
+
send_scrollback(channels, last_event_id)
|
|
23
26
|
end
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
def call(*)
|
|
27
|
-
spawn_helper_threads
|
|
28
|
-
super
|
|
27
|
+
[200, HEADERS.dup, stream]
|
|
29
28
|
end
|
|
30
29
|
|
|
31
30
|
private
|
|
32
31
|
|
|
33
|
-
def last_event_id
|
|
34
|
-
request.env['HTTP_LAST_EVENT_ID']
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
def send_scrollback
|
|
32
|
+
def send_scrollback(channels, last_event_id)
|
|
38
33
|
scrollback_events = []
|
|
39
34
|
scrollback_events = channels.flat_map { |c| c.scrollback(since: last_event_id) } if last_event_id
|
|
40
35
|
scrollback_events = [Pubsubstub.heartbeat_event] if scrollback_events.empty?
|
|
41
|
-
|
|
36
|
+
Stream.new do |connection|
|
|
42
37
|
scrollback_events.each do |event|
|
|
43
38
|
connection << event.to_message
|
|
44
39
|
end
|
|
45
40
|
end
|
|
46
41
|
end
|
|
47
42
|
|
|
48
|
-
def
|
|
49
|
-
|
|
43
|
+
def use_persistent_connections?
|
|
44
|
+
Pubsubstub.use_persistent_connections && !event_machine?
|
|
50
45
|
end
|
|
51
46
|
|
|
52
|
-
def
|
|
53
|
-
(
|
|
47
|
+
def event_machine?
|
|
48
|
+
defined?(EventMachine) && EventMachine.reactor_running?
|
|
54
49
|
end
|
|
55
50
|
|
|
56
|
-
def subscribe_connection
|
|
57
|
-
|
|
51
|
+
def subscribe_connection(channels, last_event_id)
|
|
52
|
+
Stream.new do |connection|
|
|
58
53
|
subscription = register(channels, connection)
|
|
59
54
|
begin
|
|
60
55
|
subscription.stream(last_event_id)
|
|
@@ -31,7 +31,7 @@ module Pubsubstub
|
|
|
31
31
|
# redis.client.call allow to bypass the client mutex
|
|
32
32
|
# Since we now that the only other possible caller is blocking on reading the socket this is safe
|
|
33
33
|
synchronize do
|
|
34
|
-
redis.
|
|
34
|
+
redis._client.call(['punsubscribe', pubsub_pattern])
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
|
data/lib/pubsubstub/version.rb
CHANGED
data/pubsubstub.gemspec
CHANGED
|
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
19
|
spec.require_paths = ["lib"]
|
|
20
20
|
|
|
21
|
-
spec.add_dependency '
|
|
22
|
-
spec.add_dependency 'redis', "~>
|
|
21
|
+
spec.add_dependency 'rack'
|
|
22
|
+
spec.add_dependency 'redis', "~> 4.0"
|
|
23
23
|
|
|
24
|
-
spec.add_development_dependency "bundler"
|
|
24
|
+
spec.add_development_dependency "bundler"
|
|
25
25
|
end
|
data/spec/channel_spec.rb
CHANGED
data/spec/event_spec.rb
CHANGED
data/spec/publish_action_spec.rb
CHANGED
data/spec/spec_helper.rb
CHANGED
|
@@ -19,7 +19,7 @@ Pubsubstub.logger.level = Logger::DEBUG
|
|
|
19
19
|
# Fake EM
|
|
20
20
|
module EventMachine
|
|
21
21
|
extend self
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
def reactor_running?
|
|
24
24
|
false
|
|
25
25
|
end
|
|
@@ -36,4 +36,9 @@ RSpec.configure do |config|
|
|
|
36
36
|
config.order = 'random'
|
|
37
37
|
|
|
38
38
|
config.before(:each) { Redis.new(url: Pubsubstub.redis_url).flushdb }
|
|
39
|
+
|
|
40
|
+
# Clean threads after finish
|
|
41
|
+
config.after(:each) do
|
|
42
|
+
Thread.list.each { |thread| thread.join(0.5) if thread != Thread.current }
|
|
43
|
+
end
|
|
39
44
|
end
|
data/spec/stream_action_spec.rb
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
+
RSpec.shared_examples "short lived connections" do
|
|
4
|
+
it "immediately returns the scrollback" do
|
|
5
|
+
Pubsubstub.publish('foo', 'bar', id: 1)
|
|
6
|
+
Pubsubstub.publish('foo', 'baz', id: 2)
|
|
7
|
+
|
|
8
|
+
get '/?channels[]=foo', {}, 'HTTP_LAST_EVENT_ID' => 1
|
|
9
|
+
expect(last_response.body).to eq("id: 2\ndata: baz\n\n")
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
it "returns and heartbeat if scrollback is empty" do
|
|
13
|
+
Timecop.freeze('2015-01-01T00:00:00+00:00') do
|
|
14
|
+
get '/'
|
|
15
|
+
message = "id: 1420070400000\nevent: heartbeat\nretry: #{Pubsubstub.reconnect_timeout}\ndata: ping\n\n"
|
|
16
|
+
expect(last_response.body).to eq(message)
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
|
|
3
21
|
describe Pubsubstub::StreamAction do
|
|
4
22
|
let(:app) { Pubsubstub::StreamAction.new }
|
|
5
23
|
|
|
@@ -8,21 +26,18 @@ describe Pubsubstub::StreamAction do
|
|
|
8
26
|
allow(EventMachine).to receive(:reactor_running?).and_return(true)
|
|
9
27
|
end
|
|
10
28
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
Pubsubstub.publish('foo', 'baz', id: 2)
|
|
29
|
+
it_behaves_like "short lived connections"
|
|
30
|
+
end
|
|
14
31
|
|
|
15
|
-
|
|
16
|
-
|
|
32
|
+
context "with persistent connections disabled" do
|
|
33
|
+
around :example do |example|
|
|
34
|
+
previous = Pubsubstub.use_persistent_connections
|
|
35
|
+
Pubsubstub.use_persistent_connections = false
|
|
36
|
+
example.run
|
|
37
|
+
Pubsubstub.use_persistent_connections = previous
|
|
17
38
|
end
|
|
18
39
|
|
|
19
|
-
|
|
20
|
-
Timecop.freeze('2015-01-01T00:00:00+00:00') do
|
|
21
|
-
get '/'
|
|
22
|
-
message = "id: 1420070400000\nevent: heartbeat\nretry: #{Pubsubstub.reconnect_timeout}\ndata: ping\n\n"
|
|
23
|
-
expect(last_response.body).to eq(message)
|
|
24
|
-
end
|
|
25
|
-
end
|
|
40
|
+
it_behaves_like "short lived connections"
|
|
26
41
|
end
|
|
27
42
|
|
|
28
43
|
it "immediately send a heartbeat event if there is no scrollback" do
|
data/spec/subscriber_spec.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
|
-
describe Pubsubstub::Subscriber do
|
|
3
|
+
RSpec.describe Pubsubstub::Subscriber do
|
|
4
4
|
describe "#start" do
|
|
5
5
|
let(:channel) { Pubsubstub::Channel.new('plop') }
|
|
6
6
|
let(:events) { (1..10).map { |i| Pubsubstub::Event.new("refresh ##{i}", id: i) } }
|
|
@@ -10,12 +10,17 @@ describe Pubsubstub::Subscriber do
|
|
|
10
10
|
subject.add_event_listener('plop', -> (event) { published_events << event })
|
|
11
11
|
subscribe_thread = Thread.new { subject.start }
|
|
12
12
|
|
|
13
|
-
expect { subject.subscribed? }.to happen
|
|
13
|
+
expect { subject.subscribed? }.to happen.in_under(1)
|
|
14
14
|
|
|
15
15
|
events.each(&channel.method(:publish))
|
|
16
16
|
|
|
17
|
+
expect { published_events.size == events.size }.to happen.in_under(2)
|
|
18
|
+
|
|
17
19
|
subject.stop
|
|
18
|
-
|
|
20
|
+
|
|
21
|
+
subscribe_thread.join(2)
|
|
22
|
+
|
|
23
|
+
expect { ! subject.subscribed? }.to happen.in_under(1)
|
|
19
24
|
|
|
20
25
|
expect(subscribe_thread).to complete
|
|
21
26
|
|
data/spec/subscription_spec.rb
CHANGED
|
@@ -6,7 +6,7 @@ module HTTPHelpers
|
|
|
6
6
|
queue = Queue.new
|
|
7
7
|
Thread.start do
|
|
8
8
|
begin
|
|
9
|
-
Net::HTTP.start(uri.host, uri.port) do |http|
|
|
9
|
+
Net::HTTP.start(uri.host, uri.port, open_timeout: 10) do |http|
|
|
10
10
|
request = Net::HTTP::Get.new uri.request_uri
|
|
11
11
|
headers.each do |name, value|
|
|
12
12
|
request.add_field(name, value)
|
metadata
CHANGED
|
@@ -1,57 +1,57 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: pubsubstub
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Guillaume Malette
|
|
8
|
-
autorequire:
|
|
8
|
+
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2020-09-27 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
|
-
name:
|
|
14
|
+
name: rack
|
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
|
16
16
|
requirements:
|
|
17
|
-
- - "
|
|
17
|
+
- - ">="
|
|
18
18
|
- !ruby/object:Gem::Version
|
|
19
|
-
version: '
|
|
19
|
+
version: '0'
|
|
20
20
|
type: :runtime
|
|
21
21
|
prerelease: false
|
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
|
23
23
|
requirements:
|
|
24
|
-
- - "
|
|
24
|
+
- - ">="
|
|
25
25
|
- !ruby/object:Gem::Version
|
|
26
|
-
version: '
|
|
26
|
+
version: '0'
|
|
27
27
|
- !ruby/object:Gem::Dependency
|
|
28
28
|
name: redis
|
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
|
30
30
|
requirements:
|
|
31
31
|
- - "~>"
|
|
32
32
|
- !ruby/object:Gem::Version
|
|
33
|
-
version: '
|
|
33
|
+
version: '4.0'
|
|
34
34
|
type: :runtime
|
|
35
35
|
prerelease: false
|
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
|
37
37
|
requirements:
|
|
38
38
|
- - "~>"
|
|
39
39
|
- !ruby/object:Gem::Version
|
|
40
|
-
version: '
|
|
40
|
+
version: '4.0'
|
|
41
41
|
- !ruby/object:Gem::Dependency
|
|
42
42
|
name: bundler
|
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
|
44
44
|
requirements:
|
|
45
|
-
- - "
|
|
45
|
+
- - ">="
|
|
46
46
|
- !ruby/object:Gem::Version
|
|
47
|
-
version: '
|
|
47
|
+
version: '0'
|
|
48
48
|
type: :development
|
|
49
49
|
prerelease: false
|
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
|
51
51
|
requirements:
|
|
52
|
-
- - "
|
|
52
|
+
- - ">="
|
|
53
53
|
- !ruby/object:Gem::Version
|
|
54
|
-
version: '
|
|
54
|
+
version: '0'
|
|
55
55
|
description: Pubsubstub can be added to a rack Application or deployed standalone.
|
|
56
56
|
It uses Redis to do the Pub/Sub
|
|
57
57
|
email:
|
|
@@ -74,13 +74,17 @@ files:
|
|
|
74
74
|
- example/Gemfile
|
|
75
75
|
- example/config.ru
|
|
76
76
|
- example/puma_config.rb
|
|
77
|
+
- gemfiles/Gemfile.rack-1.x
|
|
78
|
+
- gemfiles/Gemfile.rack-1.x.lock
|
|
79
|
+
- gemfiles/Gemfile.rack-2.x
|
|
80
|
+
- gemfiles/Gemfile.rack-2.x.lock
|
|
77
81
|
- lib/pubsubstub.rb
|
|
78
|
-
- lib/pubsubstub/action.rb
|
|
79
82
|
- lib/pubsubstub/application.rb
|
|
80
83
|
- lib/pubsubstub/channel.rb
|
|
81
84
|
- lib/pubsubstub/event.rb
|
|
82
85
|
- lib/pubsubstub/logging.rb
|
|
83
86
|
- lib/pubsubstub/publish_action.rb
|
|
87
|
+
- lib/pubsubstub/stream.rb
|
|
84
88
|
- lib/pubsubstub/stream_action.rb
|
|
85
89
|
- lib/pubsubstub/subscriber.rb
|
|
86
90
|
- lib/pubsubstub/subscription.rb
|
|
@@ -99,7 +103,7 @@ homepage: https://github.com/gmalette/pubsubstub
|
|
|
99
103
|
licenses:
|
|
100
104
|
- MIT
|
|
101
105
|
metadata: {}
|
|
102
|
-
post_install_message:
|
|
106
|
+
post_install_message:
|
|
103
107
|
rdoc_options: []
|
|
104
108
|
require_paths:
|
|
105
109
|
- lib
|
|
@@ -114,9 +118,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
114
118
|
- !ruby/object:Gem::Version
|
|
115
119
|
version: '0'
|
|
116
120
|
requirements: []
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
signing_key:
|
|
121
|
+
rubygems_version: 3.1.2
|
|
122
|
+
signing_key:
|
|
120
123
|
specification_version: 4
|
|
121
124
|
summary: Pubsubstub is a rack middleware to add Pub/Sub
|
|
122
125
|
test_files:
|
data/lib/pubsubstub/action.rb
DELETED