grpc 1.30.2-x86-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.
- checksums.yaml +7 -0
- data/etc/roots.pem +4644 -0
- data/grpc_c.32.ruby +0 -0
- data/grpc_c.64.ruby +0 -0
- data/src/ruby/bin/math_client.rb +140 -0
- data/src/ruby/bin/math_pb.rb +34 -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.clang +1 -0
- data/src/ruby/ext/grpc/ext-export.gcc +6 -0
- data/src/ruby/ext/grpc/extconf.rb +107 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.c +64 -0
- data/src/ruby/ext/grpc/rb_byte_buffer.h +35 -0
- data/src/ruby/ext/grpc/rb_call.c +1050 -0
- data/src/ruby/ext/grpc/rb_call.h +53 -0
- data/src/ruby/ext/grpc/rb_call_credentials.c +297 -0
- data/src/ruby/ext/grpc/rb_call_credentials.h +31 -0
- data/src/ruby/ext/grpc/rb_channel.c +835 -0
- data/src/ruby/ext/grpc/rb_channel.h +34 -0
- data/src/ruby/ext/grpc/rb_channel_args.c +155 -0
- data/src/ruby/ext/grpc/rb_channel_args.h +38 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.c +267 -0
- data/src/ruby/ext/grpc/rb_channel_credentials.h +32 -0
- data/src/ruby/ext/grpc/rb_completion_queue.c +100 -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 +143 -0
- data/src/ruby/ext/grpc/rb_event_thread.h +21 -0
- data/src/ruby/ext/grpc/rb_grpc.c +328 -0
- data/src/ruby/ext/grpc/rb_grpc.h +76 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.c +573 -0
- data/src/ruby/ext/grpc/rb_grpc_imports.generated.h +865 -0
- data/src/ruby/ext/grpc/rb_loader.c +57 -0
- data/src/ruby/ext/grpc/rb_loader.h +25 -0
- data/src/ruby/ext/grpc/rb_server.c +372 -0
- data/src/ruby/ext/grpc/rb_server.h +32 -0
- data/src/ruby/ext/grpc/rb_server_credentials.c +243 -0
- data/src/ruby/ext/grpc/rb_server_credentials.h +32 -0
- data/src/ruby/lib/grpc.rb +37 -0
- data/src/ruby/lib/grpc/2.3/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.4/grpc_c.so +0 -0
- data/src/ruby/lib/grpc/2.5/grpc_c.so +0 -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/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 +669 -0
- data/src/ruby/lib/grpc/generic/bidi_call.rb +233 -0
- data/src/ruby/lib/grpc/generic/client_stub.rb +501 -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/pb/README.md +42 -0
- data/src/ruby/pb/generate_proto_ruby.sh +51 -0
- data/src/ruby/pb/grpc/health/checker.rb +75 -0
- data/src/ruby/pb/grpc/health/v1/health_pb.rb +31 -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 +17 -0
- data/src/ruby/pb/src/proto/grpc/testing/messages_pb.rb +105 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_pb.rb +16 -0
- data/src/ruby/pb/src/proto/grpc/testing/test_services_pb.rb +118 -0
- data/src/ruby/pb/test/client.rb +769 -0
- data/src/ruby/pb/test/server.rb +252 -0
- data/src/ruby/pb/test/xds_client.rb +213 -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 +82 -0
- data/src/ruby/spec/channel_spec.rb +234 -0
- data/src/ruby/spec/client_auth_spec.rb +126 -0
- data/src/ruby/spec/client_server_spec.rb +664 -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 +672 -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/package_option_spec.rb +82 -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 +79 -0
- data/src/ruby/spec/server_spec.rb +209 -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
- metadata +394 -0
@@ -0,0 +1,42 @@
|
|
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::CallCredentials do
|
18
|
+
CallCredentials = GRPC::Core::CallCredentials
|
19
|
+
|
20
|
+
let(:auth_proc) { proc { { 'plugin_key' => 'plugin_value' } } }
|
21
|
+
|
22
|
+
describe '#new' do
|
23
|
+
it 'can successfully create a CallCredentials from a proc' do
|
24
|
+
expect { CallCredentials.new(auth_proc) }.not_to raise_error
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe '#compose' do
|
29
|
+
it 'can compose with another CallCredentials' do
|
30
|
+
creds1 = CallCredentials.new(auth_proc)
|
31
|
+
creds2 = CallCredentials.new(auth_proc)
|
32
|
+
expect { creds1.compose creds2 }.not_to raise_error
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'can compose with multiple CallCredentials' do
|
36
|
+
creds1 = CallCredentials.new(auth_proc)
|
37
|
+
creds2 = CallCredentials.new(auth_proc)
|
38
|
+
creds3 = CallCredentials.new(auth_proc)
|
39
|
+
expect { creds1.compose(creds2, creds3) }.not_to raise_error
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -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, 'dummy_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,82 @@
|
|
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
|
+
end
|
54
|
+
|
55
|
+
describe '#compose' do
|
56
|
+
it 'can compose with a CallCredentials' do
|
57
|
+
certs = load_test_certs
|
58
|
+
channel_creds = ChannelCredentials.new(*certs)
|
59
|
+
auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
|
60
|
+
call_creds = CallCredentials.new auth_proc
|
61
|
+
expect { channel_creds.compose call_creds }.not_to raise_error
|
62
|
+
end
|
63
|
+
|
64
|
+
it 'can compose with multiple CallCredentials' do
|
65
|
+
certs = load_test_certs
|
66
|
+
channel_creds = ChannelCredentials.new(*certs)
|
67
|
+
auth_proc = proc { { 'plugin_key' => 'plugin_value' } }
|
68
|
+
call_creds1 = CallCredentials.new auth_proc
|
69
|
+
call_creds2 = CallCredentials.new auth_proc
|
70
|
+
expect do
|
71
|
+
channel_creds.compose(call_creds1, call_creds2)
|
72
|
+
end.not_to raise_error
|
73
|
+
end
|
74
|
+
|
75
|
+
it 'cannot compose with ChannelCredentials' do
|
76
|
+
certs = load_test_certs
|
77
|
+
channel_creds1 = ChannelCredentials.new(*certs)
|
78
|
+
channel_creds2 = ChannelCredentials.new(*certs)
|
79
|
+
expect { channel_creds1.compose channel_creds2 }.to raise_error(TypeError)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
@@ -0,0 +1,234 @@
|
|
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('dummy_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('dummy_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('dummy_host', a, :this_channel_is_insecure)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
end
|
132
|
+
|
133
|
+
describe '#create_call' do
|
134
|
+
it 'creates a call OK' do
|
135
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
136
|
+
|
137
|
+
deadline = Time.now + 5
|
138
|
+
|
139
|
+
blk = proc do
|
140
|
+
ch.create_call(nil, nil, 'dummy_method', nil, deadline)
|
141
|
+
end
|
142
|
+
expect(&blk).to_not raise_error
|
143
|
+
end
|
144
|
+
|
145
|
+
it 'raises an error if called on a closed channel' do
|
146
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
147
|
+
ch.close
|
148
|
+
|
149
|
+
deadline = Time.now + 5
|
150
|
+
blk = proc do
|
151
|
+
ch.create_call(nil, nil, 'dummy_method', nil, deadline)
|
152
|
+
end
|
153
|
+
expect(&blk).to raise_error(RuntimeError)
|
154
|
+
end
|
155
|
+
|
156
|
+
it 'raises if grpc was initialized in another process' do
|
157
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
158
|
+
|
159
|
+
deadline = Time.now + 5
|
160
|
+
|
161
|
+
blk = proc do
|
162
|
+
fork_with_propagated_error_message do
|
163
|
+
ch.create_call(nil, nil, 'dummy_method', nil, deadline)
|
164
|
+
end
|
165
|
+
end
|
166
|
+
expect(&blk).to raise_error(RuntimeError, 'grpc cannot be used before and after forking')
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe '#destroy' do
|
171
|
+
it 'destroys a channel ok' do
|
172
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
173
|
+
blk = proc { ch.destroy }
|
174
|
+
expect(&blk).to_not raise_error
|
175
|
+
end
|
176
|
+
|
177
|
+
it 'can be called more than once without error' do
|
178
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
179
|
+
blk = proc { ch.destroy }
|
180
|
+
blk.call
|
181
|
+
expect(&blk).to_not raise_error
|
182
|
+
end
|
183
|
+
end
|
184
|
+
|
185
|
+
describe '#connectivity_state' do
|
186
|
+
it 'returns an enum' do
|
187
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
188
|
+
valid_states = [
|
189
|
+
GRPC::Core::ConnectivityStates::IDLE,
|
190
|
+
GRPC::Core::ConnectivityStates::CONNECTING,
|
191
|
+
GRPC::Core::ConnectivityStates::READY,
|
192
|
+
GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
|
193
|
+
GRPC::Core::ConnectivityStates::FATAL_FAILURE
|
194
|
+
]
|
195
|
+
|
196
|
+
expect(valid_states).to include(ch.connectivity_state)
|
197
|
+
end
|
198
|
+
|
199
|
+
it 'returns an enum when trying to connect' do
|
200
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
201
|
+
ch.connectivity_state(true)
|
202
|
+
valid_states = [
|
203
|
+
GRPC::Core::ConnectivityStates::IDLE,
|
204
|
+
GRPC::Core::ConnectivityStates::CONNECTING,
|
205
|
+
GRPC::Core::ConnectivityStates::READY,
|
206
|
+
GRPC::Core::ConnectivityStates::TRANSIENT_FAILURE,
|
207
|
+
GRPC::Core::ConnectivityStates::FATAL_FAILURE
|
208
|
+
]
|
209
|
+
|
210
|
+
expect(valid_states).to include(ch.connectivity_state)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
describe '::SSL_TARGET' do
|
215
|
+
it 'is a symbol' do
|
216
|
+
expect(GRPC::Core::Channel::SSL_TARGET).to be_a(Symbol)
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe '#close' do
|
221
|
+
it 'closes a channel ok' do
|
222
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
223
|
+
blk = proc { ch.close }
|
224
|
+
expect(&blk).to_not raise_error
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'can be called more than once without error' do
|
228
|
+
ch = GRPC::Core::Channel.new(fake_host, nil, :this_channel_is_insecure)
|
229
|
+
blk = proc { ch.close }
|
230
|
+
blk.call
|
231
|
+
expect(&blk).to_not raise_error
|
232
|
+
end
|
233
|
+
end
|
234
|
+
end
|