sse-rails-engine 1.2.0 → 1.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/sse_rails_engine/manager.rb +5 -3
- data/lib/sse_rails_engine/version.rb +1 -1
- data/test/dummy/log/test.log +67 -5
- data/test/lib/sse_rails_engine/manager_test.rb +26 -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: 5ba7d9cea724ef6cd38b1ae06f4b0a037e575cee
|
4
|
+
data.tar.gz: 8aef607c6e1908f4a07571842e59667271d44da1
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c433f71bb37b808669f96d6cddcb77c7547258329d5c3d40149a735375a807a3ae1a46534790a424b91d3631d4e8e72cbc5e172684f2955b24cbf18efbf84984
|
7
|
+
data.tar.gz: 7d7965dd774c11512ffc7d156ef52753b0c478a3759dd36486e64fcd1305cecbebe085c65443974ff6862ba8837a02f9b21b76917f957c732a87f76fe395b600
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module SseRailsEngine
|
2
2
|
class Manager
|
3
|
-
|
3
|
+
RackHijackUnsupported = Class.new RuntimeError
|
4
|
+
|
5
|
+
attr_reader :connections, :heartbeat_thread
|
4
6
|
|
5
7
|
SSE_HEADER = ["HTTP/1.1 200 OK\r\n",
|
6
8
|
"Content-Type: text/event-stream\r\n",
|
@@ -21,7 +23,7 @@ module SseRailsEngine
|
|
21
23
|
# Perform full hijack of socket (http://old.blog.phusion.nl/2013/01/23/the-new-rack-socket-hijacking-api/)
|
22
24
|
SseRailsEngine.manager.open_connection(socket)
|
23
25
|
else
|
24
|
-
raise 'This Rack server does not support hijacking, ensure you are using >= v1.5 of Rack'
|
26
|
+
raise RackHijackUnsupported, 'This Rack server does not support hijacking, ensure you are using >= v1.5 of Rack'
|
25
27
|
end
|
26
28
|
end
|
27
29
|
|
@@ -65,7 +67,7 @@ module SseRailsEngine
|
|
65
67
|
|
66
68
|
def start_heartbeats
|
67
69
|
Rails.logger.debug 'Starting SSE heartbeat thread!'
|
68
|
-
Thread.new do
|
70
|
+
@heartbeat_thread = Thread.new do
|
69
71
|
loop do
|
70
72
|
sleep SseRailsEngine.heartbeat_interval
|
71
73
|
send_event('heartbeat', '')
|
data/test/dummy/log/test.log
CHANGED
@@ -1,11 +1,73 @@
|
|
1
1
|
Starting SSE heartbeat thread!
|
2
2
|
Starting SSE heartbeat thread!
|
3
|
-
New SSE Client connected: #<StringIO:0x007fa8041d31a8>
|
4
|
-
SSE Client disconnected: #<StringIO:0x007fa8041d31a8>
|
5
3
|
Starting SSE heartbeat thread!
|
6
|
-
New SSE Client connected: #<StringIO:0x007fa8041d0020>
|
7
4
|
Starting SSE heartbeat thread!
|
8
|
-
New SSE Client connected: #<StringIO:0x007fa8041c9338>
|
9
5
|
Starting SSE heartbeat thread!
|
10
6
|
Starting SSE heartbeat thread!
|
11
|
-
|
7
|
+
Starting SSE heartbeat thread!
|
8
|
+
Starting SSE heartbeat thread!
|
9
|
+
Starting SSE heartbeat thread!
|
10
|
+
Starting SSE heartbeat thread!
|
11
|
+
Starting SSE heartbeat thread!
|
12
|
+
Starting SSE heartbeat thread!
|
13
|
+
Starting SSE heartbeat thread!
|
14
|
+
Starting SSE heartbeat thread!
|
15
|
+
Starting SSE heartbeat thread!
|
16
|
+
Starting SSE heartbeat thread!
|
17
|
+
New SSE Client connected: #<StringIO:0x007fc5cb2272a0>
|
18
|
+
Failed to send event to SSE: #<StringIO:0x007fc5cb2272a0> (foo, bar - RuntimeError (RuntimeError
|
19
|
+
Starting SSE heartbeat thread!
|
20
|
+
Starting SSE heartbeat thread!
|
21
|
+
New SSE Client connected: #<StringIO:0x007fe0c42c4190>
|
22
|
+
Starting SSE heartbeat thread!
|
23
|
+
Starting SSE heartbeat thread!
|
24
|
+
Starting SSE heartbeat thread!
|
25
|
+
Starting SSE heartbeat thread!
|
26
|
+
Starting SSE heartbeat thread!
|
27
|
+
Starting SSE heartbeat thread!
|
28
|
+
Starting SSE heartbeat thread!
|
29
|
+
Starting SSE heartbeat thread!
|
30
|
+
Starting SSE heartbeat thread!
|
31
|
+
Starting SSE heartbeat thread!
|
32
|
+
Starting SSE heartbeat thread!
|
33
|
+
Starting SSE heartbeat thread!
|
34
|
+
Starting SSE heartbeat thread!
|
35
|
+
Starting SSE heartbeat thread!
|
36
|
+
Starting SSE heartbeat thread!
|
37
|
+
Starting SSE heartbeat thread!
|
38
|
+
Starting SSE heartbeat thread!
|
39
|
+
New SSE Client connected: #<StringIO:0x007f97591563a8>
|
40
|
+
SSE Client disconnected: #<StringIO:0x007f97591563a8>
|
41
|
+
Starting SSE heartbeat thread!
|
42
|
+
New SSE Client connected: #<StringIO:0x007f975914ef18>
|
43
|
+
Starting SSE heartbeat thread!
|
44
|
+
New SSE Client connected: #<StringIO:0x007f97591474e8>
|
45
|
+
Failed to send event to SSE: #<StringIO:0x007f97591474e8> (foo, bar - RuntimeError (RuntimeError
|
46
|
+
Starting SSE heartbeat thread!
|
47
|
+
Starting SSE heartbeat thread!
|
48
|
+
New SSE Client connected: #<StringIO:0x007f975913dba0>
|
49
|
+
Starting SSE heartbeat thread!
|
50
|
+
Starting SSE heartbeat thread!
|
51
|
+
Starting SSE heartbeat thread!
|
52
|
+
New SSE Client connected: #<StringIO:0x007f9759124f88>
|
53
|
+
Starting SSE heartbeat thread!
|
54
|
+
New SSE Client connected: #<StringIO:0x007f975911ec50>
|
55
|
+
Starting SSE heartbeat thread!
|
56
|
+
Starting SSE heartbeat thread!
|
57
|
+
Starting SSE heartbeat thread!
|
58
|
+
New SSE Client connected: #<StringIO:0x007ff3392c3a88>
|
59
|
+
Failed to send event to SSE: #<StringIO:0x007ff3392c3a88> (foo, bar - RuntimeError (RuntimeError
|
60
|
+
Starting SSE heartbeat thread!
|
61
|
+
New SSE Client connected: #<StringIO:0x007ff3392ba4b0>
|
62
|
+
Starting SSE heartbeat thread!
|
63
|
+
New SSE Client connected: #<StringIO:0x007ff3392aad08>
|
64
|
+
Starting SSE heartbeat thread!
|
65
|
+
Starting SSE heartbeat thread!
|
66
|
+
New SSE Client connected: #<StringIO:0x007ff339282bf0>
|
67
|
+
Starting SSE heartbeat thread!
|
68
|
+
New SSE Client connected: #<StringIO:0x007ff33927b4b8>
|
69
|
+
SSE Client disconnected: #<StringIO:0x007ff33927b4b8>
|
70
|
+
Starting SSE heartbeat thread!
|
71
|
+
New SSE Client connected: #<StringIO:0x007ff339278948>
|
72
|
+
Starting SSE heartbeat thread!
|
73
|
+
Starting SSE heartbeat thread!
|
@@ -13,6 +13,11 @@ describe SseRailsEngine::Manager do
|
|
13
13
|
SseRailsEngine::Manager.stubs(:start_heartbeats).returns(true)
|
14
14
|
end
|
15
15
|
|
16
|
+
it 'ensures rack supports hijacking' do
|
17
|
+
env['rack.hijack'] = nil
|
18
|
+
assert_raises(SseRailsEngine::Manager::RackHijackUnsupported) { manager.register(env) }
|
19
|
+
end
|
20
|
+
|
16
21
|
it 'registers new response streams' do
|
17
22
|
manager.connections.size.must_equal 0
|
18
23
|
manager.register(env)
|
@@ -32,6 +37,15 @@ describe SseRailsEngine::Manager do
|
|
32
37
|
manager.connections.size.must_equal 0
|
33
38
|
end
|
34
39
|
|
40
|
+
it 'closes connection when failed sending event to client' do
|
41
|
+
ActionController::Live::SSE.any_instance.stubs(:write).raises(RuntimeError)
|
42
|
+
|
43
|
+
manager.register(env)
|
44
|
+
manager.connections.size.must_equal 1
|
45
|
+
manager.send_event('foo', 'bar')
|
46
|
+
manager.connections.size.must_equal 0
|
47
|
+
end
|
48
|
+
|
35
49
|
it 'writes string event to stream' do
|
36
50
|
manager.register(env)
|
37
51
|
manager.send_event('foo', 'bar')
|
@@ -43,4 +57,16 @@ describe SseRailsEngine::Manager do
|
|
43
57
|
manager.send_event('foo', { a: 123, 'b' => 'abc', c: { foo: 'bar' } })
|
44
58
|
env['rack.hijack_io'].string.must_equal(SseRailsEngine::Manager::SSE_HEADER + "event: foo\ndata: {\"a\":123,\"b\":\"abc\",\"c\":{\"foo\":\"bar\"}}\n\n")
|
45
59
|
end
|
60
|
+
|
61
|
+
it 'writes minimum headers to rack middleware' do
|
62
|
+
manager.call(env).must_equal [ -1, {}, []]
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'ensures heartbeat is sent' do
|
66
|
+
SseRailsEngine.stubs(:heartbeat_interval).returns(0,5)
|
67
|
+
SseRailsEngine::Manager.unstub(:start_heartbeats)
|
68
|
+
SseRailsEngine::Manager.any_instance.expects(:send_event).once
|
69
|
+
manager = SseRailsEngine::Manager.new
|
70
|
+
sleep 0.2
|
71
|
+
end
|
46
72
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sse-rails-engine
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Shane Hender
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|