grpc 1.49.0.pre1-x64-mingw-ucrt

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 (127) 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-msvcrt.ruby +0 -0
  5. data/grpc_c.64-ucrt.ruby +0 -0
  6. data/src/ruby/bin/math_client.rb +140 -0
  7. data/src/ruby/bin/math_pb.rb +34 -0
  8. data/src/ruby/bin/math_server.rb +191 -0
  9. data/src/ruby/bin/math_services_pb.rb +51 -0
  10. data/src/ruby/bin/noproto_client.rb +93 -0
  11. data/src/ruby/bin/noproto_server.rb +97 -0
  12. data/src/ruby/ext/grpc/ext-export-truffleruby.clang +2 -0
  13. data/src/ruby/ext/grpc/ext-export-truffleruby.gcc +7 -0
  14. data/src/ruby/ext/grpc/ext-export.clang +2 -0
  15. data/src/ruby/ext/grpc/ext-export.gcc +7 -0
  16. data/src/ruby/ext/grpc/extconf.rb +163 -0
  17. data/src/ruby/ext/grpc/rb_byte_buffer.c +65 -0
  18. data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
  19. data/src/ruby/ext/grpc/rb_call.c +1051 -0
  20. data/src/ruby/ext/grpc/rb_call.h +57 -0
  21. data/src/ruby/ext/grpc/rb_call_credentials.c +341 -0
  22. data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
  23. data/src/ruby/ext/grpc/rb_channel.c +849 -0
  24. data/src/ruby/ext/grpc/rb_channel.h +34 -0
  25. data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
  26. data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
  27. data/src/ruby/ext/grpc/rb_channel_credentials.c +286 -0
  28. data/src/ruby/ext/grpc/rb_channel_credentials.h +37 -0
  29. data/src/ruby/ext/grpc/rb_completion_queue.c +101 -0
  30. data/src/ruby/ext/grpc/rb_completion_queue.h +36 -0
  31. data/src/ruby/ext/grpc/rb_compression_options.c +471 -0
  32. data/src/ruby/ext/grpc/rb_compression_options.h +29 -0
  33. data/src/ruby/ext/grpc/rb_enable_cpp.cc +22 -0
  34. data/src/ruby/ext/grpc/rb_event_thread.c +145 -0
  35. data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
  36. data/src/ruby/ext/grpc/rb_grpc.c +333 -0
  37. data/src/ruby/ext/grpc/rb_grpc.h +77 -0
  38. data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +597 -0
  39. data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +901 -0
  40. data/src/ruby/ext/grpc/rb_loader.c +61 -0
  41. data/src/ruby/ext/grpc/rb_loader.h +25 -0
  42. data/src/ruby/ext/grpc/rb_server.c +388 -0
  43. data/src/ruby/ext/grpc/rb_server.h +32 -0
  44. data/src/ruby/ext/grpc/rb_server_credentials.c +259 -0
  45. data/src/ruby/ext/grpc/rb_server_credentials.h +37 -0
  46. data/src/ruby/ext/grpc/rb_xds_channel_credentials.c +218 -0
  47. data/src/ruby/ext/grpc/rb_xds_channel_credentials.h +37 -0
  48. data/src/ruby/ext/grpc/rb_xds_server_credentials.c +170 -0
  49. data/src/ruby/ext/grpc/rb_xds_server_credentials.h +37 -0
  50. data/src/ruby/lib/grpc/3.1/grpc_c.so +0 -0
  51. data/src/ruby/lib/grpc/core/status_codes.rb +135 -0
  52. data/src/ruby/lib/grpc/core/time_consts.rb +56 -0
  53. data/src/ruby/lib/grpc/errors.rb +277 -0
  54. data/src/ruby/lib/grpc/generic/active_call.rb +675 -0
  55. data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
  56. data/src/ruby/lib/grpc/generic/client_stub.rb +503 -0
  57. data/src/ruby/lib/grpc/generic/interceptor_registry.rb +53 -0
  58. data/src/ruby/lib/grpc/generic/interceptors.rb +186 -0
  59. data/src/ruby/lib/grpc/generic/rpc_desc.rb +204 -0
  60. data/src/ruby/lib/grpc/generic/rpc_server.rb +551 -0
  61. data/src/ruby/lib/grpc/generic/service.rb +211 -0
  62. data/src/ruby/lib/grpc/google_rpc_status_utils.rb +40 -0
  63. data/src/ruby/lib/grpc/grpc.rb +24 -0
  64. data/src/ruby/lib/grpc/logconfig.rb +44 -0
  65. data/src/ruby/lib/grpc/notifier.rb +45 -0
  66. data/src/ruby/lib/grpc/structs.rb +15 -0
  67. data/src/ruby/lib/grpc/version.rb +18 -0
  68. data/src/ruby/lib/grpc.rb +37 -0
  69. data/src/ruby/pb/README.md +42 -0
  70. data/src/ruby/pb/generate_proto_ruby.sh +52 -0
  71. data/src/ruby/pb/grpc/health/checker.rb +75 -0
  72. data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -0
  73. data/src/ruby/pb/grpc/health/v1/health_services_pb.rb +62 -0
  74. data/src/ruby/pb/grpc/testing/duplicate/echo_duplicate_services_pb.rb +44 -0
  75. data/src/ruby/pb/grpc/testing/metrics_pb.rb +28 -0
  76. data/src/ruby/pb/grpc/testing/metrics_services_pb.rb +49 -0
  77. data/src/ruby/pb/src/proto/grpc/testing/empty_pb.rb +17 -0
  78. data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +149 -0
  79. data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +17 -0
  80. data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +152 -0
  81. data/src/ruby/pb/test/client.rb +769 -0
  82. data/src/ruby/pb/test/server.rb +252 -0
  83. data/src/ruby/pb/test/xds_client.rb +415 -0
  84. data/src/ruby/spec/call_credentials_spec.rb +42 -0
  85. data/src/ruby/spec/call_spec.rb +180 -0
  86. data/src/ruby/spec/channel_connection_spec.rb +126 -0
  87. data/src/ruby/spec/channel_credentials_spec.rb +124 -0
  88. data/src/ruby/spec/channel_spec.rb +245 -0
  89. data/src/ruby/spec/client_auth_spec.rb +152 -0
  90. data/src/ruby/spec/client_server_spec.rb +664 -0
  91. data/src/ruby/spec/compression_options_spec.rb +149 -0
  92. data/src/ruby/spec/debug_message_spec.rb +134 -0
  93. data/src/ruby/spec/error_sanity_spec.rb +49 -0
  94. data/src/ruby/spec/errors_spec.rb +142 -0
  95. data/src/ruby/spec/generic/active_call_spec.rb +683 -0
  96. data/src/ruby/spec/generic/client_interceptors_spec.rb +153 -0
  97. data/src/ruby/spec/generic/client_stub_spec.rb +1083 -0
  98. data/src/ruby/spec/generic/interceptor_registry_spec.rb +65 -0
  99. data/src/ruby/spec/generic/rpc_desc_spec.rb +374 -0
  100. data/src/ruby/spec/generic/rpc_server_pool_spec.rb +127 -0
  101. data/src/ruby/spec/generic/rpc_server_spec.rb +748 -0
  102. data/src/ruby/spec/generic/server_interceptors_spec.rb +218 -0
  103. data/src/ruby/spec/generic/service_spec.rb +263 -0
  104. data/src/ruby/spec/google_rpc_status_utils_spec.rb +282 -0
  105. data/src/ruby/spec/pb/codegen/grpc/testing/package_options.proto +28 -0
  106. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import.proto +22 -0
  107. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_import2.proto +23 -0
  108. data/src/ruby/spec/pb/codegen/grpc/testing/package_options_ruby_style.proto +41 -0
  109. data/src/ruby/spec/pb/codegen/grpc/testing/same_package_service_name.proto +27 -0
  110. data/src/ruby/spec/pb/codegen/grpc/testing/same_ruby_package_service_name.proto +29 -0
  111. data/src/ruby/spec/pb/codegen/package_option_spec.rb +98 -0
  112. data/src/ruby/spec/pb/duplicate/codegen_spec.rb +57 -0
  113. data/src/ruby/spec/pb/health/checker_spec.rb +236 -0
  114. data/src/ruby/spec/server_credentials_spec.rb +104 -0
  115. data/src/ruby/spec/server_spec.rb +231 -0
  116. data/src/ruby/spec/spec_helper.rb +61 -0
  117. data/src/ruby/spec/support/helpers.rb +107 -0
  118. data/src/ruby/spec/support/services.rb +160 -0
  119. data/src/ruby/spec/testdata/README +1 -0
  120. data/src/ruby/spec/testdata/ca.pem +20 -0
  121. data/src/ruby/spec/testdata/client.key +28 -0
  122. data/src/ruby/spec/testdata/client.pem +20 -0
  123. data/src/ruby/spec/testdata/server1.key +28 -0
  124. data/src/ruby/spec/testdata/server1.pem +22 -0
  125. data/src/ruby/spec/time_consts_spec.rb +74 -0
  126. data/src/ruby/spec/user_agent_spec.rb +74 -0
  127. metadata +406 -0
