ds9 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,169 @@
1
+ require 'helper'
2
+
3
+ class TestClient < DS9::TestCase
4
+ def test_outbound_queue_size
5
+ server ,= pipe { |req, res| }
6
+
7
+ assert_equal 1, server.outbound_queue_size
8
+ server.submit_shutdown
9
+ assert_operator server.outbound_queue_size, :>, 1
10
+ end
11
+
12
+ def test_blow_up
13
+ server, client = pipe { |req, res| }
14
+ client.writer.close
15
+
16
+ ex = assert_raises(DS9::Exception) do
17
+ server.receive
18
+ end
19
+ assert ex.code
20
+ end
21
+
22
+ def test_submit_shutdown
23
+ server, client = pipe { |req, res| }
24
+
25
+ server.submit_shutdown
26
+ server.send
27
+ client.receive
28
+ assert_predicate client.frames.last, :goaway?
29
+ end
30
+
31
+ def test_submit_goaway
32
+ server, client = pipe { |req, res| }
33
+ server.submit_goaway 0, 0
34
+ server.send
35
+ client.receive
36
+ assert_predicate client.frames.last, :goaway?
37
+ end
38
+
39
+ def test_stream_remote_closed?
40
+ server, client = pipe do |req, res|
41
+ refute req.stream.stream_remote_closed? req.stream_id
42
+ refute req.stream.stream_local_closed? req.stream_id
43
+ res.submit_response [[":status", '200'],
44
+ ["server", 'test server'],
45
+ ["date", 'Sat, 27 Jun 2015 17:29:21 GMT'],
46
+ ["X-Whatever", "blah"]]
47
+ res.finish 'omglol'
48
+ end
49
+
50
+ s = Thread.new { server.run }
51
+ c = Thread.new { client.run }
52
+
53
+ client.submit_request [
54
+ [':method', 'GET'],
55
+ [':path', '/'],
56
+ [':scheme', 'https'],
57
+ [':authority', ['localhost', '8080'].join(':')],
58
+ ['accept', '*/*'],
59
+ ['user-agent', 'test'],
60
+ ]
61
+
62
+ responses = []
63
+ while response = client.responses.pop
64
+ responses << response
65
+ if responses.length == 1
66
+ client.terminate_session DS9::NO_ERROR
67
+ end
68
+ end
69
+
70
+ s.join
71
+ c.join
72
+ end
73
+
74
+ def test_ping
75
+ server, client = pipe { |req, res| }
76
+
77
+ server.submit_ping
78
+ server.send
79
+ client.receive
80
+ assert_predicate client.frames.last, :ping?
81
+ end
82
+
83
+ def test_push
84
+ body = 'omglolwut'
85
+
86
+ server, client = pipe do |req, res|
87
+ case req.path
88
+ when '/'
89
+ res.push([[':method', 'GET'],
90
+ [':path', '/omglol'],
91
+ [':scheme', 'http'],
92
+ [':authority', 'localhost:8080']])
93
+
94
+ res.submit_response [[":status", '200'],
95
+ ["server", 'test server'],
96
+ ["date", 'Sat, 27 Jun 2015 17:29:21 GMT'],
97
+ ["X-Whatever", "blah"]]
98
+ when '/omglol'
99
+ res.submit_response [[":status", '200'],
100
+ ["server", 'test server'],
101
+ ["date", 'Sat, 27 Jun 2015 17:29:21 GMT'],
102
+ ["X-Whatever", "blah"]]
103
+ res.finish 'lololol'
104
+ end
105
+
106
+ res.finish body
107
+ end
108
+
109
+ s = Thread.new { server.run }
110
+ c = Thread.new { client.run }
111
+
112
+ client.submit_request [
113
+ [':method', 'GET'],
114
+ [':path', '/'],
115
+ [':scheme', 'https'],
116
+ [':authority', ['localhost', '8080'].join(':')],
117
+ ['accept', '*/*'],
118
+ ['user-agent', 'test'],
119
+ ]
120
+
121
+ responses = []
122
+ while response = client.responses.pop
123
+ responses << response
124
+ if responses.length == 2
125
+ client.terminate_session DS9::NO_ERROR
126
+ end
127
+ end
128
+
129
+ s.join
130
+ c.join
131
+ assert_equal ["omglolwut", "lololol"], responses.map(&:body).map(&:string)
132
+ end
133
+
134
+ def test_request
135
+ body = 'omglolwut'
136
+
137
+ server, client = pipe do |req, res|
138
+ res.submit_response [[":status", '200'],
139
+ ["server", 'test server'],
140
+ ["date", 'Sat, 27 Jun 2015 17:29:21 GMT'],
141
+ ["X-Whatever", "blah"]]
142
+ res.finish body
143
+ end
144
+
145
+ client.submit_request [
146
+ [':method', 'GET'],
147
+ [':path', '/'],
148
+ [':scheme', 'https'],
149
+ [':authority', ['localhost', '8080'].join(':')],
150
+ ['accept', '*/*'],
151
+ ['user-agent', 'test'],
152
+ ]
153
+
154
+ s = Thread.new { server.run }
155
+ c = Thread.new { client.run }
156
+
157
+ responses = []
158
+ while response = client.responses.pop
159
+ responses << response
160
+ if responses.length == 1
161
+ client.terminate_session DS9::NO_ERROR
162
+ end
163
+ end
164
+
165
+ s.join
166
+ c.join
167
+ assert_equal ["omglolwut"], responses.map(&:body).map(&:string)
168
+ end
169
+ end
@@ -0,0 +1,45 @@
1
+ require 'helper'
2
+
3
+ class TestDS9 < Minitest::Test
4
+ def test_sanity
5
+ assert DS9::PROTO_VERSION_ID
6
+ end
7
+
8
+ def test_session_allocation
9
+ assert DS9::Server.new
10
+ end
11
+
12
+ def test_session_submit_settings
13
+ session = DS9::Server.new
14
+ session.submit_settings [[DS9::Settings::MAX_CONCURRENT_STREAMS, 100]]
15
+ end
16
+
17
+ def test_send
18
+ called = false
19
+ session = Class.new(DS9::Server) {
20
+ define_method :send_event do |string|
21
+ called = string
22
+ string.length
23
+ end
24
+ }.new
25
+
26
+ session.submit_settings [[DS9::Settings::MAX_CONCURRENT_STREAMS, 100]]
27
+ session.send
28
+ assert called
29
+ end
30
+
31
+ def test_want_read?
32
+ session = DS9::Server.new
33
+ session.submit_settings [[DS9::Settings::MAX_CONCURRENT_STREAMS, 100]]
34
+ assert_predicate session, :want_write?
35
+ end
36
+
37
+ def test_want_write?
38
+ session = DS9::Server.new
39
+ session.submit_settings [[DS9::Settings::MAX_CONCURRENT_STREAMS, 100]]
40
+ assert_predicate session, :want_write?
41
+
42
+ session = DS9::Server.new
43
+ refute_predicate session, :want_write?
44
+ end
45
+ end
metadata ADDED
@@ -0,0 +1,121 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ds9
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Aaron Patterson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-01-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: minitest
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '5.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '5.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rdoc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake-compiler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 0.4.1
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 0.4.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: hoe
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.14'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.14'
69
+ description: |-
70
+ This library allows you to write HTTP/2 clients and servers. It is a wrapper
71
+ around nghttp2.
72
+ email:
73
+ - aaron@tenderlovemaking.com
74
+ executables: []
75
+ extensions:
76
+ - ext/ds9/extconf.rb
77
+ extra_rdoc_files:
78
+ - CHANGELOG.md
79
+ - Manifest.txt
80
+ - README.md
81
+ files:
82
+ - ".autotest"
83
+ - CHANGELOG.md
84
+ - Manifest.txt
85
+ - README.md
86
+ - Rakefile
87
+ - ext/ds9/ds9.c
88
+ - ext/ds9/ds9.h
89
+ - ext/ds9/ds9_frames.c
90
+ - ext/ds9/extconf.rb
91
+ - lib/ds9.rb
92
+ - test/helper.rb
93
+ - test/test_client.rb
94
+ - test/test_ds9.rb
95
+ homepage: https://github.com/tenderlove/ds9
96
+ licenses:
97
+ - MIT
98
+ metadata: {}
99
+ post_install_message:
100
+ rdoc_options:
101
+ - "--main"
102
+ - README.md
103
+ require_paths:
104
+ - lib
105
+ required_ruby_version: !ruby/object:Gem::Requirement
106
+ requirements:
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: 2.2.2
110
+ required_rubygems_version: !ruby/object:Gem::Requirement
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ version: '0'
115
+ requirements: []
116
+ rubyforge_project:
117
+ rubygems_version: 2.5.1
118
+ signing_key:
119
+ specification_version: 4
120
+ summary: This library allows you to write HTTP/2 clients and servers
121
+ test_files: []