grpc 1.30.2-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of grpc might be problematic. Click here for more details.

Files changed (121) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4644 -0
  3. data/grpc_c.32.ruby +0 -0
  4. data/grpc_c.64.ruby +0 -0
  5. data/src/ruby/bin/math_client.rb +140 -0
  6. data/src/ruby/bin/math_pb.rb +34 -0
  7. data/src/ruby/bin/math_server.rb +191 -0
  8. data/src/ruby/bin/math_services_pb.rb +51 -0
  9. data/src/ruby/bin/noproto_client.rb +93 -0
  10. data/src/ruby/bin/noproto_server.rb +97 -0
  11. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  12. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  13. data/src/ruby/ext/grpc/extconf.rb +107 -0
  14. data/src/ruby/ext/grpc/rb_byte_buffer.c +64 -0
  15. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  16. data/src/ruby/ext/grpc/rb_call.c +1050 -0
  17. data/src/ruby/ext/grpc/rb_call.h +53 -0
  18. data/src/ruby/ext/grpc/rb_call_credentials.c +297 -0
  19. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  20. data/src/ruby/ext/grpc/rb_channel.c +835 -0
  21. data/src/ruby/ext/grpc/rb_channel.h +34 -0
  22. data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
  23. data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
  24. data/src/ruby/ext/grpc/rb_channel_credentials.c +267 -0
  25. data/src/ruby/ext/grpc/rb_channel_credentials.h +32 -0
  26. data/src/ruby/ext/grpc/rb_completion_queue.c +100 -0
  27. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  28. data/src/ruby/ext/grpc/rb_compression_options.c +470 -0
  29. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  30. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  31. data/src/ruby/ext/grpc/rb_event_thread.c +143 -0
  32. data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
  33. data/src/ruby/ext/grpc/rb_grpc.c +328 -0
  34. data/src/ruby/ext/grpc/rb_grpc.h +76 -0
  35. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +573 -0
  36. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +865 -0
  37. data/src/ruby/ext/grpc/rb_loader.c +57 -0
  38. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  39. data/src/ruby/ext/grpc/rb_server.c +372 -0
  40. data/src/ruby/ext/grpc/rb_server.h +32 -0
  41. data/src/ruby/ext/grpc/rb_server_credentials.c +243 -0
  42. data/src/ruby/ext/grpc/rb_server_credentials.h +32 -0
  43. data/src/ruby/lib/grpc.rb +37 -0
  44. data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
  45. data/src/ruby/lib/grpc/2.4/grpc_c.so +0 -0
  46. data/src/ruby/lib/grpc/2.5/grpc_c.so +0 -0
  47. data/src/ruby/lib/grpc/2.6/grpc_c.so +0 -0
  48. data/src/ruby/lib/grpc/2.7/grpc_c.so +0 -0
  49. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  50. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  51. data/src/ruby/lib/grpc/errors.rb +277 -0
  52. data/src/ruby/lib/grpc/generic/active_call.rb +669 -0
  53. data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
  54. data/src/ruby/lib/grpc/generic/client_stub.rb +501 -0
  55. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  56. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  57. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  58. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  59. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  60. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  61. data/src/ruby/lib/grpc/grpc.rb +24 -0
  62. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  63. data/src/ruby/lib/grpc/notifier.rb +45 -0
  64. data/src/ruby/lib/grpc/structs.rb +15 -0
  65. data/src/ruby/lib/grpc/version.rb +18 -0
  66. data/src/ruby/pb/README.md +42 -0
  67. data/src/ruby/pb/generate_proto_ruby.sh +51 -0
  68. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  69. data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
  70. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  71. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  72. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  73. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  74. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
  75. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +105 -0
  76. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
  77. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +118 -0
  78. data/src/ruby/pb/test/client.rb +769 -0
  79. data/src/ruby/pb/test/server.rb +252 -0
  80. data/src/ruby/pb/test/xds_client.rb +213 -0
  81. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  82. data/src/ruby/spec/call_spec.rb +180 -0
  83. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  84. data/src/ruby/spec/channel_credentials_spec.rb +82 -0
  85. data/src/ruby/spec/channel_spec.rb +234 -0
  86. data/src/ruby/spec/client_auth_spec.rb +126 -0
  87. data/src/ruby/spec/client_server_spec.rb +664 -0
  88. data/src/ruby/spec/compression_options_spec.rb +149 -0
  89. data/src/ruby/spec/debug_message_spec.rb +134 -0
  90. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  91. data/src/ruby/spec/errors_spec.rb +142 -0
  92. data/src/ruby/spec/generic/active_call_spec.rb +672 -0
  93. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  94. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  95. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  96. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  97. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  98. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  99. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  100. data/src/ruby/spec/generic/service_spec.rb +263 -0
  101. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  102. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  103. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  104. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  105. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  106. data/src/ruby/spec/pb/codegen/package_option_spec.rb +82 -0
  107. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  108. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  109. data/src/ruby/spec/server_credentials_spec.rb +79 -0
  110. data/src/ruby/spec/server_spec.rb +209 -0
  111. data/src/ruby/spec/spec_helper.rb +61 -0
  112. data/src/ruby/spec/support/helpers.rb +107 -0
  113. data/src/ruby/spec/support/services.rb +160 -0
  114. data/src/ruby/spec/testdata/README +1 -0
  115. data/src/ruby/spec/testdata/ca.pem +20 -0
  116. data/src/ruby/spec/testdata/client.key +28 -0
  117. data/src/ruby/spec/testdata/client.pem +20 -0
  118. data/src/ruby/spec/testdata/server1.key +28 -0
  119. data/src/ruby/spec/testdata/server1.pem +22 -0
  120. data/src/ruby/spec/time_consts_spec.rb +74 -0
  121. metadata +394 -0
