grpc 1.58.3-aarch64-linux
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/etc/roots.pem +4337 -0
- data/grpc_c.32-msvcrt.ruby +0 -0
- data/grpc_c.64-msvcrt.ruby +0 -0
- data/grpc_c.64-ucrt.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +40 -0
- data/src/ruby/bin/math_server.rb +191 -0
- data/src/ruby/bin/math_services_pb.rb +51 -0
- data/src/ruby/bin/noproto_client.rb +93 -0
- data/src/ruby/bin/noproto_server.rb +97 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
- data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
- data/src/ruby/ext/grpc/ext-export.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +208 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1075 -0
- data/src/ruby/ext/grpc/rb_call.h +57 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +340 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +875 -0
- data/src/ruby/ext/grpc/rb_channel.h +35 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +170 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
- data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
- data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
- data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
- data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
- data/src/ruby/ext/grpc/rb_event_thread.c +161 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
- data/src/ruby/ext/grpc/rb_grpc.c +496 -0
- data/src/ruby/ext/grpc/rb_grpc.h +83 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +599 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +904 -0
- data/src/ruby/ext/grpc/rb_loader.c +61 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +405 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +258 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
- data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.c +169 -0
- data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
- data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.0/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
- data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
- data/src/ruby/lib/grpc/errors.rb +277 -0
- data/src/ruby/lib/grpc/generic/active_call.rb +670 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
- data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
- data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
- data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
- data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
- data/src/ruby/lib/grpc/generic/service.rb +211 -0
- data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
- data/src/ruby/lib/grpc/grpc.rb +24 -0
- data/src/ruby/lib/grpc/logconfig.rb +44 -0
- data/src/ruby/lib/grpc/notifier.rb +45 -0
- data/src/ruby/lib/grpc/structs.rb +15 -0
- data/src/ruby/lib/grpc/version.rb +18 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +46 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +42 -0
- data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
- data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
- data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
- data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
- data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +38 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +63 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +40 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
- data/src/ruby/pb/test/client.rb +785 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +415 -0
- data/src/ruby/spec/call_credentials_spec.rb +42 -0
- data/src/ruby/spec/call_spec.rb +180 -0
- data/src/ruby/spec/channel_connection_spec.rb +126 -0
- data/src/ruby/spec/channel_credentials_spec.rb +124 -0
- data/src/ruby/spec/channel_spec.rb +207 -0
- data/src/ruby/spec/client_auth_spec.rb +152 -0
- data/src/ruby/spec/client_server_spec.rb +676 -0
- data/src/ruby/spec/compression_options_spec.rb +149 -0
- data/src/ruby/spec/debug_message_spec.rb +134 -0
- data/src/ruby/spec/error_sanity_spec.rb +49 -0
- data/src/ruby/spec/errors_spec.rb +142 -0
- data/src/ruby/spec/generic/active_call_spec.rb +692 -0
- data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
- data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
- data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
- data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
- data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
- data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
- data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
- data/src/ruby/spec/generic/service_spec.rb +263 -0
- data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
- data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
- data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
- data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
- data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
- data/src/ruby/spec/server_credentials_spec.rb +104 -0
- data/src/ruby/spec/server_spec.rb +231 -0
- data/src/ruby/spec/spec_helper.rb +61 -0
- data/src/ruby/spec/support/helpers.rb +107 -0
- data/src/ruby/spec/support/services.rb +160 -0
- data/src/ruby/spec/testdata/README +1 -0
- data/src/ruby/spec/testdata/ca.pem +20 -0
- data/src/ruby/spec/testdata/client.key +28 -0
- data/src/ruby/spec/testdata/client.pem +20 -0
- data/src/ruby/spec/testdata/server1.key +28 -0
- data/src/ruby/spec/testdata/server1.pem +22 -0
- data/src/ruby/spec/time_consts_spec.rb +74 -0
- data/src/ruby/spec/user_agent_spec.rb +74 -0
- metadata +406 -0
@@ -0,0 +1,236 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
require 'grpc/health/v1/health_pb'
|
17
|
+
require 'grpc/health/checker'
|
18
|
+
require 'open3'
|
19
|
+
require 'tmpdir'
|
20
|
+
|
21
|
+
def can_run_codegen_check
|
22
|
+
system('which grpc_ruby_plugin') && system('which protoc')
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'Health protobuf code generation' do
|
26
|
+
context 'the health service file used by grpc/health/checker' do
|
27
|
+
if !can_run_codegen_check
|
28
|
+
skip 'protoc || grpc_ruby_plugin missing, cannot verify health code-gen'
|
29
|
+
else
|
30
|
+
it 'should already be loaded indirectly i.e, used by the other specs' do
|
31
|
+
expect(require('grpc/health/v1/health_services_pb')).to be(false)
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'should have the same content as created by code generation' do
|
35
|
+
root_dir = File.join(File.dirname(__FILE__), '..', '..', '..', '..')
|
36
|
+
pb_dir = File.join(root_dir, 'proto')
|
37
|
+
|
38
|
+
# Get the current content
|
39
|
+
service_path = File.join(root_dir, 'ruby', 'pb', 'grpc',
|
40
|
+
'health', 'v1', 'health_services_pb.rb')
|
41
|
+
want = nil
|
42
|
+
File.open(service_path) { |f| want = f.read }
|
43
|
+
|
44
|
+
# Regenerate it
|
45
|
+
plugin, = Open3.capture2('which', 'grpc_ruby_plugin')
|
46
|
+
plugin = plugin.strip
|
47
|
+
got = nil
|
48
|
+
Dir.mktmpdir do |tmp_dir|
|
49
|
+
gen_out = File.join(tmp_dir, 'grpc', 'health', 'v1',
|
50
|
+
'health_services_pb.rb')
|
51
|
+
pid = spawn(
|
52
|
+
'protoc',
|
53
|
+
'-I.',
|
54
|
+
'grpc/health/v1/health.proto',
|
55
|
+
"--grpc_out=#{tmp_dir}",
|
56
|
+
"--plugin=protoc-gen-grpc=#{plugin}",
|
57
|
+
chdir: pb_dir)
|
58
|
+
Process.wait(pid)
|
59
|
+
File.open(gen_out) { |f| got = f.read }
|
60
|
+
end
|
61
|
+
expect(got).to eq(want)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe Grpc::Health::Checker do
|
68
|
+
StatusCodes = GRPC::Core::StatusCodes
|
69
|
+
ServingStatus = Grpc::Health::V1::HealthCheckResponse::ServingStatus
|
70
|
+
HCResp = Grpc::Health::V1::HealthCheckResponse
|
71
|
+
HCReq = Grpc::Health::V1::HealthCheckRequest
|
72
|
+
success_tests =
|
73
|
+
[
|
74
|
+
{
|
75
|
+
desc: 'the service is not specified',
|
76
|
+
service: ''
|
77
|
+
}, {
|
78
|
+
desc: 'the service is specified',
|
79
|
+
service: 'fake-service-1'
|
80
|
+
}
|
81
|
+
]
|
82
|
+
|
83
|
+
context 'initialization' do
|
84
|
+
it 'can be constructed with no args' do
|
85
|
+
checker = Grpc::Health::Checker.new
|
86
|
+
expect(checker).to_not be(nil)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
context 'method `add_status` and `check`' do
|
91
|
+
success_tests.each do |t|
|
92
|
+
it "should succeed when #{t[:desc]}" do
|
93
|
+
checker = Grpc::Health::Checker.new
|
94
|
+
checker.add_status(t[:service], ServingStatus::NOT_SERVING)
|
95
|
+
got = checker.check(HCReq.new(service: t[:service]), nil)
|
96
|
+
want = HCResp.new(status: ServingStatus::NOT_SERVING)
|
97
|
+
expect(got).to eq(want)
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
context 'method `add_statuses`' do
|
103
|
+
it 'should add status to each service' do
|
104
|
+
checker = Grpc::Health::Checker.new
|
105
|
+
checker.add_statuses(
|
106
|
+
'service1' => ServingStatus::SERVING,
|
107
|
+
'service2' => ServingStatus::NOT_SERVING
|
108
|
+
)
|
109
|
+
service1_health = checker.check(HCReq.new(service: 'service1'), nil)
|
110
|
+
service2_health = checker.check(HCReq.new(service: 'service2'), nil)
|
111
|
+
expect(service1_health).to eq(HCResp.new(status: ServingStatus::SERVING))
|
112
|
+
expect(service2_health).to eq(HCResp.new(status: ServingStatus::NOT_SERVING))
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
context 'method `set_status_for_services`' do
|
117
|
+
it 'should add given status to all given services' do
|
118
|
+
checker = Grpc::Health::Checker.new
|
119
|
+
checker.set_status_for_services(
|
120
|
+
ServingStatus::SERVING,
|
121
|
+
'service1',
|
122
|
+
'service2'
|
123
|
+
)
|
124
|
+
service1_health = checker.check(HCReq.new(service: 'service1'), nil)
|
125
|
+
service2_health = checker.check(HCReq.new(service: 'service2'), nil)
|
126
|
+
expect(service1_health).to eq(HCResp.new(status: ServingStatus::SERVING))
|
127
|
+
expect(service2_health).to eq(HCResp.new(status: ServingStatus::SERVING))
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context 'method `check`' do
|
132
|
+
success_tests.each do |t|
|
133
|
+
it "should fail with NOT_FOUND when #{t[:desc]}" do
|
134
|
+
checker = Grpc::Health::Checker.new
|
135
|
+
blk = proc do
|
136
|
+
checker.check(HCReq.new(service: t[:service]), nil)
|
137
|
+
end
|
138
|
+
expected_msg = /#{StatusCodes::NOT_FOUND}/
|
139
|
+
expect(&blk).to raise_error GRPC::NotFound, expected_msg
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
context 'method `clear_status`' do
|
145
|
+
success_tests.each do |t|
|
146
|
+
it "should fail after clearing status when #{t[:desc]}" do
|
147
|
+
checker = Grpc::Health::Checker.new
|
148
|
+
checker.add_status(t[:service], ServingStatus::NOT_SERVING)
|
149
|
+
got = checker.check(HCReq.new(service: t[:service]), nil)
|
150
|
+
want = HCResp.new(status: ServingStatus::NOT_SERVING)
|
151
|
+
expect(got).to eq(want)
|
152
|
+
|
153
|
+
checker.clear_status(t[:service])
|
154
|
+
blk = proc do
|
155
|
+
checker.check(HCReq.new(service: t[:service]), nil)
|
156
|
+
end
|
157
|
+
expected_msg = /#{StatusCodes::NOT_FOUND}/
|
158
|
+
expect(&blk).to raise_error GRPC::NotFound, expected_msg
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context 'method `clear_all`' do
|
164
|
+
it 'should return NOT_FOUND after being invoked' do
|
165
|
+
checker = Grpc::Health::Checker.new
|
166
|
+
success_tests.each do |t|
|
167
|
+
checker.add_status(t[:service], ServingStatus::NOT_SERVING)
|
168
|
+
got = checker.check(HCReq.new(service: t[:service]), nil)
|
169
|
+
want = HCResp.new(status: ServingStatus::NOT_SERVING)
|
170
|
+
expect(got).to eq(want)
|
171
|
+
end
|
172
|
+
|
173
|
+
checker.clear_all
|
174
|
+
|
175
|
+
success_tests.each do |t|
|
176
|
+
blk = proc do
|
177
|
+
checker.check(HCReq.new(service: t[:service]), nil)
|
178
|
+
end
|
179
|
+
expected_msg = /#{StatusCodes::NOT_FOUND}/
|
180
|
+
expect(&blk).to raise_error GRPC::NotFound, expected_msg
|
181
|
+
end
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe 'running on RpcServer' do
|
186
|
+
RpcServer = GRPC::RpcServer
|
187
|
+
CheckerStub = Grpc::Health::Checker.rpc_stub_class
|
188
|
+
|
189
|
+
before(:each) do
|
190
|
+
server_host = '0.0.0.0:0'
|
191
|
+
@client_opts = { channel_override: @ch }
|
192
|
+
server_opts = {
|
193
|
+
poll_period: 1
|
194
|
+
}
|
195
|
+
@srv = new_rpc_server_for_testing(**server_opts)
|
196
|
+
server_port = @srv.add_http2_port(server_host, :this_port_is_insecure)
|
197
|
+
@host = "localhost:#{server_port}"
|
198
|
+
@ch = GRPC::Core::Channel.new(@host, nil, :this_channel_is_insecure)
|
199
|
+
end
|
200
|
+
|
201
|
+
after(:each) do
|
202
|
+
@srv.stop
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should receive the correct status', server: true do
|
206
|
+
Thread.abort_on_exception = true
|
207
|
+
checker = Grpc::Health::Checker.new
|
208
|
+
@srv.handle(checker)
|
209
|
+
checker.add_status('', ServingStatus::NOT_SERVING)
|
210
|
+
t = Thread.new { @srv.run }
|
211
|
+
@srv.wait_till_running
|
212
|
+
|
213
|
+
stub = CheckerStub.new(@host, :this_channel_is_insecure, **@client_opts)
|
214
|
+
got = stub.check(HCReq.new)
|
215
|
+
want = HCResp.new(status: ServingStatus::NOT_SERVING)
|
216
|
+
expect(got).to eq(want)
|
217
|
+
@srv.stop
|
218
|
+
t.join
|
219
|
+
end
|
220
|
+
|
221
|
+
it 'should fail on unknown services', server: true do
|
222
|
+
checker = Grpc::Health::Checker.new
|
223
|
+
@srv.handle(checker)
|
224
|
+
t = Thread.new { @srv.run }
|
225
|
+
@srv.wait_till_running
|
226
|
+
blk = proc do
|
227
|
+
stub = CheckerStub.new(@host, :this_channel_is_insecure, **@client_opts)
|
228
|
+
stub.check(HCReq.new(service: 'unknown'))
|
229
|
+
end
|
230
|
+
expected_msg = /#{StatusCodes::NOT_FOUND}/
|
231
|
+
expect(&blk).to raise_error GRPC::NotFound, expected_msg
|
232
|
+
@srv.stop
|
233
|
+
t.join
|
234
|
+
end
|
235
|
+
end
|
236
|
+
end
|
@@ -0,0 +1,104 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
def load_test_certs
|
18
|
+
test_root = File.join(File.dirname(__FILE__), 'testdata')
|
19
|
+
files = ['ca.pem', 'server1.key', 'server1.pem']
|
20
|
+
contents = files.map { |f| File.open(File.join(test_root, f)).read }
|
21
|
+
[contents[0], [{ private_key: contents[1], cert_chain: contents[2] }], false]
|
22
|
+
end
|
23
|
+
|
24
|
+
describe GRPC::Core::ServerCredentials do
|
25
|
+
Creds = GRPC::Core::ServerCredentials
|
26
|
+
XdsCreds = GRPC::Core::XdsServerCredentials
|
27
|
+
|
28
|
+
describe '#new' do
|
29
|
+
it 'can be constructed from a fake CA PEM, server PEM and a server key' do
|
30
|
+
creds = Creds.new('a', [{ private_key: 'a', cert_chain: 'b' }], false)
|
31
|
+
expect(creds).to_not be_nil
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'can be constructed using the test certificates' do
|
35
|
+
certs = load_test_certs
|
36
|
+
expect { Creds.new(*certs) }.not_to raise_error
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'cannot be constructed without a nil key_cert pair array' do
|
40
|
+
root_cert, _, _ = load_test_certs
|
41
|
+
blk = proc do
|
42
|
+
Creds.new(root_cert, nil, false)
|
43
|
+
end
|
44
|
+
expect(&blk).to raise_error
|
45
|
+
end
|
46
|
+
|
47
|
+
it 'cannot be constructed without any key_cert pairs' do
|
48
|
+
root_cert, _, _ = load_test_certs
|
49
|
+
blk = proc do
|
50
|
+
Creds.new(root_cert, [], false)
|
51
|
+
end
|
52
|
+
expect(&blk).to raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'cannot be constructed without a server cert chain' do
|
56
|
+
root_cert, server_key, _ = load_test_certs
|
57
|
+
blk = proc do
|
58
|
+
Creds.new(root_cert,
|
59
|
+
[{ server_key: server_key, cert_chain: nil }],
|
60
|
+
false)
|
61
|
+
end
|
62
|
+
expect(&blk).to raise_error
|
63
|
+
end
|
64
|
+
|
65
|
+
it 'cannot be constructed without a server key' do
|
66
|
+
root_cert, _, _ = load_test_certs
|
67
|
+
blk = proc do
|
68
|
+
Creds.new(root_cert,
|
69
|
+
[{ server_key: nil, cert_chain: cert_chain }])
|
70
|
+
end
|
71
|
+
expect(&blk).to raise_error
|
72
|
+
end
|
73
|
+
|
74
|
+
it 'can be constructed without a root_cret' do
|
75
|
+
_, cert_pairs, _ = load_test_certs
|
76
|
+
blk = proc { Creds.new(nil, cert_pairs, false) }
|
77
|
+
expect(&blk).to_not raise_error
|
78
|
+
end
|
79
|
+
|
80
|
+
it 'can be constructed with a fallback credential' do
|
81
|
+
_, cert_pairs, _ = load_test_certs
|
82
|
+
fallback = Creds.new(nil, cert_pairs, false)
|
83
|
+
blk = proc { XdsCreds.new(fallback) }
|
84
|
+
expect(&blk).to_not raise_error
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'cannot be constructed with nil' do
|
88
|
+
blk = proc { XdsCreds.new(nil) }
|
89
|
+
expect(&blk).to raise_error TypeError, /expected grpc_server_credentials/
|
90
|
+
end
|
91
|
+
|
92
|
+
it 'cannot be constructed with a non-C-extension object' do
|
93
|
+
not_a_fallback = 100
|
94
|
+
blk = proc { XdsCreds.new(not_a_fallback) }
|
95
|
+
expect(&blk).to raise_error TypeError, /expected grpc_server_credentials/
|
96
|
+
end
|
97
|
+
|
98
|
+
it 'cannot be constructed with a non-ServerCredentials object' do
|
99
|
+
not_a_fallback = GRPC::Core::ChannelCredentials.new
|
100
|
+
blk = proc { XdsCreds.new(not_a_fallback) }
|
101
|
+
expect(&blk).to raise_error TypeError, /expected grpc_server_credentials/
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
@@ -0,0 +1,231 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require 'spec_helper'
|
16
|
+
|
17
|
+
def load_test_certs
|
18
|
+
test_root = File.join(File.dirname(__FILE__), 'testdata')
|
19
|
+
files = ['ca.pem', 'server1.key', 'server1.pem']
|
20
|
+
contents = files.map { |f| File.open(File.join(test_root, f)).read }
|
21
|
+
[contents[0], [{ private_key: contents[1], cert_chain: contents[2] }], false]
|
22
|
+
end
|
23
|
+
|
24
|
+
Server = GRPC::Core::Server
|
25
|
+
|
26
|
+
describe Server do
|
27
|
+
def create_test_cert
|
28
|
+
GRPC::Core::ServerCredentials.new(*load_test_certs)
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '#start' do
|
32
|
+
it 'runs without failing' do
|
33
|
+
blk = proc { new_core_server_for_testing(nil).start }
|
34
|
+
expect(&blk).to_not raise_error
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'fails if the server is closed' do
|
38
|
+
s = new_core_server_for_testing(nil)
|
39
|
+
s.shutdown_and_notify(nil)
|
40
|
+
s.close
|
41
|
+
expect { s.start }.to raise_error(RuntimeError)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
describe '#shutdown_and_notify and #destroy' do
|
46
|
+
it 'destroys a server ok' do
|
47
|
+
s = start_a_server
|
48
|
+
blk = proc do
|
49
|
+
s.shutdown_and_notify(nil)
|
50
|
+
s.destroy
|
51
|
+
end
|
52
|
+
expect(&blk).to_not raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it 'can be called more than once without error' do
|
56
|
+
s = start_a_server
|
57
|
+
begin
|
58
|
+
blk = proc do
|
59
|
+
s.shutdown_and_notify(nil)
|
60
|
+
s.destroy
|
61
|
+
end
|
62
|
+
expect(&blk).to_not raise_error
|
63
|
+
blk.call
|
64
|
+
expect(&blk).to_not raise_error
|
65
|
+
ensure
|
66
|
+
s.shutdown_and_notify(nil)
|
67
|
+
s.close
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#shutdown_and_notify and #close' do
|
73
|
+
it 'closes a server ok' do
|
74
|
+
s = start_a_server
|
75
|
+
begin
|
76
|
+
blk = proc do
|
77
|
+
s.shutdown_and_notify(nil)
|
78
|
+
s.close
|
79
|
+
end
|
80
|
+
expect(&blk).to_not raise_error
|
81
|
+
ensure
|
82
|
+
s.shutdown_and_notify(nil)
|
83
|
+
s.close
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'can be called more than once without error' do
|
88
|
+
s = start_a_server
|
89
|
+
blk = proc do
|
90
|
+
s.shutdown_and_notify(nil)
|
91
|
+
s.close
|
92
|
+
end
|
93
|
+
expect(&blk).to_not raise_error
|
94
|
+
blk.call
|
95
|
+
expect(&blk).to_not raise_error
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
describe '#add_http_port' do
|
100
|
+
describe 'for insecure servers' do
|
101
|
+
it 'runs without failing' do
|
102
|
+
blk = proc do
|
103
|
+
s = new_core_server_for_testing(nil)
|
104
|
+
s.add_http2_port('localhost:0', :this_port_is_insecure)
|
105
|
+
s.shutdown_and_notify(nil)
|
106
|
+
s.close
|
107
|
+
end
|
108
|
+
expect(&blk).to_not raise_error
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'fails if the server is closed' do
|
112
|
+
s = new_core_server_for_testing(nil)
|
113
|
+
s.shutdown_and_notify(nil)
|
114
|
+
s.close
|
115
|
+
blk = proc do
|
116
|
+
s.add_http2_port('localhost:0', :this_port_is_insecure)
|
117
|
+
end
|
118
|
+
expect(&blk).to raise_error(RuntimeError)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
|
122
|
+
describe 'for secure servers' do
|
123
|
+
let(:cert) { create_test_cert }
|
124
|
+
it 'runs without failing' do
|
125
|
+
blk = proc do
|
126
|
+
s = new_core_server_for_testing(nil)
|
127
|
+
s.add_http2_port('localhost:0', cert)
|
128
|
+
s.shutdown_and_notify(nil)
|
129
|
+
s.close
|
130
|
+
end
|
131
|
+
expect(&blk).to_not raise_error
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'fails if the server is closed' do
|
135
|
+
s = new_core_server_for_testing(nil)
|
136
|
+
s.shutdown_and_notify(nil)
|
137
|
+
s.close
|
138
|
+
blk = proc { s.add_http2_port('localhost:0', cert) }
|
139
|
+
expect(&blk).to raise_error(RuntimeError)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
describe 'for xds servers' do
|
144
|
+
let(:cert) { create_test_cert }
|
145
|
+
let(:xds) { GRPC::Core::XdsServerCredentials.new(cert) }
|
146
|
+
it 'runs without failing' do
|
147
|
+
blk = proc do
|
148
|
+
s = new_core_server_for_testing(nil)
|
149
|
+
s.add_http2_port('localhost:0', xds)
|
150
|
+
s.shutdown_and_notify(nil)
|
151
|
+
s.close
|
152
|
+
end
|
153
|
+
expect(&blk).to_not raise_error
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'fails if the server is closed' do
|
157
|
+
s = new_core_server_for_testing(nil)
|
158
|
+
s.shutdown_and_notify(nil)
|
159
|
+
s.close
|
160
|
+
blk = proc { s.add_http2_port('localhost:0', xds) }
|
161
|
+
expect(&blk).to raise_error(RuntimeError)
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
shared_examples '#new' do
|
167
|
+
it 'takes nil channel args' do
|
168
|
+
expect { new_core_server_for_testing(nil) }.to_not raise_error
|
169
|
+
end
|
170
|
+
|
171
|
+
it 'does not take a hash with bad keys as channel args' do
|
172
|
+
blk = construct_with_args(Object.new => 1)
|
173
|
+
expect(&blk).to raise_error TypeError
|
174
|
+
blk = construct_with_args(1 => 1)
|
175
|
+
expect(&blk).to raise_error TypeError
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'does not take a hash with bad values as channel args' do
|
179
|
+
blk = construct_with_args(symbol: Object.new)
|
180
|
+
expect(&blk).to raise_error TypeError
|
181
|
+
blk = construct_with_args('1' => {})
|
182
|
+
expect(&blk).to raise_error TypeError
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'can take a hash with a symbol key as channel args' do
|
186
|
+
blk = construct_with_args(a_symbol: 1)
|
187
|
+
expect(&blk).to_not raise_error
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'can take a hash with a string key as channel args' do
|
191
|
+
blk = construct_with_args('a_symbol' => 1)
|
192
|
+
expect(&blk).to_not raise_error
|
193
|
+
end
|
194
|
+
|
195
|
+
it 'can take a hash with a string value as channel args' do
|
196
|
+
blk = construct_with_args(a_symbol: '1')
|
197
|
+
expect(&blk).to_not raise_error
|
198
|
+
end
|
199
|
+
|
200
|
+
it 'can take a hash with a symbol value as channel args' do
|
201
|
+
blk = construct_with_args(a_symbol: :another_symbol)
|
202
|
+
expect(&blk).to_not raise_error
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'can take a hash with a numeric value as channel args' do
|
206
|
+
blk = construct_with_args(a_symbol: 1)
|
207
|
+
expect(&blk).to_not raise_error
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'can take a hash with many args as channel args' do
|
211
|
+
args = Hash[127.times.collect { |x| [x.to_s, x] }]
|
212
|
+
blk = construct_with_args(args)
|
213
|
+
expect(&blk).to_not raise_error
|
214
|
+
end
|
215
|
+
end
|
216
|
+
|
217
|
+
describe '#new with an insecure channel' do
|
218
|
+
def construct_with_args(a)
|
219
|
+
proc { new_core_server_for_testing(a) }
|
220
|
+
end
|
221
|
+
|
222
|
+
it_behaves_like '#new'
|
223
|
+
end
|
224
|
+
|
225
|
+
def start_a_server
|
226
|
+
s = new_core_server_for_testing(nil)
|
227
|
+
s.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
|
228
|
+
s.start
|
229
|
+
s
|
230
|
+
end
|
231
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
# Copyright 2015 gRPC authors.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
spec_dir = File.expand_path(File.dirname(__FILE__))
|
16
|
+
root_dir = File.expand_path(File.join(spec_dir, '..'))
|
17
|
+
lib_dir = File.expand_path(File.join(root_dir, 'lib'))
|
18
|
+
|
19
|
+
$LOAD_PATH.unshift(spec_dir)
|
20
|
+
$LOAD_PATH.unshift(lib_dir)
|
21
|
+
$LOAD_PATH.uniq!
|
22
|
+
|
23
|
+
# set up coverage
|
24
|
+
require 'simplecov'
|
25
|
+
SimpleCov.start do
|
26
|
+
add_filter 'spec'
|
27
|
+
add_filter 'bin'
|
28
|
+
SimpleCov.command_name ENV['COVERAGE_NAME']
|
29
|
+
end if ENV['COVERAGE_NAME']
|
30
|
+
|
31
|
+
require 'rspec'
|
32
|
+
require 'logging'
|
33
|
+
require 'rspec/logging_helper'
|
34
|
+
require 'grpc'
|
35
|
+
|
36
|
+
require_relative 'support/services'
|
37
|
+
require_relative 'support/helpers'
|
38
|
+
|
39
|
+
# GRPC is the general RPC module
|
40
|
+
#
|
41
|
+
# Configure its logging for fine-grained log control during test runs
|
42
|
+
module GRPC
|
43
|
+
extend Logging.globally
|
44
|
+
end
|
45
|
+
Logging.logger.root.appenders = Logging.appenders.stdout
|
46
|
+
Logging.logger.root.level = :info
|
47
|
+
Logging.logger['GRPC'].level = :info
|
48
|
+
Logging.logger['GRPC::ActiveCall'].level = :info
|
49
|
+
Logging.logger['GRPC::BidiCall'].level = :info
|
50
|
+
|
51
|
+
# Configure RSpec to capture log messages for each test. The output from the
|
52
|
+
# logs will be stored in the @log_output variable. It is a StringIO instance.
|
53
|
+
RSpec.configure do |config|
|
54
|
+
include RSpec::LoggingHelper
|
55
|
+
config.capture_log_messages # comment this out to see logs during test runs
|
56
|
+
include GRPC::Spec::Helpers
|
57
|
+
end
|
58
|
+
|
59
|
+
RSpec::Expectations.configuration.warn_about_potential_false_positives = false
|
60
|
+
|
61
|
+
Thread.abort_on_exception = true
|