@@ -0,0 +1,180 @@
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
+ call = make_test_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
+
99
+ it 'must be set to a status' do
100
+ call = make_test_call
101
+ bad_sts = Object.new
102
+ expect { call.status = bad_sts }.to raise_error(TypeError)
103
+ end
104
+
105
+ it 'can be set to nil' do
106
+ call = make_test_call
107
+ expect { call.status = nil }.not_to raise_error
108
+ end
109
+ end
110
+
111
+ describe '#metadata' do
112
+ it 'can save the metadata hash and read it back' do
113
+ call = make_test_call
114
+ md = { 'k1' => 'v1', 'k2' => 'v2' }
115
+ expect { call.metadata = md }.not_to raise_error
116
+ expect(call.metadata).to be(md)
117
+ end
118
+
119
+ it 'must be set with a hash' do
120
+ call = make_test_call
121
+ bad_md = Object.new
122
+ expect { call.metadata = bad_md }.to raise_error(TypeError)
123
+ end
124
+
125
+ it 'can be set to nil' do
126
+ call = make_test_call
127
+ expect { call.metadata = nil }.not_to raise_error
128
+ end
129
+ end
130
+
131
+ describe '#set_credentials!' do
132
+ it 'can set a valid CallCredentials object' do
133
+ call = make_test_call
134
+ auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
135
+ creds = GRPC::Core::CallCredentials.new auth_proc
136
+ expect { call.set_credentials! creds }.not_to raise_error
137
+ end
138
+ end
139
+
140
+ describe '#cancel' do
141
+ it 'completes ok' do
142
+ call = make_test_call
143
+ expect { call.cancel }.not_to raise_error
144
+ end
145
+
146
+ it 'completes ok when the call is closed' do
147
+ call = make_test_call
148
+ call.close
149
+ expect { call.cancel }.not_to raise_error
150
+ end
151
+ end
152
+
153
+ describe '#cancel_with_status' do
154
+ it 'completes ok' do
155
+ call = make_test_call
156
+ expect do
157
+ call.cancel_with_status(0, 'test status')
158
+ end.not_to raise_error
159
+ expect do
160
+ call.cancel_with_status(0, nil)
161
+ end.to raise_error(TypeError)
162
+ end
163
+
164
+ it 'completes ok when the call is closed' do
165
+ call = make_test_call
166
+ call.close
167
+ expect do
168
+ call.cancel_with_status(0, 'test status')
169
+ end.not_to raise_error
170
+ end
171
+ end
172
+
173
+ def make_test_call
174
+ @ch.create_call(nil, nil, 'phony_method', nil, deadline)
175
+ end
176
+
177
+ def deadline
178
+ Time.now + 2 # in 2 seconds; arbitrary
179
+ end
180
+ 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,245 @@
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
+ def fork_with_propagated_error_message
32
+ pipe_read, pipe_write = IO.pipe
33
+ pid = fork do
34
+ pipe_read.close
35
+ begin
36
+ yield
37
+ rescue => exc
38
+ pipe_write.syswrite(exc.message)
39
+ end
40
+ pipe_write.close
41
+ end
42
+ pipe_write.close
43
+
44
+ exc_message = pipe_read.read
45
+ Process.wait(pid)
46
+
47
+ unless $CHILD_STATUS.success?
48
+ raise "forked process failed with #{$CHILD_STATUS}"
49
+ end
50
+ raise exc_message unless exc_message.empty?
51
+ end
52
+
53
+ shared_examples '#new' do
54
+ it 'take a host name without channel args' do
55
+ blk = proc do
56
+ GRPC::Core::Channel.new('phony_host', nil, :this_channel_is_insecure)
57
+ end
58
+ expect(&blk).not_to raise_error
59
+ end
60
+
61
+ it 'does not take a hash with bad keys as channel args' do
62
+ blk = construct_with_args(Object.new => 1)
63
+ expect(&blk).to raise_error TypeError
64
+ blk = construct_with_args(1 => 1)
65
+ expect(&blk).to raise_error TypeError
66
+ end
67
+
68
+ it 'does not take a hash with bad values as channel args' do
69
+ blk = construct_with_args(symbol: Object.new)
70
+ expect(&blk).to raise_error TypeError
71
+ blk = construct_with_args('1' => {})
72
+ expect(&blk).to raise_error TypeError
73
+ end
74
+
75
+ it 'can take a hash with a symbol key as channel args' do
76
+ blk = construct_with_args(a_symbol: 1)
77
+ expect(&blk).to_not raise_error
78
+ end
79
+
80
+ it 'can take a hash with a string key as channel args' do
81
+ blk = construct_with_args('a_symbol' => 1)
82
+ expect(&blk).to_not raise_error
83
+ end
84
+
85
+ it 'can take a hash with a string value as channel args' do
86
+ blk = construct_with_args(a_symbol: '1')
87
+ expect(&blk).to_not raise_error
88
+ end
89
+
90
+ it 'can take a hash with a symbol value as channel args' do
91
+ blk = construct_with_args(a_symbol: :another_symbol)
92
+ expect(&blk).to_not raise_error
93
+ end
94
+
95
+ it 'can take a hash with a numeric value as channel args' do
96
+ blk = construct_with_args(a_symbol: 1)
97
+ expect(&blk).to_not raise_error
98
+ end
99
+
100
+ it 'can take a hash with many args as channel args' do
101
+ args = Hash[127.times.collect { |x| [x.to_s, x] }]
102
+ blk = construct_with_args(args)
103
+ expect(&blk).to_not raise_error
104
+ end
105
+
106
+ it 'raises if grpc was initialized in another process' do
107
+ blk = construct_with_args({})
108
+ expect(&blk).not_to raise_error
109
+ expect do
110
+ fork_with_propagated_error_message(&blk)
111
+ end.to raise_error(RuntimeError, 'grpc cannot be used before and after forking')
112
+ end
113
+ end
114
+
115
+ describe '#new for secure channels' do
116
+ def construct_with_args(a)
117
+ proc { GRPC::Core::Channel.new('phony_host', a, create_test_cert) }
118
+ end
119
+
120
+ it_behaves_like '#new'
121
+ end
122
+
123
+ describe '#new for insecure channels' do
124
+ it_behaves_like '#new'
125
+
126
+ def construct_with_args(a)
127
+ proc do
128
+ GRPC::Core::Channel.new('phony_host', a, :this_channel_is_insecure)
129
+ end
130
+ end
131
+ end
132
+
133
+ describe '#new for XDS channels' do
134
+ it_behaves_like '#new'
135
+
136
+ def construct_with_args(a)
137
+ proc do
138
+ xds_creds = GRPC::Core::XdsChannelCredentials.new(create_test_cert)
139
+ GRPC::Core::Channel.new('dummy_host', a, xds_creds)
140
+ end
141
+ end
142
+ end
143
+
144
+ describe '#create_call' do
145
+ it 'creates a call OK' do
146
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
147
+
148
+ deadline = Time.now + 5
149
+
150
+ blk = proc do
151
+ ch.create_call(nil, nil, 'phony_method', nil, deadline)
152
+ end
153
+ expect(&blk).to_not raise_error
154
+ end
155
+
156
+ it 'raises an error if called on a closed channel' do
157
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
158
+ ch.close
159
+
160
+ deadline = Time.now + 5
161
+ blk = proc do
162
+ ch.create_call(nil, nil, 'phony_method', nil, deadline)
163
+ end
164
+ expect(&blk).to raise_error(RuntimeError)
165
+ end
166
+
167
+ it 'raises if grpc was initialized in another process' do
168
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
169
+
170
+ deadline = Time.now + 5
171
+
172
+ blk = proc do
173
+ fork_with_propagated_error_message do
174
+ ch.create_call(nil, nil, 'phony_method', nil, deadline)
175
+ end
176
+ end
177
+ expect(&blk).to raise_error(RuntimeError, 'grpc cannot be used before and after forking')
178
+ end
179
+ end
180
+
181
+ describe '#destroy' do
182
+ it 'destroys a channel ok' do
183
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
184
+ blk = proc { ch.destroy }
185
+ expect(&blk).to_not raise_error
186
+ end
187
+
188
+ it 'can be called more than once without error' do
189
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
190
+ blk = proc { ch.destroy }
191
+ blk.call
192
+ expect(&blk).to_not raise_error
193
+ end
194
+ end
195
+
196
+ describe '#connectivity_state' do
197
+ it 'returns an enum' do
198
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
199
+ valid_states = [
200
+ GRPC::Core::ConnectivityStates::IDLE,
201
+ GRPC::Core::ConnectivityStates::CONNECTING,
202
+ GRPC::Core::ConnectivityStates::READY,
203
+ GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
204
+ GRPC::Core::ConnectivityStates::FATAL_FAILURE
205
+ ]
206
+
207
+ expect(valid_states).to include(ch.connectivity_state)
208
+ end
209
+
210
+ it 'returns an enum when trying to connect' do
211
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
212
+ ch.connectivity_state(true)
213
+ valid_states = [
214
+ GRPC::Core::ConnectivityStates::IDLE,
215
+ GRPC::Core::ConnectivityStates::CONNECTING,
216
+ GRPC::Core::ConnectivityStates::READY,
217
+ GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
218
+ GRPC::Core::ConnectivityStates::FATAL_FAILURE
219
+ ]
220
+
221
+ expect(valid_states).to include(ch.connectivity_state)
222
+ end
223
+ end
224
+
225
+ describe '::SSL_TARGET' do
226
+ it 'is a symbol' do
227
+ expect(GRPC::Core::Channel::SSL_TARGET).to be_a(Symbol)
228
+ end
229
+ end
230
+
231
+ describe '#close' do
232
+ it 'closes a channel ok' do
233
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
234
+ blk = proc { ch.close }
235
+ expect(&blk).to_not raise_error
236
+ end
237
+
238
+ it 'can be called more than once without error' do
239
+ ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
240
+ blk = proc { ch.close }
241
+ blk.call
242
+ expect(&blk).to_not raise_error
243
+ end
244
+ end
245
+ end