Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(81)

Side by Side Diff: third_party/grpc/src/ruby/spec/server_spec.rb

Issue 1932353002: Initial checkin of gRPC to third_party/ Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 # Copyright 2015, Google Inc.
2 # All rights reserved.
3 #
4 # Redistribution and use in source and binary forms, with or without
5 # modification, are permitted provided that the following conditions are
6 # met:
7 #
8 # * Redistributions of source code must retain the above copyright
9 # notice, this list of conditions and the following disclaimer.
10 # * Redistributions in binary form must reproduce the above
11 # copyright notice, this list of conditions and the following disclaimer
12 # in the documentation and/or other materials provided with the
13 # distribution.
14 # * Neither the name of Google Inc. nor the names of its
15 # contributors may be used to endorse or promote products derived from
16 # this software without specific prior written permission.
17 #
18 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29
30 require 'grpc'
31
32 def load_test_certs
33 test_root = File.join(File.dirname(__FILE__), 'testdata')
34 files = ['ca.pem', 'server1.key', 'server1.pem']
35 contents = files.map { |f| File.open(File.join(test_root, f)).read }
36 [contents[0], [{ private_key: contents[1], cert_chain: contents[2] }], false]
37 end
38
39 Server = GRPC::Core::Server
40
41 describe Server do
42 def create_test_cert
43 GRPC::Core::ServerCredentials.new(*load_test_certs)
44 end
45
46 before(:each) do
47 @cq = GRPC::Core::CompletionQueue.new
48 end
49
50 describe '#start' do
51 it 'runs without failing' do
52 blk = proc { Server.new(@cq, nil).start }
53 expect(&blk).to_not raise_error
54 end
55
56 it 'fails if the server is closed' do
57 s = Server.new(@cq, nil)
58 s.close(@cq)
59 expect { s.start }.to raise_error(RuntimeError)
60 end
61 end
62
63 describe '#destroy' do
64 it 'destroys a server ok' do
65 s = start_a_server
66 blk = proc { s.destroy(@cq) }
67 expect(&blk).to_not raise_error
68 end
69
70 it 'can be called more than once without error' do
71 s = start_a_server
72 begin
73 blk = proc { s.destroy(@cq) }
74 expect(&blk).to_not raise_error
75 blk.call
76 expect(&blk).to_not raise_error
77 ensure
78 s.close(@cq)
79 end
80 end
81 end
82
83 describe '#close' do
84 it 'closes a server ok' do
85 s = start_a_server
86 begin
87 blk = proc { s.close(@cq) }
88 expect(&blk).to_not raise_error
89 ensure
90 s.close(@cq)
91 end
92 end
93
94 it 'can be called more than once without error' do
95 s = start_a_server
96 blk = proc { s.close(@cq) }
97 expect(&blk).to_not raise_error
98 blk.call
99 expect(&blk).to_not raise_error
100 end
101 end
102
103 describe '#add_http_port' do
104 describe 'for insecure servers' do
105 it 'runs without failing' do
106 blk = proc do
107 s = Server.new(@cq, nil)
108 s.add_http2_port('localhost:0', :this_port_is_insecure)
109 s.close(@cq)
110 end
111 expect(&blk).to_not raise_error
112 end
113
114 it 'fails if the server is closed' do
115 s = Server.new(@cq, nil)
116 s.close(@cq)
117 blk = proc do
118 s.add_http2_port('localhost:0', :this_port_is_insecure)
119 end
120 expect(&blk).to raise_error(RuntimeError)
121 end
122 end
123
124 describe 'for secure servers' do
125 let(:cert) { create_test_cert }
126 it 'runs without failing' do
127 blk = proc do
128 s = Server.new(@cq, nil)
129 s.add_http2_port('localhost:0', cert)
130 s.close(@cq)
131 end
132 expect(&blk).to_not raise_error
133 end
134
135 it 'fails if the server is closed' do
136 s = Server.new(@cq, nil)
137 s.close(@cq)
138 blk = proc { s.add_http2_port('localhost:0', cert) }
139 expect(&blk).to raise_error(RuntimeError)
140 end
141 end
142 end
143
144 shared_examples '#new' do
145 it 'takes a completion queue with nil channel args' do
146 expect { Server.new(@cq, nil) }.to_not raise_error
147 end
148
149 it 'does not take a hash with bad keys as channel args' do
150 blk = construct_with_args(Object.new => 1)
151 expect(&blk).to raise_error TypeError
152 blk = construct_with_args(1 => 1)
153 expect(&blk).to raise_error TypeError
154 end
155
156 it 'does not take a hash with bad values as channel args' do
157 blk = construct_with_args(symbol: Object.new)
158 expect(&blk).to raise_error TypeError
159 blk = construct_with_args('1' => {})
160 expect(&blk).to raise_error TypeError
161 end
162
163 it 'can take a hash with a symbol key as channel args' do
164 blk = construct_with_args(a_symbol: 1)
165 expect(&blk).to_not raise_error
166 end
167
168 it 'can take a hash with a string key as channel args' do
169 blk = construct_with_args('a_symbol' => 1)
170 expect(&blk).to_not raise_error
171 end
172
173 it 'can take a hash with a string value as channel args' do
174 blk = construct_with_args(a_symbol: '1')
175 expect(&blk).to_not raise_error
176 end
177
178 it 'can take a hash with a symbol value as channel args' do
179 blk = construct_with_args(a_symbol: :another_symbol)
180 expect(&blk).to_not raise_error
181 end
182
183 it 'can take a hash with a numeric value as channel args' do
184 blk = construct_with_args(a_symbol: 1)
185 expect(&blk).to_not raise_error
186 end
187
188 it 'can take a hash with many args as channel args' do
189 args = Hash[127.times.collect { |x| [x.to_s, x] }]
190 blk = construct_with_args(args)
191 expect(&blk).to_not raise_error
192 end
193 end
194
195 describe '#new with an insecure channel' do
196 def construct_with_args(a)
197 proc { Server.new(@cq, a) }
198 end
199
200 it_behaves_like '#new'
201 end
202
203 def start_a_server
204 s = Server.new(@cq, nil)
205 s.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
206 s.start
207 s
208 end
209 end
OLDNEW
« no previous file with comments | « third_party/grpc/src/ruby/spec/server_credentials_spec.rb ('k') | third_party/grpc/src/ruby/spec/spec_helper.rb » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698