grpc 1.74.0.pre2-x86-linux-gnu

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (133) hide show
  1. checksums.yaml +7 -0
  2. data/etc/roots.pem +4337 -0
  3. data/grpc_c.32-msvcrt.ruby +0 -0
  4. data/grpc_c.64-ucrt.ruby +0 -0
  5. data/src/ruby/bin/math_client.rb +140 -0
  6. data/src/ruby/bin/math_pb.rb +19 -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-truffleruby-with-ruby-abi-version.clang +2 -0
  12. data/src/ruby/ext/grpc/ext-export-truffleruby-with-ruby-abi-version.gcc +7 -0
  13. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.clang +2 -0
  14. data/src/ruby/ext/grpc/ext-export-with-ruby-abi-version.gcc +7 -0
  15. data/src/ruby/ext/grpc/ext-export.clang +1 -0
  16. data/src/ruby/ext/grpc/ext-export.gcc +6 -0
  17. data/src/ruby/ext/grpc/extconf.rb +269 -0
  18. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  19. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  20. data/src/ruby/ext/grpc/rb_call.c +1075 -0
  21. data/src/ruby/ext/grpc/rb_call.h +57 -0
  22. data/src/ruby/ext/grpc/rb_call_credentials.c +347 -0
  23. data/src/ruby/ext/grpc/rb_call_credentials.h +32 -0
  24. data/src/ruby/ext/grpc/rb_channel.c +391 -0
  25. data/src/ruby/ext/grpc/rb_channel.h +32 -0
  26. data/src/ruby/ext/grpc/rb_channel_args.c +174 -0
  27. data/src/ruby/ext/grpc/rb_channel_args.h +42 -0
  28. data/src/ruby/ext/grpc/rb_channel_credentials.c +285 -0
  29. data/src/ruby/ext/grpc/rb_channel_credentials.h +36 -0
  30. data/src/ruby/ext/grpc/rb_completion_queue.c +95 -0
  31. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  32. data/src/ruby/ext/grpc/rb_compression_options.c +469 -0
  33. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  34. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  35. data/src/ruby/ext/grpc/rb_event_thread.c +167 -0
  36. data/src/ruby/ext/grpc/rb_event_thread.h +22 -0
  37. data/src/ruby/ext/grpc/rb_grpc.c +500 -0
  38. data/src/ruby/ext/grpc/rb_grpc.h +88 -0
  39. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +597 -0
  40. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +902 -0
  41. data/src/ruby/ext/grpc/rb_loader.c +57 -0
  42. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  43. data/src/ruby/ext/grpc/rb_server.c +406 -0
  44. data/src/ruby/ext/grpc/rb_server.h +32 -0
  45. data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
  46. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  47. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +217 -0
  48. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +36 -0
  49. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
  50. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  51. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  52. data/src/ruby/lib/grpc/3.2/grpc_c.so +0 -0
  53. data/src/ruby/lib/grpc/3.3/grpc_c.so +0 -0
  54. data/src/ruby/lib/grpc/3.4/grpc_c.so +0 -0
  55. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  56. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  57. data/src/ruby/lib/grpc/errors.rb +277 -0
  58. data/src/ruby/lib/grpc/generic/active_call.rb +679 -0
  59. data/src/ruby/lib/grpc/generic/bidi_call.rb +237 -0
  60. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  61. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  62. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  63. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  64. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  65. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  66. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  67. data/src/ruby/lib/grpc/grpc.rb +24 -0
  68. data/src/ruby/lib/grpc/logconfig.rb +57 -0
  69. data/src/ruby/lib/grpc/notifier.rb +45 -0
  70. data/src/ruby/lib/grpc/structs.rb +15 -0
  71. data/src/ruby/lib/grpc/version.rb +18 -0
  72. data/src/ruby/lib/grpc.rb +37 -0
  73. data/src/ruby/pb/README.md +42 -0
  74. data/src/ruby/pb/generate_proto_ruby.sh +46 -0
  75. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  76. data/src/ruby/pb/grpc/health/v1/health_pb.rb +21 -0
  77. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  78. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  79. data/src/ruby/pb/grpc/testing/metrics_pb.rb +19 -0
  80. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  81. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
  82. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +50 -0
  83. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +19 -0
  84. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +174 -0
  85. data/src/ruby/pb/test/client.rb +785 -0
  86. data/src/ruby/pb/test/server.rb +252 -0
  87. data/src/ruby/pb/test/xds_client.rb +415 -0
  88. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  89. data/src/ruby/spec/call_spec.rb +193 -0
  90. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  91. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  92. data/src/ruby/spec/channel_spec.rb +209 -0
  93. data/src/ruby/spec/client_auth_spec.rb +152 -0
  94. data/src/ruby/spec/client_server_spec.rb +317 -0
  95. data/src/ruby/spec/compression_options_spec.rb +149 -0
  96. data/src/ruby/spec/core_spec.rb +22 -0
  97. data/src/ruby/spec/debug_message_spec.rb +134 -0
  98. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  99. data/src/ruby/spec/errors_spec.rb +142 -0
  100. data/src/ruby/spec/generic/active_call_spec.rb +670 -0
  101. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  102. data/src/ruby/spec/generic/client_stub_spec.rb +1079 -0
  103. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  104. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  105. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  106. data/src/ruby/spec/generic/rpc_server_spec.rb +773 -0
  107. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  108. data/src/ruby/spec/generic/service_spec.rb +263 -0
  109. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  110. data/src/ruby/spec/logconfig_spec.rb +30 -0
  111. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  112. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  113. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  114. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  115. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  116. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  117. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  118. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  119. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  120. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  121. data/src/ruby/spec/server_spec.rb +231 -0
  122. data/src/ruby/spec/spec_helper.rb +61 -0
  123. data/src/ruby/spec/support/helpers.rb +107 -0
  124. data/src/ruby/spec/support/services.rb +163 -0
  125. data/src/ruby/spec/testdata/README +1 -0
  126. data/src/ruby/spec/testdata/ca.pem +20 -0
  127. data/src/ruby/spec/testdata/client.key +28 -0
  128. data/src/ruby/spec/testdata/client.pem +20 -0
  129. data/src/ruby/spec/testdata/server1.key +28 -0
  130. data/src/ruby/spec/testdata/server1.pem +22 -0
  131. data/src/ruby/spec/time_consts_spec.rb +74 -0
  132. data/src/ruby/spec/user_agent_spec.rb +74 -0
  133. metadata +411 -0
