protobuf-cucumber 3.10.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rubocop.yml +70 -0
- data/.rubocop_todo.yml +145 -0
- data/.travis.yml +40 -0
- data/.yardopts +5 -0
- data/CHANGES.md +344 -0
- data/CONTRIBUTING.md +16 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +33 -0
- data/Rakefile +64 -0
- data/bin/protoc-gen-ruby +22 -0
- data/bin/rpc_server +5 -0
- data/install-protobuf.sh +28 -0
- data/lib/protobuf.rb +129 -0
- data/lib/protobuf/cli.rb +257 -0
- data/lib/protobuf/code_generator.rb +120 -0
- data/lib/protobuf/decoder.rb +28 -0
- data/lib/protobuf/deprecation.rb +117 -0
- data/lib/protobuf/descriptors.rb +3 -0
- data/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +62 -0
- data/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +301 -0
- data/lib/protobuf/encoder.rb +11 -0
- data/lib/protobuf/enum.rb +365 -0
- data/lib/protobuf/exceptions.rb +9 -0
- data/lib/protobuf/field.rb +74 -0
- data/lib/protobuf/field/base_field.rb +380 -0
- data/lib/protobuf/field/base_field_object_definitions.rb +504 -0
- data/lib/protobuf/field/bool_field.rb +64 -0
- data/lib/protobuf/field/bytes_field.rb +78 -0
- data/lib/protobuf/field/double_field.rb +25 -0
- data/lib/protobuf/field/enum_field.rb +61 -0
- data/lib/protobuf/field/field_array.rb +104 -0
- data/lib/protobuf/field/field_hash.rb +122 -0
- data/lib/protobuf/field/fixed32_field.rb +25 -0
- data/lib/protobuf/field/fixed64_field.rb +28 -0
- data/lib/protobuf/field/float_field.rb +43 -0
- data/lib/protobuf/field/int32_field.rb +21 -0
- data/lib/protobuf/field/int64_field.rb +34 -0
- data/lib/protobuf/field/integer_field.rb +23 -0
- data/lib/protobuf/field/message_field.rb +51 -0
- data/lib/protobuf/field/sfixed32_field.rb +27 -0
- data/lib/protobuf/field/sfixed64_field.rb +28 -0
- data/lib/protobuf/field/signed_integer_field.rb +29 -0
- data/lib/protobuf/field/sint32_field.rb +21 -0
- data/lib/protobuf/field/sint64_field.rb +21 -0
- data/lib/protobuf/field/string_field.rb +51 -0
- data/lib/protobuf/field/uint32_field.rb +21 -0
- data/lib/protobuf/field/uint64_field.rb +21 -0
- data/lib/protobuf/field/varint_field.rb +77 -0
- data/lib/protobuf/generators/base.rb +85 -0
- data/lib/protobuf/generators/enum_generator.rb +39 -0
- data/lib/protobuf/generators/extension_generator.rb +27 -0
- data/lib/protobuf/generators/field_generator.rb +193 -0
- data/lib/protobuf/generators/file_generator.rb +262 -0
- data/lib/protobuf/generators/group_generator.rb +122 -0
- data/lib/protobuf/generators/message_generator.rb +104 -0
- data/lib/protobuf/generators/option_generator.rb +17 -0
- data/lib/protobuf/generators/printable.rb +160 -0
- data/lib/protobuf/generators/service_generator.rb +50 -0
- data/lib/protobuf/lifecycle.rb +33 -0
- data/lib/protobuf/logging.rb +39 -0
- data/lib/protobuf/message.rb +260 -0
- data/lib/protobuf/message/fields.rb +233 -0
- data/lib/protobuf/message/serialization.rb +85 -0
- data/lib/protobuf/optionable.rb +70 -0
- data/lib/protobuf/rpc/buffer.rb +78 -0
- data/lib/protobuf/rpc/client.rb +140 -0
- data/lib/protobuf/rpc/connectors/base.rb +221 -0
- data/lib/protobuf/rpc/connectors/ping.rb +89 -0
- data/lib/protobuf/rpc/connectors/socket.rb +78 -0
- data/lib/protobuf/rpc/connectors/zmq.rb +319 -0
- data/lib/protobuf/rpc/dynamic_discovery.pb.rb +50 -0
- data/lib/protobuf/rpc/env.rb +60 -0
- data/lib/protobuf/rpc/error.rb +28 -0
- data/lib/protobuf/rpc/error/client_error.rb +31 -0
- data/lib/protobuf/rpc/error/server_error.rb +43 -0
- data/lib/protobuf/rpc/middleware.rb +25 -0
- data/lib/protobuf/rpc/middleware/exception_handler.rb +40 -0
- data/lib/protobuf/rpc/middleware/logger.rb +95 -0
- data/lib/protobuf/rpc/middleware/request_decoder.rb +79 -0
- data/lib/protobuf/rpc/middleware/response_encoder.rb +83 -0
- data/lib/protobuf/rpc/middleware/runner.rb +18 -0
- data/lib/protobuf/rpc/rpc.pb.rb +64 -0
- data/lib/protobuf/rpc/rpc_method.rb +16 -0
- data/lib/protobuf/rpc/server.rb +39 -0
- data/lib/protobuf/rpc/servers/socket/server.rb +121 -0
- data/lib/protobuf/rpc/servers/socket/worker.rb +56 -0
- data/lib/protobuf/rpc/servers/socket_runner.rb +46 -0
- data/lib/protobuf/rpc/servers/zmq/broker.rb +194 -0
- data/lib/protobuf/rpc/servers/zmq/server.rb +321 -0
- data/lib/protobuf/rpc/servers/zmq/util.rb +48 -0
- data/lib/protobuf/rpc/servers/zmq/worker.rb +105 -0
- data/lib/protobuf/rpc/servers/zmq_runner.rb +70 -0
- data/lib/protobuf/rpc/service.rb +172 -0
- data/lib/protobuf/rpc/service_directory.rb +261 -0
- data/lib/protobuf/rpc/service_dispatcher.rb +45 -0
- data/lib/protobuf/rpc/service_filters.rb +250 -0
- data/lib/protobuf/rpc/stat.rb +119 -0
- data/lib/protobuf/socket.rb +21 -0
- data/lib/protobuf/tasks.rb +1 -0
- data/lib/protobuf/tasks/compile.rake +80 -0
- data/lib/protobuf/varint.rb +20 -0
- data/lib/protobuf/varint_pure.rb +31 -0
- data/lib/protobuf/version.rb +3 -0
- data/lib/protobuf/wire_type.rb +10 -0
- data/lib/protobuf/zmq.rb +21 -0
- data/profile.html +5103 -0
- data/proto/dynamic_discovery.proto +44 -0
- data/proto/google/protobuf/compiler/plugin.proto +147 -0
- data/proto/google/protobuf/descriptor.proto +779 -0
- data/proto/rpc.proto +69 -0
- data/protobuf-cucumber.gemspec +57 -0
- data/spec/benchmark/tasks.rb +143 -0
- data/spec/bin/protoc-gen-ruby_spec.rb +23 -0
- data/spec/encoding/all_types_spec.rb +103 -0
- data/spec/encoding/extreme_values_spec.rb +0 -0
- data/spec/functional/class_inheritance_spec.rb +52 -0
- data/spec/functional/code_generator_spec.rb +58 -0
- data/spec/functional/socket_server_spec.rb +59 -0
- data/spec/functional/zmq_server_spec.rb +105 -0
- data/spec/lib/protobuf/cli_spec.rb +317 -0
- data/spec/lib/protobuf/code_generator_spec.rb +87 -0
- data/spec/lib/protobuf/enum_spec.rb +307 -0
- data/spec/lib/protobuf/field/bool_field_spec.rb +91 -0
- data/spec/lib/protobuf/field/double_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/enum_field_spec.rb +44 -0
- data/spec/lib/protobuf/field/field_array_spec.rb +105 -0
- data/spec/lib/protobuf/field/field_hash_spec.rb +168 -0
- data/spec/lib/protobuf/field/fixed32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/fixed64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/float_field_spec.rb +90 -0
- data/spec/lib/protobuf/field/int32_field_spec.rb +120 -0
- data/spec/lib/protobuf/field/int64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/message_field_spec.rb +132 -0
- data/spec/lib/protobuf/field/sfixed32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sfixed64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint32_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/sint64_field_spec.rb +9 -0
- data/spec/lib/protobuf/field/string_field_spec.rb +79 -0
- data/spec/lib/protobuf/field/uint32_field_spec.rb +7 -0
- data/spec/lib/protobuf/field/uint64_field_spec.rb +7 -0
- data/spec/lib/protobuf/field_spec.rb +192 -0
- data/spec/lib/protobuf/generators/base_spec.rb +154 -0
- data/spec/lib/protobuf/generators/enum_generator_spec.rb +82 -0
- data/spec/lib/protobuf/generators/extension_generator_spec.rb +42 -0
- data/spec/lib/protobuf/generators/field_generator_spec.rb +197 -0
- data/spec/lib/protobuf/generators/file_generator_spec.rb +119 -0
- data/spec/lib/protobuf/generators/message_generator_spec.rb +0 -0
- data/spec/lib/protobuf/generators/service_generator_spec.rb +99 -0
- data/spec/lib/protobuf/lifecycle_spec.rb +94 -0
- data/spec/lib/protobuf/message_spec.rb +944 -0
- data/spec/lib/protobuf/optionable_spec.rb +265 -0
- data/spec/lib/protobuf/rpc/client_spec.rb +66 -0
- data/spec/lib/protobuf/rpc/connectors/base_spec.rb +226 -0
- data/spec/lib/protobuf/rpc/connectors/ping_spec.rb +69 -0
- data/spec/lib/protobuf/rpc/connectors/socket_spec.rb +34 -0
- data/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +110 -0
- data/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +62 -0
- data/spec/lib/protobuf/rpc/middleware/logger_spec.rb +49 -0
- data/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +115 -0
- data/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +91 -0
- data/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +38 -0
- data/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +43 -0
- data/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +55 -0
- data/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +35 -0
- data/spec/lib/protobuf/rpc/service_directory_spec.rb +293 -0
- data/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +35 -0
- data/spec/lib/protobuf/rpc/service_filters_spec.rb +517 -0
- data/spec/lib/protobuf/rpc/service_spec.rb +162 -0
- data/spec/lib/protobuf/rpc/stat_spec.rb +101 -0
- data/spec/lib/protobuf/varint_spec.rb +29 -0
- data/spec/lib/protobuf_spec.rb +105 -0
- data/spec/spec_helper.rb +42 -0
- data/spec/support/all.rb +6 -0
- data/spec/support/packed_field.rb +23 -0
- data/spec/support/protos/all_types.data.bin +0 -0
- data/spec/support/protos/all_types.data.txt +119 -0
- data/spec/support/protos/enum.pb.rb +63 -0
- data/spec/support/protos/enum.proto +37 -0
- data/spec/support/protos/extreme_values.data.bin +0 -0
- data/spec/support/protos/google_unittest.bin +0 -0
- data/spec/support/protos/google_unittest.pb.rb +798 -0
- data/spec/support/protos/google_unittest.proto +884 -0
- data/spec/support/protos/google_unittest_custom_options.bin +0 -0
- data/spec/support/protos/google_unittest_custom_options.pb.rb +361 -0
- data/spec/support/protos/google_unittest_custom_options.proto +424 -0
- data/spec/support/protos/google_unittest_import.pb.rb +55 -0
- data/spec/support/protos/google_unittest_import.proto +73 -0
- data/spec/support/protos/google_unittest_import_public.pb.rb +31 -0
- data/spec/support/protos/google_unittest_import_public.proto +41 -0
- data/spec/support/protos/map-test.bin +157 -0
- data/spec/support/protos/map-test.pb.rb +85 -0
- data/spec/support/protos/map-test.proto +68 -0
- data/spec/support/protos/multi_field_extensions.pb.rb +59 -0
- data/spec/support/protos/multi_field_extensions.proto +35 -0
- data/spec/support/protos/resource.pb.rb +172 -0
- data/spec/support/protos/resource.proto +137 -0
- data/spec/support/resource_service.rb +23 -0
- data/spec/support/server.rb +65 -0
- data/spec/support/test_app_file.rb +2 -0
- data/varint_prof.rb +82 -0
- metadata +579 -0
@@ -0,0 +1,162 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require SUPPORT_PATH.join('resource_service')
|
3
|
+
|
4
|
+
RSpec.describe Protobuf::Rpc::Service do
|
5
|
+
|
6
|
+
context 'class methods' do
|
7
|
+
subject { Test::ResourceService }
|
8
|
+
|
9
|
+
before :each do
|
10
|
+
reset_service_location Test::ResourceService
|
11
|
+
end
|
12
|
+
|
13
|
+
describe '.host' do
|
14
|
+
specify { expect(subject.host).to eq described_class::DEFAULT_HOST }
|
15
|
+
end
|
16
|
+
|
17
|
+
describe '.host=' do
|
18
|
+
before { subject.host = 'mynewhost.com' }
|
19
|
+
specify { expect(subject.host).to eq 'mynewhost.com' }
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.port' do
|
23
|
+
specify { expect(subject.port).to eq described_class::DEFAULT_PORT }
|
24
|
+
end
|
25
|
+
|
26
|
+
describe '.port=' do
|
27
|
+
before { subject.port = 12345 }
|
28
|
+
specify { expect(subject.port).to eq 12345 }
|
29
|
+
end
|
30
|
+
|
31
|
+
describe '.configure' do
|
32
|
+
context 'when providing a host' do
|
33
|
+
before { subject.configure(:host => 'mynewhost.com') }
|
34
|
+
specify { expect(subject.host).to eq 'mynewhost.com' }
|
35
|
+
end
|
36
|
+
|
37
|
+
context 'when providing a port' do
|
38
|
+
before { subject.configure(:port => 12345) }
|
39
|
+
specify { expect(subject.port).to eq 12345 }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
describe '.located_at' do
|
44
|
+
context 'when given location is empty' do
|
45
|
+
before { subject.located_at(nil) }
|
46
|
+
specify { expect(subject.host).to eq described_class::DEFAULT_HOST }
|
47
|
+
specify { expect(subject.port).to eq described_class::DEFAULT_PORT }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'when given location is invalid' do
|
51
|
+
before { subject.located_at('i like pie') }
|
52
|
+
specify { expect(subject.host).to eq described_class::DEFAULT_HOST }
|
53
|
+
specify { expect(subject.port).to eq described_class::DEFAULT_PORT }
|
54
|
+
end
|
55
|
+
|
56
|
+
context 'when given location contains a host and port' do
|
57
|
+
before { subject.located_at('mynewdomain.com:12345') }
|
58
|
+
specify { expect(subject.host).to eq 'mynewdomain.com' }
|
59
|
+
specify { expect(subject.port).to eq 12345 }
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe '.client' do
|
64
|
+
it 'initializes a client object for this service' do
|
65
|
+
client = double('client')
|
66
|
+
expect(::Protobuf::Rpc::Client).to receive(:new)
|
67
|
+
.with(hash_including(
|
68
|
+
:service => subject,
|
69
|
+
:host => subject.host,
|
70
|
+
:port => subject.port,
|
71
|
+
)).and_return(client)
|
72
|
+
expect(subject.client).to eq client
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '.rpc' do
|
77
|
+
before { Test::ResourceService.rpc(:update, Test::ResourceFindRequest, Test::Resource) }
|
78
|
+
subject { Test::ResourceService.rpcs[:update] }
|
79
|
+
specify { expect(subject.method).to eq :update }
|
80
|
+
specify { expect(subject.request_type).to eq Test::ResourceFindRequest }
|
81
|
+
specify { expect(subject.response_type).to eq Test::Resource }
|
82
|
+
end
|
83
|
+
|
84
|
+
describe '.rpc_method?' do
|
85
|
+
before { Test::ResourceService.rpc(:delete, Test::Resource, Test::Resource) }
|
86
|
+
|
87
|
+
context 'when given name is a pre-defined rpc method' do
|
88
|
+
it 'returns true' do
|
89
|
+
expect(subject.rpc_method?(:delete)).to be true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when given name is not a pre-defined rpc method' do
|
94
|
+
it 'returns false' do
|
95
|
+
expect(subject.rpc_method?(:zoobaboo)).to be false
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context 'instance methods' do
|
102
|
+
context 'when invoking a service call' do
|
103
|
+
before do
|
104
|
+
stub_const('NewTestService', Class.new(Protobuf::Rpc::Service) do
|
105
|
+
rpc :find_with_implied_response, Test::ResourceFindRequest, Test::Resource
|
106
|
+
def find_with_implied_response
|
107
|
+
response.name = 'Implicit response'
|
108
|
+
end
|
109
|
+
|
110
|
+
rpc :find_with_respond_with, Test::ResourceFindRequest, Test::Resource
|
111
|
+
def find_with_respond_with
|
112
|
+
custom = Test::Resource.new(:name => 'Custom response')
|
113
|
+
respond_with(custom)
|
114
|
+
end
|
115
|
+
|
116
|
+
rpc :find_with_rpc_failed, Test::ResourceFindRequest, Test::Resource
|
117
|
+
def find_with_rpc_failed
|
118
|
+
rpc_failed('This is a failed endpoint')
|
119
|
+
response.name = 'Name will still be set'
|
120
|
+
end
|
121
|
+
end)
|
122
|
+
end
|
123
|
+
|
124
|
+
let(:request) { Test::ResourceFindRequest.new(:name => 'resource') }
|
125
|
+
let(:response) { Test::Resource.new }
|
126
|
+
|
127
|
+
context 'when calling the rpc method' do
|
128
|
+
context 'when response is implied' do
|
129
|
+
let(:env) do
|
130
|
+
Protobuf::Rpc::Env.new(
|
131
|
+
'request' => request,
|
132
|
+
'response_type' => response_type,
|
133
|
+
)
|
134
|
+
end
|
135
|
+
let(:response_type) { service.rpcs[:find_with_implied_response].response_type }
|
136
|
+
let(:service) { NewTestService }
|
137
|
+
|
138
|
+
subject { NewTestService.new(env) }
|
139
|
+
|
140
|
+
before { subject.find_with_implied_response }
|
141
|
+
specify { expect(subject.response).to be_a(Test::Resource) }
|
142
|
+
specify { expect(subject.response.name).to eq 'Implicit response' }
|
143
|
+
end
|
144
|
+
|
145
|
+
context 'when using respond_with paradigm' do
|
146
|
+
let(:env) do
|
147
|
+
Protobuf::Rpc::Env.new(
|
148
|
+
'method_name' => :find_with_respond_with,
|
149
|
+
'request' => request,
|
150
|
+
)
|
151
|
+
end
|
152
|
+
|
153
|
+
subject { NewTestService.new(env) }
|
154
|
+
|
155
|
+
before { subject.find_with_respond_with }
|
156
|
+
specify { expect(subject.response).to be_a(Test::Resource) }
|
157
|
+
specify { expect(subject.response.name).to eq 'Custom response' }
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end
|
161
|
+
end
|
162
|
+
end
|
@@ -0,0 +1,101 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'timecop'
|
3
|
+
require 'active_support/core_ext/numeric/time'
|
4
|
+
|
5
|
+
RSpec.describe ::Protobuf::Rpc::Stat do
|
6
|
+
|
7
|
+
before(:all) do
|
8
|
+
BarService = ::Struct.new(:method_name) unless defined?(BarService)
|
9
|
+
end
|
10
|
+
|
11
|
+
describe '#server=' do
|
12
|
+
it 'understands Array' do
|
13
|
+
stat = ::Protobuf::Rpc::Stat.new
|
14
|
+
stat.server = [3333, "127.0.0.1"]
|
15
|
+
expect(stat.server).to eq("127.0.0.1:3333")
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'understands String' do
|
19
|
+
stat = ::Protobuf::Rpc::Stat.new
|
20
|
+
stat.server = "thatserverthough"
|
21
|
+
expect(stat.server).to eq("thatserverthough")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'server mode' do
|
26
|
+
it 'describes a server response to a client' do
|
27
|
+
::Timecop.freeze(10.minutes.ago) do
|
28
|
+
stats = ::Protobuf::Rpc::Stat.new(:SERVER)
|
29
|
+
stats.client = 'myserver1'
|
30
|
+
stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars))
|
31
|
+
stats.request_size = 43
|
32
|
+
stats.response_size = 1302
|
33
|
+
|
34
|
+
::Timecop.freeze(1.62.seconds.from_now) do
|
35
|
+
stats.stop
|
36
|
+
expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - OK - #{::Time.now.iso8601}"
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
context 'when request is still running' do
|
42
|
+
it 'omits response size, duration, and timestamp' do
|
43
|
+
stats = ::Protobuf::Rpc::Stat.new(:SERVER)
|
44
|
+
stats.client = 'myserver1'
|
45
|
+
stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars))
|
46
|
+
stats.request_size = 43
|
47
|
+
expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/- - OK"
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
describe 'client mode' do
|
53
|
+
it 'describes a client request to a server' do
|
54
|
+
::Timecop.freeze(10.minutes.ago) do
|
55
|
+
stats = ::Protobuf::Rpc::Stat.new(:CLIENT)
|
56
|
+
stats.server = ['30000', 'myserver1.myhost.com']
|
57
|
+
stats.service = 'Foo::BarService'
|
58
|
+
stats.method_name = 'find_bars'
|
59
|
+
stats.request_size = 37
|
60
|
+
stats.response_size = 12345
|
61
|
+
|
62
|
+
::Timecop.freeze(0.832.seconds.from_now) do
|
63
|
+
stats.stop
|
64
|
+
expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - OK - #{::Time.now.iso8601}"
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'error log' do
|
71
|
+
it 'resolves error to a string' do
|
72
|
+
::Timecop.freeze(10.minutes.ago) do
|
73
|
+
stats = ::Protobuf::Rpc::Stat.new(:CLIENT)
|
74
|
+
stats.server = ['30000', 'myserver1.myhost.com']
|
75
|
+
stats.service = 'Foo::BarService'
|
76
|
+
stats.status = ::Protobuf::Socketrpc::ErrorReason::RPC_ERROR
|
77
|
+
stats.method_name = 'find_bars'
|
78
|
+
stats.request_size = 37
|
79
|
+
stats.response_size = 12345
|
80
|
+
|
81
|
+
::Timecop.freeze(0.832.seconds.from_now) do
|
82
|
+
stats.stop
|
83
|
+
expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - RPC_ERROR - #{::Time.now.iso8601}"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'when request is still running' do
|
90
|
+
it 'omits response size, duration, and timestamp' do
|
91
|
+
stats = ::Protobuf::Rpc::Stat.new(:CLIENT)
|
92
|
+
stats.server = ['30000', 'myserver1.myhost.com']
|
93
|
+
stats.service = 'Foo::BarService'
|
94
|
+
stats.method_name = 'find_bars'
|
95
|
+
stats.request_size = 37
|
96
|
+
expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/- - OK"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
require 'base64'
|
2
|
+
require 'spec_helper'
|
3
|
+
|
4
|
+
RSpec.describe Protobuf::Varint do
|
5
|
+
VALUES = {
|
6
|
+
0 => "AA==",
|
7
|
+
5 => "BQ==",
|
8
|
+
51 => "Mw==",
|
9
|
+
9_192 => "6Ec=",
|
10
|
+
80_389 => "hfQE",
|
11
|
+
913_389 => "7d83",
|
12
|
+
516_192_829_912_693 => "9eyMkpivdQ==",
|
13
|
+
9_999_999_999_999_999_999 => "//+fz8jgyOOKAQ==",
|
14
|
+
}.freeze
|
15
|
+
|
16
|
+
[defined?(::Varint) ? ::Varint : nil, Protobuf::VarintPure].compact.each do |klass|
|
17
|
+
context "with #{klass}" do
|
18
|
+
before { described_class.extend(klass) }
|
19
|
+
after { load ::File.expand_path('../../../../lib/protobuf/varint.rb', __FILE__) }
|
20
|
+
|
21
|
+
VALUES.each do |number, encoded|
|
22
|
+
it "decodes #{number}" do
|
23
|
+
io = StringIO.new(Base64.decode64(encoded))
|
24
|
+
expect(described_class.decode(io)).to eq(number)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'protobuf'
|
3
|
+
|
4
|
+
RSpec.describe ::Protobuf do
|
5
|
+
|
6
|
+
describe '.client_host' do
|
7
|
+
after { ::Protobuf.client_host = nil }
|
8
|
+
|
9
|
+
subject { ::Protobuf.client_host }
|
10
|
+
|
11
|
+
context 'when client_host is not pre-configured' do
|
12
|
+
it { is_expected.to eq ::Socket.gethostname }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'when client_host is pre-configured' do
|
16
|
+
let(:hostname) { 'override.myhost.com' }
|
17
|
+
before { ::Protobuf.client_host = hostname }
|
18
|
+
it { is_expected.to eq hostname }
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe '.connector_type_class' do
|
23
|
+
it "defaults to Socket" do
|
24
|
+
described_class.connector_type_class = nil
|
25
|
+
expect(described_class.connector_type_class).to eq(::Protobuf::Rpc::Connectors::Socket)
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'fails if fails to load the PB_CLIENT_TYPE' do
|
29
|
+
ENV['PB_CLIENT_TYPE'] = "something_to_autoload"
|
30
|
+
expect { load 'protobuf.rb' }.to raise_error(LoadError, /something_to_autoload/)
|
31
|
+
ENV.delete('PB_CLIENT_TYPE')
|
32
|
+
end
|
33
|
+
|
34
|
+
it 'loads the connector type class from PB_CLIENT_TYPE' do
|
35
|
+
ENV['PB_CLIENT_TYPE'] = "protobuf/rpc/connectors/zmq"
|
36
|
+
load 'protobuf.rb'
|
37
|
+
expect(::Protobuf.connector_type_class).to eq(::Protobuf::Rpc::Connectors::Zmq)
|
38
|
+
ENV.delete('PB_CLIENT_TYPE')
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '.gc_pause_server_request?' do
|
43
|
+
before { described_class.instance_variable_set(:@gc_pause_server_request, nil) }
|
44
|
+
|
45
|
+
it 'defaults to a false value' do
|
46
|
+
expect(described_class.gc_pause_server_request?).to be false
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'is settable' do
|
50
|
+
described_class.gc_pause_server_request = true
|
51
|
+
expect(described_class.gc_pause_server_request?).to be true
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
describe '.print_deprecation_warnings?' do
|
56
|
+
around do |example|
|
57
|
+
orig = described_class.print_deprecation_warnings?
|
58
|
+
example.call
|
59
|
+
described_class.print_deprecation_warnings = orig
|
60
|
+
end
|
61
|
+
|
62
|
+
it 'defaults to a true value' do
|
63
|
+
allow(ENV).to receive(:key?).with('PB_IGNORE_DEPRECATIONS').and_return(false)
|
64
|
+
described_class.instance_variable_set('@field_deprecator', nil)
|
65
|
+
expect(described_class.print_deprecation_warnings?).to be true
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'is settable' do
|
69
|
+
described_class.print_deprecation_warnings = false
|
70
|
+
expect(described_class.print_deprecation_warnings?).to be false
|
71
|
+
end
|
72
|
+
|
73
|
+
context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do
|
74
|
+
it 'defaults to a false value' do
|
75
|
+
allow(ENV).to receive(:key?).with('PB_IGNORE_DEPRECATIONS').and_return(true)
|
76
|
+
described_class.instance_variable_set('@field_deprecator', nil)
|
77
|
+
expect(described_class.print_deprecation_warnings?).to be false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
describe '.ignore_unknown_fields?' do
|
83
|
+
around do |example|
|
84
|
+
orig = described_class.ignore_unknown_fields?
|
85
|
+
example.call
|
86
|
+
described_class.ignore_unknown_fields = orig
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'defaults to a true value' do
|
90
|
+
if described_class.instance_variable_defined?('@ignore_unknown_fields')
|
91
|
+
described_class.send(:remove_instance_variable, '@ignore_unknown_fields')
|
92
|
+
end
|
93
|
+
expect(described_class.ignore_unknown_fields?).to be true
|
94
|
+
end
|
95
|
+
|
96
|
+
it 'is settable' do
|
97
|
+
expect do
|
98
|
+
described_class.ignore_unknown_fields = false
|
99
|
+
end.to change {
|
100
|
+
described_class.ignore_unknown_fields?
|
101
|
+
}.from(true).to(false)
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'timeout'
|
2
|
+
require 'rubygems'
|
3
|
+
require 'bundler'
|
4
|
+
Bundler.setup :default, :development, :test
|
5
|
+
require 'pry'
|
6
|
+
require 'pathname'
|
7
|
+
|
8
|
+
$LOAD_PATH << ::File.expand_path('../..', __FILE__)
|
9
|
+
SUPPORT_PATH = Pathname.new(::File.expand_path('../support', __FILE__))
|
10
|
+
PROTOS_PATH = SUPPORT_PATH.join('protos')
|
11
|
+
$LOAD_PATH << SUPPORT_PATH
|
12
|
+
|
13
|
+
require 'protobuf'
|
14
|
+
require 'protobuf/rpc/server'
|
15
|
+
require SUPPORT_PATH.join('all')
|
16
|
+
|
17
|
+
$LOAD_PATH << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__)
|
18
|
+
require 'google/protobuf/compiler/plugin.pb'
|
19
|
+
|
20
|
+
# Including a way to turn on debug logger for spec runs
|
21
|
+
if ENV.key?('DEBUG')
|
22
|
+
debug_log = ::File.expand_path('../../debug_specs.log', __FILE__)
|
23
|
+
::Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG)
|
24
|
+
else
|
25
|
+
::Protobuf::Logging.initialize_logger('/dev/null')
|
26
|
+
end
|
27
|
+
|
28
|
+
# Get rid of the deprecation env var if present (messes with specs).
|
29
|
+
ENV.delete("PB_IGNORE_DEPRECATIONS")
|
30
|
+
|
31
|
+
::Protobuf::Rpc::Client.class_eval do
|
32
|
+
def ==(other)
|
33
|
+
connector.options == other.options && \
|
34
|
+
success_cb == other.success_cb && \
|
35
|
+
failure_cb == other.failure_cb
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def reset_service_location(service)
|
40
|
+
service.host = nil
|
41
|
+
service.port = nil
|
42
|
+
end
|