@@ -0,0 +1,57 @@
1
+ # Copyright 2016 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 'open3'
17
+ require 'tmpdir'
18
+
19
+ def can_run_codegen_check
20
+ system('which grpc_ruby_plugin') && system('which protoc')
21
+ end
22
+
23
+ describe 'Ping protobuf code generation' do
24
+ if !can_run_codegen_check
25
+ skip 'protoc || grpc_ruby_plugin missing, cannot verify ping code-gen'
26
+ else
27
+ it 'should have the same content as created by code generation' do
28
+ root_dir = File.join(File.dirname(__FILE__), '..', '..', '..', '..', '..')
29
+
30
+ # Get the current content
31
+ service_path = File.join(root_dir, 'src', 'ruby', 'pb', 'grpc',
32
+ 'testing', 'duplicate',
33
+ 'echo_duplicate_services_pb.rb')
34
+ want = nil
35
+ File.open(service_path) { |f| want = f.read }
36
+
37
+ # Regenerate it
38
+ plugin, = Open3.capture2('which', 'grpc_ruby_plugin')
39
+ plugin = plugin.strip
40
+ got = nil
41
+ Dir.mktmpdir do |tmp_dir|
42
+ gen_out = File.join(tmp_dir, 'src', 'proto', 'grpc', 'testing',
43
+ 'duplicate', 'echo_duplicate_services_pb.rb')
44
+ pid = spawn(
45
+ 'protoc',
46
+ '-I.',
47
+ 'src/proto/grpc/testing/duplicate/echo_duplicate.proto',
48
+ "--grpc_out=#{tmp_dir}",
49
+ "--plugin=protoc-gen-grpc=#{plugin}",
50
+ chdir: root_dir)
51
+ Process.wait(pid)
52
+ File.open(gen_out) { |f| got = f.read }
53
+ end
54
+ expect(got).to eq(want)
55
+ end
56
+ end
57
+ end
@@ -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,79 @@
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
+
27
+ describe '#new' do
28
+ it 'can be constructed from a fake CA PEM, server PEM and a server key' do
29
+ creds = Creds.new('a', [{ private_key: 'a', cert_chain: 'b' }], false)
30
+ expect(creds).to_not be_nil
31
+ end
32
+
33
+ it 'can be constructed using the test certificates' do
34
+ certs = load_test_certs
35
+ expect { Creds.new(*certs) }.not_to raise_error
36
+ end
37
+
38
+ it 'cannot be constructed without a nil key_cert pair array' do
39
+ root_cert, _, _ = load_test_certs
40
+ blk = proc do
41
+ Creds.new(root_cert, nil, false)
42
+ end
43
+ expect(&blk).to raise_error
44
+ end
45
+
46
+ it 'cannot be constructed without any key_cert pairs' do
47
+ root_cert, _, _ = load_test_certs
48
+ blk = proc do
49
+ Creds.new(root_cert, [], false)
50
+ end
51
+ expect(&blk).to raise_error
52
+ end
53
+
54
+ it 'cannot be constructed without a server cert chain' do
55
+ root_cert, server_key, _ = load_test_certs
56
+ blk = proc do
57
+ Creds.new(root_cert,
58
+ [{ server_key: server_key, cert_chain: nil }],
59
+ false)
60
+ end
61
+ expect(&blk).to raise_error
62
+ end
63
+
64
+ it 'cannot be constructed without a server key' do
65
+ root_cert, _, _ = load_test_certs
66
+ blk = proc do
67
+ Creds.new(root_cert,
68
+ [{ server_key: nil, cert_chain: cert_chain }])
69
+ end
70
+ expect(&blk).to raise_error
71
+ end
72
+
73
+ it 'can be constructed without a root_cret' do
74
+ _, cert_pairs, _ = load_test_certs
75
+ blk = proc { Creds.new(nil, cert_pairs, false) }
76
+ expect(&blk).to_not raise_error
77
+ end
78
+ end
79
+ end
@@ -0,0 +1,209 @@
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
+ end
143
+
144
+ shared_examples '#new' do
145
+ it 'takes nil channel args' do
146
+ expect { new_core_server_for_testing(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 { new_core_server_for_testing(a) }
198
+ end
199
+
200
+ it_behaves_like '#new'
201
+ end
202
+
203
+ def start_a_server
204
+ s = new_core_server_for_testing(nil)
205
+ s.add_http2_port('0.0.0.0:0', :this_port_is_insecure)
206
+ s.start
207
+ s
208
+ end
209
+ end