@@ -0,0 +1,193 @@
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
+ include GRPC::Core::StatusCodes
18
+
19
+ describe GRPC::Core::WriteFlags do
20
+ it 'should define the known write flag values' do
21
+ m = GRPC::Core::WriteFlags
22
+ expect(m.const_get(:BUFFER_HINT)).to_not be_nil
23
+ expect(m.const_get(:NO_COMPRESS)).to_not be_nil
24
+ end
25
+ end
26
+
27
+ describe GRPC::Core::RpcErrors do
28
+ before(:each) do
29
+ @known_types = {
30
+ OK: 0,
31
+ ERROR: 1,
32
+ NOT_ON_SERVER: 2,
33
+ NOT_ON_CLIENT: 3,
34
+ ALREADY_ACCEPTED: 4,
35
+ ALREADY_INVOKED: 5,
36
+ NOT_INVOKED: 6,
37
+ ALREADY_FINISHED: 7,
38
+ TOO_MANY_OPERATIONS: 8,
39
+ INVALID_FLAGS: 9,
40
+ ErrorMessages: {
41
+ 0 => 'ok',
42
+ 1 => 'unknown error',
43
+ 2 => 'not available on a server',
44
+ 3 => 'not available on a client',
45
+ 4 => 'call is already accepted',
46
+ 5 => 'call is already invoked',
47
+ 6 => 'call is not yet invoked',
48
+ 7 => 'call is already finished',
49
+ 8 => 'outstanding read or write present',
50
+ 9 => 'a bad flag was given'
51
+ }
52
+ }
53
+ end
54
+
55
+ it 'should have symbols for all the known error codes' do
56
+ m = GRPC::Core::RpcErrors
57
+ syms_and_codes = m.constants.collect { |c| [c, m.const_get(c)] }
58
+ expect(Hash[syms_and_codes]).to eq(@known_types)
59
+ end
60
+ end
61
+
62
+ describe GRPC::Core::CallOps do
63
+ before(:each) do
64
+ @known_types = {
65
+ SEND_INITIAL_METADATA: 0,
66
+ SEND_MESSAGE: 1,
67
+ SEND_CLOSE_FROM_CLIENT: 2,
68
+ SEND_STATUS_FROM_SERVER: 3,
69
+ RECV_INITIAL_METADATA: 4,
70
+ RECV_MESSAGE: 5,
71
+ RECV_STATUS_ON_CLIENT: 6,
72
+ RECV_CLOSE_ON_SERVER: 7
73
+ }
74
+ end
75
+
76
+ it 'should have symbols for all the known operation types' do
77
+ m = GRPC::Core::CallOps
78
+ syms_and_codes = m.constants.collect { |c| [c, m.const_get(c)] }
79
+ expect(Hash[syms_and_codes]).to eq(@known_types)
80
+ end
81
+ end
82
+
83
+ describe GRPC::Core::Call do
84
+ let(:test_tag) { Object.new }
85
+ let(:fake_host) { 'localhost:10101' }
86
+
87
+ before(:each) do
88
+ @ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
89
+ end
90
+
91
+ describe '#status' do
92
+ it 'can save the status and read it back' do
93
+ make_test_call do |call|
94
+ sts = Struct::Status.new(OK, 'OK')
95
+ expect { call.status = sts }.not_to raise_error
96
+ expect(call.status).to eq(sts)
97
+ end
98
+ end
99
+
100
+ it 'must be set to a status' do
101
+ make_test_call do |call|
102
+ bad_sts = Object.new
103
+ expect { call.status = bad_sts }.to raise_error(TypeError)
104
+ end
105
+ end
106
+
107
+ it 'can be set to nil' do
108
+ make_test_call do |call|
109
+ expect { call.status = nil }.not_to raise_error
110
+ end
111
+ end
112
+ end
113
+
114
+ describe '#metadata' do
115
+ it 'can save the metadata hash and read it back' do
116
+ make_test_call do |call|
117
+ md = { 'k1' => 'v1', 'k2' => 'v2' }
118
+ expect { call.metadata = md }.not_to raise_error
119
+ expect(call.metadata).to be(md)
120
+ end
121
+ end
122
+
123
+ it 'must be set with a hash' do
124
+ make_test_call do |call|
125
+ bad_md = Object.new
126
+ expect { call.metadata = bad_md }.to raise_error(TypeError)
127
+ end
128
+ end
129
+
130
+ it 'can be set to nil' do
131
+ make_test_call do |call|
132
+ expect { call.metadata = nil }.not_to raise_error
133
+ end
134
+ end
135
+ end
136
+
137
+ describe '#set_credentials!' do
138
+ it 'can set a valid CallCredentials object' do
139
+ make_test_call do |call|
140
+ auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
141
+ creds = GRPC::Core::CallCredentials.new auth_proc
142
+ expect { call.set_credentials! creds }.not_to raise_error
143
+ end
144
+ end
145
+ end
146
+
147
+ describe '#cancel' do
148
+ it 'completes ok' do
149
+ make_test_call do |call|
150
+ expect { call.cancel }.not_to raise_error
151
+ end
152
+ end
153
+
154
+ it 'completes ok when the call is closed' do
155
+ make_test_call do |call|
156
+ call.close
157
+ expect { call.cancel }.not_to raise_error
158
+ end
159
+ end
160
+ end
161
+
162
+ describe '#cancel_with_status' do
163
+ it 'completes ok' do
164
+ make_test_call do |call|
165
+ expect do
166
+ call.cancel_with_status(0, 'test status')
167
+ end.not_to raise_error
168
+ expect do
169
+ call.cancel_with_status(0, nil)
170
+ end.to raise_error(TypeError)
171
+ end
172
+ end
173
+
174
+ it 'completes ok when the call is closed' do
175
+ make_test_call do |call|
176
+ call.close
177
+ expect do
178
+ call.cancel_with_status(0, 'test status')
179
+ end.not_to raise_error
180
+ end
181
+ end
182
+ end
183
+
184
+ def make_test_call
185
+ call = @ch.create_call(nil, nil, 'phony_method', nil, deadline)
186
+ yield call
187
+ call.close
188
+ end
189
+
190
+ def deadline
191
+ Time.now + 2 # in 2 seconds; arbitrary
192
+ end
193
+ end
@@ -0,0 +1,126 @@
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
+ require 'spec_helper'
15
+ require 'timeout'
16
+
17
+ include Timeout
18
+ include GRPC::Core
19
+ include GRPC::Spec::Helpers
20
+
21
+ def start_server(port = 0)
22
+ @srv = new_rpc_server_for_testing(pool_size: 1)
23
+ server_port = @srv.add_http2_port("localhost:#{port}", :this_port_is_insecure)
24
+ @srv.handle(EchoService)
25
+ @server_thd = Thread.new { @srv.run }
26
+ @srv.wait_till_running
27
+ server_port
28
+ end
29
+
30
+ def stop_server
31
+ expect(@srv.stopped?).to be(false)
32
+ @srv.stop
33
+ @server_thd.join
34
+ expect(@srv.stopped?).to be(true)
35
+ end
36
+
37
+ describe 'channel connection behavior' do
38
+ it 'the client channel handles temporary loss of a transport' do
39
+ port = start_server
40
+ stub = EchoStub.new("localhost:#{port}", :this_channel_is_insecure)
41
+ req = EchoMsg.new
42
+ expect(stub.an_rpc(req)).to be_a(EchoMsg)
43
+ stop_server
44
+ sleep 1
45
+ # TODO(apolcyn) grabbing the same port might fail, is this stable enough?
46
+ start_server(port)
47
+ expect(stub.an_rpc(req)).to be_a(EchoMsg)
48
+ stop_server
49
+ end
50
+
51
+ it 'observably connects and reconnects to transient server' \
52
+ ' when using the channel state API' do
53
+ port = start_server
54
+ ch = GRPC::Core::Channel.new("localhost:#{port}", {},
55
+ :this_channel_is_insecure)
56
+
57
+ expect(ch.connectivity_state).to be(GRPC::Core::ConnectivityStates::IDLE)
58
+
59
+ state = ch.connectivity_state(true)
60
+
61
+ count = 0
62
+ while count < 20 && state != GRPC::Core::ConnectivityStates::READY
63
+ ch.watch_connectivity_state(state, Time.now + 60)
64
+ state = ch.connectivity_state(true)
65
+ count += 1
66
+ end
67
+
68
+ expect(state).to be(GRPC::Core::ConnectivityStates::READY)
69
+
70
+ stop_server
71
+
72
+ state = ch.connectivity_state
73
+
74
+ count = 0
75
+ while count < 20 && state == GRPC::Core::ConnectivityStates::READY
76
+ ch.watch_connectivity_state(state, Time.now + 60)
77
+ state = ch.connectivity_state
78
+ count += 1
79
+ end
80
+
81
+ expect(state).to_not be(GRPC::Core::ConnectivityStates::READY)
82
+
83
+ start_server(port)
84
+
85
+ state = ch.connectivity_state(true)
86
+
87
+ count = 0
88
+ while count < 20 && state != GRPC::Core::ConnectivityStates::READY
89
+ ch.watch_connectivity_state(state, Time.now + 60)
90
+ state = ch.connectivity_state(true)
91
+ count += 1
92
+ end
93
+
94
+ expect(state).to be(GRPC::Core::ConnectivityStates::READY)
95
+
96
+ stop_server
97
+ end
98
+
99
+ it 'concurrent watches on the same channel' do
100
+ timeout(180) do
101
+ port = start_server
102
+ ch = GRPC::Core::Channel.new("localhost:#{port}", {},
103
+ :this_channel_is_insecure)
104
+ stop_server
105
+
106
+ thds = []
107
+ 50.times do
108
+ thds << Thread.new do
109
+ while ch.connectivity_state(true) != ConnectivityStates::READY
110
+ ch.watch_connectivity_state(
111
+ ConnectivityStates::READY, Time.now + 60)
112
+ break
113
+ end
114
+ end
115
+ end
116
+
117
+ sleep 0.01
118
+
119
+ start_server(port)
120
+
121
+ thds.each(&:join)
122
+
123
+ stop_server
124
+ end
125
+ end
126
+ end
@@ -0,0 +1,124 @@
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
+ describe GRPC::Core::ChannelCredentials do
18
+ ChannelCredentials = GRPC::Core::ChannelCredentials
19
+ CallCredentials = GRPC::Core::CallCredentials
20
+
21
+ def load_test_certs
22
+ test_root = File.join(File.dirname(__FILE__), 'testdata')
23
+ files = ['ca.pem', 'server1.key', 'server1.pem']
24
+ files.map { |f| File.open(File.join(test_root, f)).read }
25
+ end
26
+
27
+ describe '#new' do
28
+ it 'can be constructed with fake inputs' do
29
+ blk = proc { ChannelCredentials.new('root_certs', 'key', 'cert') }
30
+ expect(&blk).not_to raise_error
31
+ end
32
+
33
+ it 'it can be constructed using specific test certificates' do
34
+ certs = load_test_certs
35
+ expect { ChannelCredentials.new(*certs) }.not_to raise_error
36
+ end
37
+
38
+ it 'can be constructed with server roots certs only' do
39
+ root_cert, _, _ = load_test_certs
40
+ expect { ChannelCredentials.new(root_cert) }.not_to raise_error
41
+ end
42
+
43
+ it 'can be constructed with a nil server roots' do
44
+ _, client_key, client_chain = load_test_certs
45
+ blk = proc { ChannelCredentials.new(nil, client_key, client_chain) }
46
+ expect(&blk).not_to raise_error
47
+ end
48
+
49
+ it 'can be constructed with no params' do
50
+ blk = proc { ChannelCredentials.new(nil) }
51
+ expect(&blk).not_to raise_error
52
+ end
53
+
54
+ it 'fails gracefully with constructed with a nil private key' do
55
+ blk = proc { GRPC::Core::ChannelCredentials.new(nil, nil, '') }
56
+ expect(&blk).to raise_error
57
+ end
58
+
59
+ it 'fails gracefully with constructed with a nil cert chain' do
60
+ blk = proc { GRPC::Core::ChannelCredentials.new(nil, '', nil) }
61
+ expect(&blk).to raise_error
62
+ end
63
+
64
+ it 'can be constructed with a fallback credential' do
65
+ blk = proc {
66
+ fallback = GRPC::Core::ChannelCredentials.new
67
+ GRPC::Core::XdsChannelCredentials.new(fallback)
68
+ }
69
+ expect(&blk).not_to raise_error
70
+ end
71
+
72
+ it 'fails gracefully constructed with nil' do
73
+ blk = proc {
74
+ GRPC::Core::XdsChannelCredentials.new(nil)
75
+ }
76
+ expect(&blk).to raise_error TypeError, /expected grpc_channel_credentials/
77
+ end
78
+
79
+ it 'fails gracefully constructed with a non-C-extension object' do
80
+ blk = proc {
81
+ not_a_fallback = 100
82
+ GRPC::Core::XdsChannelCredentials.new(not_a_fallback)
83
+ }
84
+ expect(&blk).to raise_error TypeError, /expected grpc_channel_credentials/
85
+ end
86
+
87
+ it 'fails gracefully constructed with a non-ChannelCredentials object' do
88
+ blk = proc {
89
+ not_a_fallback = GRPC::Core::Channel.new('dummy_host', nil,
90
+ :this_channel_is_insecure)
91
+ GRPC::Core::XdsChannelCredentials.new(not_a_fallback)
92
+ }
93
+ expect(&blk).to raise_error TypeError, /expected grpc_channel_credentials/
94
+ end
95
+ end
96
+
97
+ describe '#compose' do
98
+ it 'can compose with a CallCredentials' do
99
+ certs = load_test_certs
100
+ channel_creds = ChannelCredentials.new(*certs)
101
+ auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
102
+ call_creds = CallCredentials.new auth_proc
103
+ expect { channel_creds.compose call_creds }.not_to raise_error
104
+ end
105
+
106
+ it 'can compose with multiple CallCredentials' do
107
+ certs = load_test_certs
108
+ channel_creds = ChannelCredentials.new(*certs)
109
+ auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
110
+ call_creds1 = CallCredentials.new auth_proc
111
+ call_creds2 = CallCredentials.new auth_proc
112
+ expect do
113
+ channel_creds.compose(call_creds1, call_creds2)
114
+ end.not_to raise_error
115
+ end
116
+
117
+ it 'cannot compose with ChannelCredentials' do
118
+ certs = load_test_certs
119
+ channel_creds1 = ChannelCredentials.new(*certs)
120
+ channel_creds2 = ChannelCredentials.new(*certs)
121
+ expect { channel_creds1.compose channel_creds2 }.to raise_error(TypeError)
122
+ end
123
+ end
124
+ 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
+ require 'English'
17
+
18
+ def load_test_certs
19
+ test_root = File.join(File.dirname(__FILE__), 'testdata')
20
+ files = ['ca.pem', 'server1.key', 'server1.pem']
21
+ files.map { |f| File.open(File.join(test_root, f)).read }
22
+ end
23
+
24
+ describe GRPC::Core::Channel do
25
+ let(:fake_host) { 'localhost:0' }
26
+
27
+ def create_test_cert
28
+ GRPC::Core::ChannelCredentials.new(load_test_certs[0])
29
+ end
30
+
31
+ shared_examples '#new' do
32
+ it 'take a host name without channel args' do
33
+ blk = proc do
34
+ GRPC::Core::Channel.new('phony_host', nil, :this_channel_is_insecure)
35
+ end
36
+ expect(&blk).not_to raise_error
37
+ end
38
+
39
+ it 'does not take a hash with bad keys as channel args' do
40
+ blk = construct_with_args(Object.new => 1)
41
+ expect(&blk).to raise_error TypeError
42
+ blk = construct_with_args(1 => 1)
43
+ expect(&blk).to raise_error TypeError
44
+ end
45
+
46
+ it 'does not take a hash with bad values as channel args' do
47
+ blk = construct_with_args(symbol: Object.new)
48
+ expect(&blk).to raise_error TypeError
49
+ blk = construct_with_args('1' => {})
50
+ expect(&blk).to raise_error TypeError
51
+ end
52
+
53
+ it 'can take a hash with a symbol key as channel args' do
54
+ blk = construct_with_args(a_symbol: 1)
55
+ expect(&blk).to_not raise_error
56
+ end
57
+
58
+ it 'can take a hash with a string key as channel args' do
59
+ blk = construct_with_args('a_symbol' => 1)
60
+ expect(&blk).to_not raise_error
61
+ end
62
+
63
+ it 'can take a hash with a string value as channel args' do
64
+ blk = construct_with_args(a_symbol: '1')
65
+ expect(&blk).to_not raise_error
66
+ end
67
+
68
+ it 'can take a hash with a symbol value as channel args' do
69
+ blk = construct_with_args(a_symbol: :another_symbol)
70
+ expect(&blk).to_not raise_error
71
+ end
72
+
73
+ it 'can take a hash with a numeric value as channel args' do
74
+ blk = construct_with_args(a_symbol: 1)
75
+ expect(&blk).to_not raise_error
76
+ end
77
+
78
+ it 'can take a hash with many args as channel args' do
79
+ args = Hash[127.times.collect { |x| [x.to_s, x] }]
80
+ blk = construct_with_args(args)
81
+ expect(&blk).to_not raise_error
82
+ end
83
+ end
84
+
85
+ describe '#new for secure channels' do
86
+ def construct_with_args(a)
87
+ proc { GRPC::Core::Channel.new('phony_host', a, create_test_cert) }
88
+ end
89
+
90
+ it_behaves_like '#new'
91
+ end
92
+
93
+ describe '#new for insecure channels' do
94
+ it_behaves_like '#new'
95
+
96
+ def construct_with_args(a)
97
+ proc do
98
+ GRPC::Core::Channel.new('phony_host', a, :this_channel_is_insecure)
99
+ end
100
+ end
101
+ end
102
+
103
+ describe '#new for XDS channels' do
104
+ it_behaves_like '#new'
105
+
106
+ def construct_with_args(a)
107
+ proc do
108
+ xds_creds = GRPC::Core::XdsChannelCredentials.new(create_test_cert)
109
+ GRPC::Core::Channel.new('dummy_host', a, xds_creds)
110
+ end
111
+ end
112
+ end
113
+
114
+ describe '#create_call' do
115
+ it 'creates a call OK' do
116
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
117
+
118
+ deadline = Time.now + 5
119
+
120
+ blk = proc do
121
+ call = ch.create_call(nil, nil, 'phony_method', nil, deadline)
122
+ call.close
123
+ end
124
+ expect(&blk).to_not raise_error
125
+ end
126
+
127
+ it 'raises an error if called on a closed channel' do
128
+ STDERR.puts "#{Time.now}: begin: raises an error if called on a closed channel"
129
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
130
+ STDERR.puts "#{Time.now}: created channel"
131
+ ch.close
132
+ STDERR.puts "#{Time.now}: closed channel"
133
+
134
+ deadline = Time.now + 5
135
+ blk = proc do
136
+ call = ch.create_call(nil, nil, 'phony_method', nil, deadline)
137
+ STDERR.puts "#{Time.now}: created call"
138
+ call.close
139
+ end
140
+ expect(&blk).to raise_error(RuntimeError)
141
+ STDERR.puts "#{Time.now}: finished: raises an error if called on a closed channel"
142
+ end
143
+ end
144
+
145
+ describe '#destroy' do
146
+ it 'destroys a channel ok' do
147
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
148
+ blk = proc { ch.destroy }
149
+ expect(&blk).to_not raise_error
150
+ end
151
+
152
+ it 'can be called more than once without error' do
153
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
154
+ blk = proc { ch.destroy }
155
+ blk.call
156
+ expect(&blk).to_not raise_error
157
+ end
158
+ end
159
+
160
+ describe '#connectivity_state' do
161
+ it 'returns an enum' do
162
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
163
+ valid_states = [
164
+ GRPC::Core::ConnectivityStates::IDLE,
165
+ GRPC::Core::ConnectivityStates::CONNECTING,
166
+ GRPC::Core::ConnectivityStates::READY,
167
+ GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
168
+ GRPC::Core::ConnectivityStates::FATAL_FAILURE
169
+ ]
170
+
171
+ expect(valid_states).to include(ch.connectivity_state)
172
+ end
173
+
174
+ it 'returns an enum when trying to connect' do
175
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
176
+ ch.connectivity_state(true)
177
+ valid_states = [
178
+ GRPC::Core::ConnectivityStates::IDLE,
179
+ GRPC::Core::ConnectivityStates::CONNECTING,
180
+ GRPC::Core::ConnectivityStates::READY,
181
+ GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
182
+ GRPC::Core::ConnectivityStates::FATAL_FAILURE
183
+ ]
184
+
185
+ expect(valid_states).to include(ch.connectivity_state)
186
+ end
187
+ end
188
+
189
+ describe '::SSL_TARGET' do
190
+ it 'is a symbol' do
191
+ expect(GRPC::Core::Channel::SSL_TARGET).to be_a(Symbol)
192
+ end
193
+ end
194
+
195
+ describe '#close' do
196
+ it 'closes a channel ok' do
197
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
198
+ blk = proc { ch.close }
199
+ expect(&blk).to_not raise_error
200
+ end
201
+
202
+ it 'can be called more than once without error' do
203
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
204
+ blk = proc { ch.close }
205
+ blk.call
206
+ expect(&blk).to_not raise_error
207
+ end
208
+ end
209
+ end