From 851b4289c44c26cf635dccfbaee1748a268b8d9d Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Thu, 5 Jun 2014 11:44:26 -0700 Subject: [PATCH 001/298] Update float fields to cast strings more strongly --- lib/protobuf/field/float_field.rb | 21 ++++++++ spec/lib/protobuf/field/float_field_spec.rb | 55 +++++++++++++++++++++ 2 files changed, 76 insertions(+) create mode 100644 spec/lib/protobuf/field/float_field_spec.rb diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 0480486b..5a335250 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -32,6 +32,27 @@ def wire_type WireType::FIXED32 end + ## + # Private Instance Methods + # + + def define_setter + field = self + message_class.class_eval do + define_method(field.setter_method_name) do |val| + field.warn_if_deprecated + + if val.nil? || (val.respond_to?(:empty?) && val.empty?) + @values.delete(field.name) + elsif field.acceptable?(val) + @values[field.name] = Float(val) + else + raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" + end + end + end + end + end end end diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb new file mode 100644 index 00000000..835885c0 --- /dev/null +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -0,0 +1,55 @@ +require 'spec_helper' + +describe Protobuf::Field::FloatField do + + class SomeFloatMessage < ::Protobuf::Message + optional :float, :some_float, 1 + end + + let(:instance) { SomeFloatMessage.new } + + describe '#define_setter' do + subject { instance.some_float = value; instance.some_float } + + context 'when set with an int' do + let(:value) { 100 } + + it 'is readable as a float' do + expect(subject).to eq(100.0) + end + end + + context 'when set with a float' do + let(:value) { 100.1 } + + it 'is readable as a float' do + expect(subject).to eq(100.1) + end + end + + context 'when set with a string of a float' do + let(:value) { "101.1" } + + it 'is readable as a float' do + expect(subject).to eq(101.1) + end + end + + context 'when set with a non-numeric string' do + let(:value) { "aaaa" } + + it 'throws an error' do + expect { subject }.to raise_error(ArgumentError) + end + end + + context 'when set with something that is not a float' do + let(:value) { [ 1, 2, 3 ] } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + end + +end From 5ea34151acb541938afd7472086949917a8e0ace Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Fri, 6 Jun 2014 15:15:25 -0700 Subject: [PATCH 002/298] Add a coerce! method to share code with superclass --- lib/protobuf/field/base_field.rb | 6 +++++- lib/protobuf/field/float_field.rb | 25 ++++--------------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index cb8bb9bb..739e1aaa 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -63,6 +63,10 @@ def acceptable?(value) true end + def coerce!(value) + value + end + def enum? false end @@ -226,7 +230,7 @@ def define_setter if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) - @values[field.name] = val + @values[field.name] = field.coerce!(val) else raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 5a335250..4d138972 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -20,6 +20,10 @@ def acceptable?(val) val.respond_to?(:to_f) end + def coerce!(val) + Float(val) + end + def decode(bytes) bytes.unpack('e').first end @@ -32,27 +36,6 @@ def wire_type WireType::FIXED32 end - ## - # Private Instance Methods - # - - def define_setter - field = self - message_class.class_eval do - define_method(field.setter_method_name) do |val| - field.warn_if_deprecated - - if val.nil? || (val.respond_to?(:empty?) && val.empty?) - @values.delete(field.name) - elsif field.acceptable?(val) - @values[field.name] = Float(val) - else - raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" - end - end - end - end - end end end From 59dfbb7ed12a8f181585a52a3db39f13967f9064 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Jun 2014 10:01:56 -0600 Subject: [PATCH 003/298] Update rspec 2.x syntax to 3.x to remove deprecations --- protobuf.gemspec | 2 +- spec/encoding/all_types_spec.rb | 2 +- spec/encoding/extreme_values_spec.rb | Bin 1352 -> 1357 bytes spec/functional/socket_server_spec.rb | 9 +- spec/functional/zmq_server_spec.rb | 14 +-- spec/lib/protobuf/cli_spec.rb | 78 ++++++++-------- spec/lib/protobuf/code_generator_spec.rb | 8 +- spec/lib/protobuf/enum_spec.rb | 46 +++++----- spec/lib/protobuf/field/string_field_spec.rb | 8 +- spec/lib/protobuf/generators/base_spec.rb | 11 +-- .../generators/enum_generator_spec.rb | 6 +- .../generators/extension_generator_spec.rb | 8 +- .../generators/field_generator_spec.rb | 22 ++--- .../generators/file_generator_spec.rb | 6 +- .../generators/service_generator_spec.rb | 4 +- spec/lib/protobuf/lifecycle_spec.rb | 32 +++---- spec/lib/protobuf/logger_spec.rb | 54 +++++------ spec/lib/protobuf/message_spec.rb | 84 +++++++++--------- spec/lib/protobuf/optionable_spec.rb | 2 +- spec/lib/protobuf/rpc/client_spec.rb | 26 +++--- spec/lib/protobuf/rpc/connector_spec.rb | 8 +- spec/lib/protobuf/rpc/connectors/base_spec.rb | 14 +-- .../protobuf/rpc/connectors/common_spec.rb | 64 +++++++------ .../protobuf/rpc/connectors/socket_spec.rb | 16 ++-- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 59 +++++------- .../rpc/middleware/exception_handler_spec.rb | 16 ++-- .../protobuf/rpc/middleware/logger_spec.rb | 4 +- .../rpc/middleware/request_decoder_spec.rb | 20 ++--- .../rpc/middleware/response_encoder_spec.rb | 12 +-- .../rpc/servers/socket_server_spec.rb | 6 +- .../protobuf/rpc/servers/zmq/server_spec.rb | 6 +- .../lib/protobuf/rpc/servers/zmq/util_spec.rb | 4 +- .../protobuf/rpc/servers/zmq/worker_spec.rb | 10 +-- .../protobuf/rpc/service_directory_spec.rb | 53 ++++++----- .../protobuf/rpc/service_dispatcher_spec.rb | 8 +- spec/lib/protobuf/rpc/service_filters_spec.rb | 78 ++++++++-------- spec/lib/protobuf/rpc/service_spec.rb | 54 +++++------ spec/lib/protobuf/rpc/stat_spec.rb | 8 +- spec/lib/protobuf_spec.rb | 14 +-- spec/spec_helper.rb | 1 + spec/support/packed_field.rb | 2 +- 41 files changed, 432 insertions(+), 447 deletions(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index 026f0d06..da98eee5 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -27,7 +27,7 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'pry-nav' s.add_development_dependency 'rake' - s.add_development_dependency 'rspec' + s.add_development_dependency 'rspec', '>= 3.0' s.add_development_dependency 'simplecov' s.add_development_dependency 'yard' s.add_development_dependency 'timecop' diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index 3f278cbf..c202215a 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -86,6 +86,6 @@ file.read end - data.should eq message.serialize_to_string + expect(data).to eq(message.serialize_to_string) end end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 8f8c0b9d9328f9b024258fb5c398afa3ea9071c3..65f1c910a25e433add419fb72f73bcd988187706 100644 GIT binary patch delta 66 zcmX@Xb(U*`FsoH+ML}wEiAG9dNus7+NxnjAp+;_MadBdLs$OwwQD$OJW>so@Nq&5B TNl|8Ax+a%`LTX+L7YG9YBBB>p delta 61 zcmX@hb%JYyFso@wVo9Q2aYlY=PKrWmp+atIadBdLs$OwwQD$OJW>so@Nq&5BNl|8A OI+ub%YF-K#2m=7QQ5Ew5 diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 2af158d1..ffeecc7b 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -21,8 +21,8 @@ client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) + expect(succ.name).to eq("Test Name") + expect(succ.status).to eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -41,7 +41,8 @@ c.on_success { raise "shouldn't pass"} c.on_failure {|e| error = e} end - error.message.should =~ /name.*required/ + + expect(error.message).to match(/name.*required/) end it 'calls the on_failure callback when the request type is wrong' do @@ -53,7 +54,7 @@ c.on_success { raise "shouldn't pass"} c.on_failure {|e| error = e} end - error.message.should =~ /expected request.*ResourceFindRequest.*Resource instead/i + expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 543835ce..053eb383 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -27,8 +27,8 @@ client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) + expect(succ.name).to eq("Test Name") + expect(succ.status).to eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -46,8 +46,8 @@ client.find(:name => 'Test Name', :active => true) do |c| c.on_success do |succ| - succ.name.should eq("Test Name") - succ.status.should eq(::Test::StatusType::ENABLED) + expect(succ.name).to eq("Test Name") + expect(succ.status).to eq(::Test::StatusType::ENABLED) end c.on_failure do |err| @@ -69,7 +69,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure {|e| error = e } end - error.message.should match(/name.*required/) + expect(error.message).to match(/name.*required/) end end @@ -83,7 +83,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure {|e| error = e} end - error.message.should match(/expected request.*ResourceFindRequest.*Resource instead/i) + expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end end @@ -96,7 +96,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure { |e| error = e } end - error.message.should match(/The server repeatedly failed to respond/) + expect(error.message).to match(/The server repeatedly failed to respond/) end end diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 91fdef44..c33dba9a 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -9,19 +9,19 @@ let(:sock_runner) { runner = double("SocketRunner", :register_signals => nil) - runner.stub(:run) { ::ActiveSupport::Notifications.publish( "after_server_bind" ) } + allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner } let(:zmq_runner) { runner = double "ZmqRunner", register_signals: nil - runner.stub(:run) { ::ActiveSupport::Notifications.publish( "after_server_bind" ) } + allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner } before(:each) do - ::Protobuf::Rpc::SocketRunner.stub(:new) { sock_runner } - ::Protobuf::Rpc::ZmqRunner.stub(:new) { zmq_runner } + allow(::Protobuf::Rpc::SocketRunner).to receive(:new).and_return(sock_runner) + allow(::Protobuf::Rpc::ZmqRunner).to receive(:new).and_return(zmq_runner) end describe '#start' do @@ -33,8 +33,8 @@ let(:test_args) { [ '--host=123.123.123.123' ] } it 'sends the host option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:host].should eq '123.123.123.123' + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:host]).to eq '123.123.123.123' end.and_return(sock_runner) described_class.start(args) end @@ -44,8 +44,8 @@ let(:test_args) { [ '--port=12345' ] } it 'sends the port option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:port].should eq 12345 + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:port]).to eq 12345 end.and_return(sock_runner) described_class.start(args) end @@ -55,8 +55,8 @@ let(:test_args) { [ '--threads=500' ] } it 'sends the threads option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:threads].should eq 500 + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:threads]).to eq 500 end.and_return(sock_runner) described_class.start(args) end @@ -66,8 +66,8 @@ let(:test_args) { [ '--backlog=500' ] } it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:backlog].should eq 500 + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:backlog]).to eq 500 end.and_return(sock_runner) described_class.start(args) end @@ -77,8 +77,8 @@ let(:test_args) { [ '--threshold=500' ] } it 'sends the backlog option to the runner' do - ::Protobuf::Rpc::SocketRunner.should_receive(:new) do |options| - options[:threshold].should eq 500 + expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| + expect(options[:threshold]).to eq 500 end.and_return(sock_runner) described_class.start(args) end @@ -88,9 +88,9 @@ let(:test_args) { [ '--log=mylog.log', '--level=0' ] } it 'sends the log file and level options to the runner' do - ::Protobuf::Logger.should_receive(:configure) do |options| - options[:file].should eq 'mylog.log' - options[:level].should eq 0 + expect(::Protobuf::Logger).to receive(:configure) do |options| + expect(options[:file]).to eq 'mylog.log' + expect(options[:level]).to eq 0 end described_class.start(args) end @@ -103,7 +103,7 @@ it 'sets both request and serialization pausing to false' do described_class.start(args) - ::Protobuf.should_not be_gc_pause_server_request + expect(::Protobuf).to_not be_gc_pause_server_request end end @@ -113,7 +113,7 @@ it 'sets the configuration option to GC pause server request' do described_class.start(args) - ::Protobuf.should be_gc_pause_server_request + expect(::Protobuf).to be_gc_pause_server_request end end end @@ -128,7 +128,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + expect(::Protobuf.print_deprecation_warnings?).to be_truthy end end @@ -138,7 +138,7 @@ it 'sets the deprecation warning flag to false ' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_false + expect(::Protobuf.print_deprecation_warnings?).to be_falsey end end end @@ -148,7 +148,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_true + expect(::Protobuf.print_deprecation_warnings?).to be_truthy end end @@ -157,7 +157,7 @@ it 'sets the deprecation warning flag to false' do described_class.start(args) - ::Protobuf.print_deprecation_warnings?.should be_false + expect(::Protobuf.print_deprecation_warnings?).to be_falsey end end end @@ -169,24 +169,24 @@ let(:runner) { ::Protobuf::Rpc::SocketRunner } before do - ::Protobuf::Rpc::ZmqRunner.should_not_receive(:new) + expect(::Protobuf::Rpc::ZmqRunner).not_to receive(:new) end it 'is activated by the --socket switch' do - runner.should_receive(:new) + expect(runner).to receive(:new) described_class.start(args) end it 'is activated by PB_SERVER_TYPE=Socket ENV variable' do ENV['PB_SERVER_TYPE'] = "Socket" - runner.should_receive(:new).and_return(sock_runner) + expect(runner).to receive(:new).and_return(sock_runner) described_class.start(args) ENV.delete('PB_SERVER_TYPE') end it 'configures the connector type to be socket' do load "protobuf/socket.rb" - ::Protobuf.connector_type.should == :socket + expect(::Protobuf.connector_type).to eq(:socket) end end @@ -195,12 +195,12 @@ let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new) end it 'is activated by the --workers_only switch' do - runner.should_receive(:new) do |options| - options[:workers_only].should be_true + expect(runner).to receive(:new) do |options| + expect(options[:workers_only]).to be_truthy end.and_return(zmq_runner) described_class.start(args) @@ -208,8 +208,8 @@ it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do ENV['PB_WORKERS_ONLY'] = "1" - runner.should_receive(:new) do |options| - options[:workers_only].should be_true + expect(runner).to receive(:new) do |options| + expect(options[:workers_only]).to be_truthy end.and_return(zmq_runner) described_class.start(args) @@ -222,12 +222,12 @@ let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new) end it 'is activated by the --worker_port switch' do - runner.should_receive(:new) do |options| - options[:worker_port].should eq(1234) + expect(runner).to receive(:new) do |options| + expect(options[:worker_port]).to eq(1234) end.and_return(zmq_runner) described_class.start(args) @@ -239,24 +239,24 @@ let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do - ::Protobuf::Rpc::SocketRunner.should_not_receive(:new) + expect(::Protobuf::Rpc::SocketRunner).not_to receive(:new) end it 'is activated by the --zmq switch' do - runner.should_receive(:new) + expect(runner).to receive(:new) described_class.start(args) end it 'is activated by PB_SERVER_TYPE=Zmq ENV variable' do ENV['PB_SERVER_TYPE'] = "Zmq" - runner.should_receive(:new) + expect(runner).to receive(:new) described_class.start(args) ENV.delete('PB_SERVER_TYPE') end it 'configures the connector type to be zmq' do load "protobuf/zmq.rb" - ::Protobuf.connector_type.should == :zmq + expect(::Protobuf.connector_type).to eq(:zmq) end end diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 65cace6a..ca31b278 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -27,13 +27,13 @@ end before do - ::Protobuf::Generators::FileGenerator.should_receive(:new).with(input_file1).and_return(file_generator1) - ::Protobuf::Generators::FileGenerator.should_receive(:new).with(input_file2).and_return(file_generator2) + expect(::Protobuf::Generators::FileGenerator).to receive(:new).with(input_file1).and_return(file_generator1) + expect(::Protobuf::Generators::FileGenerator).to receive(:new).with(input_file2).and_return(file_generator2) end it 'returns the serialized CodeGeneratorResponse which contains the generated file contents' do generator = described_class.new(request_bytes) - generator.response_bytes.should eq expected_response_bytes + expect(generator.response_bytes).to eq expected_response_bytes end end @@ -51,7 +51,7 @@ describe '.warn' do it 'prints a warning to stderr' do - STDERR.should_receive(:puts).with("[WARN] a warning") + expect(STDERR).to receive(:puts).with("[WARN] a warning") described_class.warn("a warning") end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index fc03322f..21ebfdd0 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -22,7 +22,7 @@ describe '.aliases_allowed?' do it 'is false when the option is not set' do - expect(Test::EnumTestType.aliases_allowed?).to be_false + expect(Test::EnumTestType.aliases_allowed?).to be_falsey end end @@ -155,15 +155,15 @@ describe '.valid_tag?' do context 'when tag is defined' do - specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_true } + specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_truthy } end context 'when tag is not defined' do - specify { expect(Test::EnumTestType.valid_tag?(300)).to be_false } + specify { expect(Test::EnumTestType.valid_tag?(300)).to be_falsey } end context 'is true for aliased enums' do - specify { expect(EnumAliasTest.valid_tag?(1)).to be_true } + specify { expect(EnumAliasTest.valid_tag?(1)).to be_truthy } end end @@ -201,31 +201,31 @@ end subject { Test::EnumTestType::ONE } - its(:class) { should eq(Fixnum) } - its(:parent_class) { should eq(Test::EnumTestType) } - its(:name) { should eq(:ONE) } - its(:tag) { should eq(1) } - its(:value) { should eq(1) } - its(:to_hash_value) { should eq(1) } - its(:to_s) { should eq("1") } - its(:inspect) { should eq('#') } - specify { subject.to_s(:tag).should eq("1") } - specify { subject.to_s(:name).should eq("ONE") } + specify { expect(subject.class).to eq(Fixnum) } + specify { expect(subject.parent_class).to eq(Test::EnumTestType) } + specify { expect(subject.name).to eq(:ONE) } + specify { expect(subject.tag).to eq(1) } + specify { expect(subject.value).to eq(1) } + specify { expect(subject.to_hash_value).to eq(1) } + specify { expect(subject.to_s).to eq("1") } + specify { expect(subject.inspect).to eq('#') } + specify { expect(subject.to_s(:tag)).to eq("1") } + specify { expect(subject.to_s(:name)).to eq("ONE") } it "can be used as the index to an array" do array = [0, 1, 2, 3] - array[::Test::EnumTestType::ONE].should eq(1) + expect(array[::Test::EnumTestType::ONE]).to eq(1) end describe '#try' do - specify { subject.try(:parent_class).should eq(subject.parent_class) } - specify { subject.try(:class).should eq(subject.class) } - specify { subject.try(:name).should eq(subject.name) } - specify { subject.try(:tag).should eq(subject.tag) } - specify { subject.try(:value).should eq(subject.value) } - specify { subject.try(:to_i).should eq(subject.to_i) } - specify { subject.try(:to_int).should eq(subject.to_int) } - specify { subject.try { |yielded| yielded.should eq(subject) } } + specify { expect(subject.try(:parent_class)).to eq(subject.parent_class) } + specify { expect(subject.try(:class)).to eq(subject.class) } + specify { expect(subject.try(:name)).to eq(subject.name) } + specify { expect(subject.try(:tag)).to eq(subject.tag) } + specify { expect(subject.try(:value)).to eq(subject.value) } + specify { expect(subject.try(:to_i)).to eq(subject.to_i) } + specify { expect(subject.try(:to_int)).to eq(subject.to_int) } + specify { subject.try { |yielded| expect(yielded).to eq(subject) } } end context 'when coercing from enum' do diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index 50ba13b9..887d8e57 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -27,18 +27,18 @@ source_string = "foo" proto = ::Test::Resource.new(:name => source_string) proto.encode - proto.name.should eq source_string + expect(proto.name).to eq source_string proto.encode - proto.name.should eq source_string + expect(proto.name).to eq source_string end it 'does not alter unicode string values after encoding multiple times' do source_string = "ยข" proto = ::Test::Resource.new(:name => source_string) proto.encode - proto.name.should eq source_string + expect(proto.name).to eq source_string proto.encode - proto.name.should eq source_string + expect(proto.name).to eq source_string end end diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 27157b77..a7a303e4 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -10,8 +10,8 @@ context 'namespaces' do let(:descriptor) { double(:name => 'Baz') } subject { described_class.new(descriptor, 0, :namespace => [ :foo, :bar ]) } - its(:type_namespace) { should eq [ :foo, :bar, 'Baz' ] } - its(:fully_qualified_type_namespace) { should eq '.foo.bar.Baz' } + specify { expect(subject.type_namespace).to eq([ :foo, :bar, 'Baz' ]) } + specify { expect(subject.fully_qualified_type_namespace).to eq('.foo.bar.Baz') } end describe '#run_once' do @@ -67,17 +67,14 @@ def compile describe '#validate_tags' do context 'when tags are duplicated' do it 'fails with a GeneratorFatalError' do - ::Protobuf::CodeGenerator.should_receive(:fatal) - .with(/FooBar object has duplicate tags\. Expected 3 tags, but got 4/) - + expect(::Protobuf::CodeGenerator).to receive(:fatal).with(/FooBar object has duplicate tags\. Expected 3 tags, but got 4/) described_class.validate_tags("FooBar", [1,2,2,3]) end end context 'when tags are missing in the range' do it 'prints a warning' do - ::Protobuf::CodeGenerator.should_receive(:warn) - .with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) + expect(::Protobuf::CodeGenerator).to receive(:warn).with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) described_class.validate_tags("FooBar", [1,2,4,5]) end end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 9d7048f5..a2dbbb0d 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -33,7 +33,7 @@ it 'compiles the enum and it\'s field values' do subject.compile - subject.to_s.should eq(compiled) + expect(subject.to_s).to eq(compiled) end context 'when allow_alias option is set' do @@ -53,14 +53,14 @@ it 'sets the allow_alias option' do subject.compile - subject.to_s.should eq(compiled) + expect(subject.to_s).to eq(compiled) end end end describe '#build_value' do it 'returns a string identifying the given enum value' do - subject.build_value(enum.value.first).should eq("define :FOO, 1") + expect(subject.build_value(enum.value.first)).to eq("define :FOO, 1") end end diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index da072abe..5d0e21f7 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -15,9 +15,9 @@ let(:message_type) { 'FooBar' } before do - ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[0], 1).and_return(field_descriptors[0]) - ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[1], 1).and_return(field_descriptors[1]) - ::Protobuf::Generators::FieldGenerator.should_receive(:new).with(field_descriptors[2], 1).and_return(field_descriptors[2]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[0], 1).and_return(field_descriptors[0]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[1], 1).and_return(field_descriptors[1]) + expect(::Protobuf::Generators::FieldGenerator).to receive(:new).with(field_descriptors[2], 1).and_return(field_descriptors[2]) end subject { described_class.new(message_type, field_descriptors, 0) } @@ -35,7 +35,7 @@ it 'compiles the a class with the extension fields' do subject.compile - subject.to_s.should eq(compiled) + expect(subject.to_s).to eq(compiled) end end diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 5f97b412..714c864e 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -27,33 +27,33 @@ describe '#compile' do subject { described_class.new(field).to_s } - it { should eq "optional :string, :foo_bar, 3\n" } + specify { expect(subject).to eq "optional :string, :foo_bar, 3\n" } context 'when the type is another message' do let(:type_enum) { :TYPE_MESSAGE } let(:type_name) { '.foo.bar.Baz' } - it { should eq "optional ::Foo::Bar::Baz, :foo_bar, 3\n" } + specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3\n" } end context 'when a default value is used' do let(:type_enum) { :TYPE_INT32 } let(:default_value) { '42' } - it { should eq "optional :int32, :foo_bar, 3, :default => 42\n" } + specify { expect(subject).to eq "optional :int32, :foo_bar, 3, :default => 42\n" } context 'when type is an enum' do let(:type_enum) { :TYPE_ENUM } let(:type_name) { '.foo.bar.Baz' } let(:default_value) { 'QUUX' } - it { should eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } + specify { expect(subject).to eq "optional ::Foo::Bar::Baz, :foo_bar, 3, :default => ::Foo::Bar::Baz::QUUX\n" } end context 'when the type is a string' do let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } - it { should eq %Q{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } + specify { expect(subject).to eq %Q{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } end context 'when float or double field type' do @@ -61,17 +61,17 @@ context 'when the default value is "nan"' do let(:default_value) { 'nan' } - it { should match(/::Float::NAN/) } + specify { expect(subject).to match(/::Float::NAN/) } end context 'when the default value is "inf"' do let(:default_value) { 'inf' } - it { should match(/::Float::INFINITY/) } + specify { expect(subject).to match(/::Float::INFINITY/) } end context 'when the default value is "-inf"' do let(:default_value) { '-inf' } - it { should match(/-::Float::INFINITY/) } + specify { expect(subject).to match(/-::Float::INFINITY/) } end end end @@ -79,19 +79,19 @@ context 'when the field is an extension' do let(:extendee) { 'foo.bar.Baz' } - it { should eq "optional :string, :foo_bar, 3, :extension => true\n" } + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :extension => true\n" } end context 'when field is packed' do let(:field_options) { { :packed => true } } - it { should eq "optional :string, :foo_bar, 3, :packed => true\n" } + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :packed => true\n" } end context 'when field is deprecated' do let(:field_options) { { :deprecated => true } } - it { should eq "optional :string, :foo_bar, 3, :deprecated => true\n" } + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :deprecated => true\n" } end end diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 19559c9a..9f666afa 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -9,7 +9,7 @@ let(:file_descriptor) { ::Google::Protobuf::FileDescriptorProto.new(descriptor_fields) } subject { described_class.new(file_descriptor) } - its(:file_name) { should eq 'test/foo.pb.rb' } + specify { expect(subject.file_name).to eq('test/foo.pb.rb') } describe '#print_import_requires' do let(:descriptor_fields) do @@ -18,8 +18,8 @@ end it 'prints a ruby require for each dependency' do - subject.should_receive(:print_require).with('test/bar.pb') - subject.should_receive(:print_require).with('test/baz.pb') + expect(subject).to receive(:print_require).with('test/bar.pb') + expect(subject).to receive(:print_require).with('test/baz.pb') subject.print_import_requires end diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index c10c6293..dae1fc02 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -29,13 +29,13 @@ it 'compiles the service and it\'s rpc methods' do subject.compile - subject.to_s.should eq(compiled) + expect(subject.to_s).to eq(compiled) end end describe '#build_method' do it 'returns a string identifying the given method descriptor' do - subject.build_method(service.method.first).should eq("rpc :search, FooRequest, FooResponse") + expect(subject.build_method(service.method.first)).to eq("rpc :search, FooRequest, FooResponse") end end diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index f40a5fb2..fce13162 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -9,8 +9,8 @@ end it "registers a string as the event_name" do - ::ActiveSupport::Notifications.should_receive(:subscribe).with("something") - subject.register("something") { true } + expect(::ActiveSupport::Notifications).to receive(:subscribe).with("something") + subject.register("something") { true } end it "only registers blocks for event callbacks" do @@ -26,8 +26,8 @@ end subject.trigger("this") - this.should_not be_nil - this.should eq("not nil") + expect(this).to_not be_nil + expect(this).to eq("not nil") end it "calls multiple registered blocks when triggered" do @@ -43,10 +43,10 @@ end subject.trigger("this") - this.should_not be_nil - this.should eq("not nil") - that.should_not be_nil - that.should eq("not nil") + expect(this).to_not be_nil + expect(this).to eq("not nil") + expect(that).to_not be_nil + expect(that).to eq("not nil") end context 'when the registered block has arity' do @@ -55,12 +55,12 @@ outer_bar = nil subject.register('foo') do |bar| - bar.should be_nil + expect(bar).to be_nil outer_bar = 'triggered' end subject.trigger('foo') - outer_bar.should eq 'triggered' + expect(outer_bar).to eq 'triggered' end end @@ -69,21 +69,21 @@ outer_bar = nil subject.register('foo') do |bar| - bar.should_not be_nil + expect(bar).to_not be_nil outer_bar = bar end subject.trigger('foo', 'baz') - outer_bar.should eq 'baz' + expect(outer_bar).to eq 'baz' end end end context "normalized event names" do - specify { subject.normalized_event_name(:derp).should eq("derp") } - specify { subject.normalized_event_name(:Derp).should eq("derp") } - specify { subject.normalized_event_name("DERP").should eq("derp") } - specify { subject.normalized_event_name("derp").should eq("derp") } + specify { expect(subject.normalized_event_name(:derp)).to eq("derp") } + specify { expect(subject.normalized_event_name(:Derp)).to eq("derp") } + specify { expect(subject.normalized_event_name("DERP")).to eq("derp") } + specify { expect(subject.normalized_event_name("derp")).to eq("derp") } end end diff --git a/spec/lib/protobuf/logger_spec.rb b/spec/lib/protobuf/logger_spec.rb index 04ce7dbe..15eaaebe 100644 --- a/spec/lib/protobuf/logger_spec.rb +++ b/spec/lib/protobuf/logger_spec.rb @@ -20,22 +20,22 @@ it 'doesn\'t create a logger if the file was not set' do subject.file = nil - subject.instance.should be_nil + expect(subject.instance).to be_nil end it 'doesn\'t create a logger if the level was not set' do subject.level = nil - subject.instance.should be_nil + expect(subject.instance).to be_nil end it 'gets a new instance of the logger when file and level are set' do - subject.file.should_not be_nil - subject.level.should_not be_nil - subject.instance.should_not be_nil + expect(subject.file).to_not be_nil + expect(subject.level).to_not be_nil + expect(subject.instance).to_not be_nil end it 'keeps the same object from multiple calls to instance' do - subject.instance === subject.instance + expect(subject.instance).to equal(subject.instance) end end @@ -43,13 +43,13 @@ describe '.configure' do before(:each) { subject.reset_device! } it 'sets the file and level in one call' do - subject.file.should_not be - subject.level.should_not be - subject.instance.should_not be + expect(subject.file).to_not be + expect(subject.level).to_not be + expect(subject.instance).to_not be subject.configure :file => 'myfile.log', :level => ::Logger::WARN - subject.file.should == 'myfile.log' - subject.level.should == ::Logger::WARN - subject.instance.level.should == ::Logger::WARN + expect(subject.file).to eq('myfile.log') + expect(subject.level).to eq(::Logger::WARN) + expect(subject.instance.level).to eq(::Logger::WARN) end end @@ -57,13 +57,13 @@ describe '.reset_device!' do it 'resets the logger instance, file, and level' do - subject.instance.should be - subject.file.should be - subject.level.should be + expect(subject.instance).to be + expect(subject.file).to be + expect(subject.level).to be subject.reset_device! - subject.instance.should_not be - subject.file.should_not be - subject.level.should_not be + expect(subject.instance).to_not be + expect(subject.file).to_not be + expect(subject.level).to_not be end end @@ -72,7 +72,7 @@ it 'doesn\'t raise errors when log instance is nil' do subject.reset_device! - subject.instance.should be_nil + expect(subject.instance).to be_nil expect { subject.debug 'No errors here' subject.info 'No errors here' @@ -85,8 +85,8 @@ end it 'logs correctly when instance is valid' do - subject.instance.should_not be_nil - subject.instance.should_receive(:info).with('Should log great') + expect(subject.instance).to_not be_nil + expect(subject.instance).to receive(:info).with('Should log great') subject.info 'Should log great' end @@ -114,20 +114,20 @@ class MyTestClass context '#log_exception' do it 'logs the exception message as an error and backtrace as debug' do - subject.should_receive(:log_error).twice - subject.should_receive(:log_debug) + expect(subject).to receive(:log_error).twice + expect(subject).to receive(:log_debug) subject.log_exception(RuntimeError.new('this is an exception')) end end - its(:log_signature) { should eq "[MyTestClass]" } + specify { expect(subject.log_signature).to eq "[MyTestClass]" } describe '#sign_message' do - specify { subject.sign_message("this is a test").should eq "[MyTestClass] this is a test" } - specify { subject.class.sign_message("this is a test").should eq "[MyTestClass] this is a test" } + specify { expect(subject.sign_message("this is a test")).to eq "[MyTestClass] this is a test" } + specify { expect(subject.class.sign_message("this is a test")).to eq "[MyTestClass] this is a test" } end it 'passes all embedded log calls to Logger instance' do - Protobuf::Logger.instance.should_receive(:debug).with('[MyTestClass] log this') + expect(Protobuf::Logger.instance).to receive(:debug).with('[MyTestClass] log this') subject.log_debug('log this') end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index b9f4b2f8..67e173bf 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -6,7 +6,7 @@ let(:message) { ::Test::Resource.new(:name => "Jim") } it 'creates a new message object decoded from the given bytes' do - ::Test::Resource.decode(message.encode).should eq message + expect(::Test::Resource.decode(message.encode)).to eq message end end @@ -62,41 +62,41 @@ let(:values) { { :name => "Jim" } } it 'creates a new message object with the given values and returns the encoded bytes' do - ::Test::Resource.encode(values).should eq ::Test::Resource.new(values).encode + expect(::Test::Resource.encode(values)).to eq ::Test::Resource.new(values).encode end end describe '#initialize' do it "initializes the enum getter to 0" do test_enum = Test::EnumTestMessage.new - test_enum.non_default_enum.should eq(0) + expect(test_enum.non_default_enum).to eq(0) end it "exposes the enum getter raw value through ! method" do test_enum = Test::EnumTestMessage.new - test_enum.non_default_enum!.should be_nil + expect(test_enum.non_default_enum!).to be_nil end it "exposes the enum getter raw value through ! method (when set)" do test_enum = Test::EnumTestMessage.new test_enum.non_default_enum = 1 - test_enum.non_default_enum!.should eq(1) + expect(test_enum.non_default_enum!).to eq(1) end it "does not try to set attributes which have nil values" do - Test::EnumTestMessage.any_instance.should_not_receive("non_default_enum=") + expect_any_instance_of(Test::EnumTestMessage).not_to receive("non_default_enum=") Test::EnumTestMessage.new(:non_default_enum => nil) end it "takes a hash as an initialization argument" do test_enum = Test::EnumTestMessage.new(:non_default_enum => 2) - test_enum.non_default_enum.should eq(2) + expect(test_enum.non_default_enum).to eq(2) end it "initializes with an object that responds to #to_hash" do hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) test_enum = Test::EnumTestMessage.new(hashie_object) - test_enum.non_default_enum.should eq(2) + expect(test_enum.non_default_enum).to eq(2) end end @@ -114,7 +114,7 @@ message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) - (new_message.name == name).should be_true + expect(new_message.name == name).to be_truthy end it "trims binary when binary is input for string fields" do @@ -123,7 +123,7 @@ message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) - (new_message.name == "my name").should be_true + expect(new_message.name == "my name").to be_truthy end end @@ -149,19 +149,19 @@ it "sets the value to nil when empty array is passed" do message.repeated_enum = [] - message.instance_variable_get("@values")[:repeated_enum].should be_nil + expect(message.instance_variable_get("@values")[:repeated_enum]).to be_nil end it "does not compact the edit original array" do a = [nil].freeze message.repeated_enum = a - message.repeated_enum.should eq([]) - a.should eq([nil].freeze) + expect(message.repeated_enum).to eq([]) + expect(a).to eq([nil].freeze) end it "compacts the set array" do message.repeated_enum = [nil] - message.repeated_enum.should eq([]) + expect(message.repeated_enum).to eq([]) end it "raises TypeError when a non-array replaces it" do @@ -179,16 +179,16 @@ it "sets the predicate to true when the boolean value is true" do subject.active = true - subject.active?.should be_true + expect(subject.active?).to be_truthy end it "sets the predicate to false when the boolean value is false" do subject.active = false - subject.active?.should be_false + expect(subject.active?).to be_falsey end it "does not put predicate methods on non-boolean fields" do - Test::ResourceFindRequest.new(:name => "resource").should_not respond_to(:name?) + expect(Test::ResourceFindRequest.new(:name => "resource")).to_not respond_to(:name?) end end @@ -196,11 +196,11 @@ subject { Test::EnumTestMessage.new(:non_default_enum => 2) } it "is false when the message does not have the field" do - subject.respond_to_and_has?(:other_field).should be_false + expect(subject.respond_to_and_has?(:other_field)).to be_falsey end it "is true when the message has the field" do - subject.respond_to_and_has?(:non_default_enum).should be_true + expect(subject.respond_to_and_has?(:non_default_enum)).to be_truthy end end @@ -208,38 +208,38 @@ subject { Test::EnumTestMessage.new(:non_default_enum => 2) } it "is false when the message does not have the field" do - subject.respond_to_and_has_and_present?(:other_field).should be_false + expect(subject.respond_to_and_has_and_present?(:other_field)).to be_falsey end it "is false when the field is repeated and a value is not present" do - subject.respond_to_and_has_and_present?(:repeated_enums).should be_false + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_falsey end it "is false when the field is repeated and the value is empty array" do subject.repeated_enums = [] - subject.respond_to_and_has_and_present?(:repeated_enums).should be_false + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_falsey end it "is true when the field is repeated and a value is present" do subject.repeated_enums = [2] - subject.respond_to_and_has_and_present?(:repeated_enums).should be_true + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_truthy end it "is true when the message has the field" do - subject.respond_to_and_has_and_present?(:non_default_enum).should be_true + expect(subject.respond_to_and_has_and_present?(:non_default_enum)).to be_truthy end context "#API" do subject { Test::EnumTestMessage.new(:non_default_enum => 2) } - it { should respond_to(:respond_to_and_has_and_present?) } - it { should respond_to(:responds_to_and_has_and_present?) } - it { should respond_to(:responds_to_has?) } - it { should respond_to(:respond_to_has?) } - it { should respond_to(:respond_to_has_present?) } - it { should respond_to(:responds_to_has_present?) } - it { should respond_to(:respond_to_and_has_present?) } - it { should respond_to(:responds_to_and_has_present?) } + specify { expect(subject).to respond_to(:respond_to_and_has_and_present?) } + specify { expect(subject).to respond_to(:responds_to_and_has_and_present?) } + specify { expect(subject).to respond_to(:responds_to_has?) } + specify { expect(subject).to respond_to(:respond_to_has?) } + specify { expect(subject).to respond_to(:respond_to_has_present?) } + specify { expect(subject).to respond_to(:responds_to_has_present?) } + specify { expect(subject).to respond_to(:respond_to_and_has_present?) } + specify { expect(subject).to respond_to(:responds_to_and_has_present?) } end end @@ -248,24 +248,24 @@ context 'generating values for an ENUM field' do it 'converts the enum to its tag representation' do hash = Test::EnumTestMessage.new(:non_default_enum => :TWO).to_hash - hash.should eq({ :non_default_enum => 2 }) + expect(hash).to eq({ :non_default_enum => 2 }) end it 'does not populate default values' do hash = Test::EnumTestMessage.new.to_hash - hash.should eq(Hash.new) + expect(hash).to eq(Hash.new) end it 'converts repeated enum fields to an array of the tags' do hash = Test::EnumTestMessage.new(:repeated_enums => [ :ONE, :TWO, :TWO, :ONE ]).to_hash - hash.should eq({ :repeated_enums => [ 1, 2, 2, 1 ] }) + expect(hash).to eq({ :repeated_enums => [ 1, 2, 2, 1 ] }) end end context 'generating values for a Message field' do it 'recursively hashes field messages' do hash = Test::Nested.new({ :resource => { :name => 'Nested' } }).to_hash - hash.should eq({ :resource => { :name => 'Nested' } }) + expect(hash).to eq({ :resource => { :name => 'Nested' } }) end it 'recursively hashes a repeated set of messages' do @@ -274,7 +274,7 @@ Test::Resource.new(:name => 'Resource 2') ]) - proto.to_hash.should eq({ :multiple_resources => [ { :name => 'Resource 1' }, + expect(proto.to_hash).to eq({ :multiple_resources => [ { :name => 'Resource 1' }, { :name => 'Resource 2' } ] }) end @@ -286,7 +286,7 @@ ::Test::ResourceFindRequest.new({ :name => 'Test Name', :active => false }) end - its(:to_json) { should eq '{"name":"Test Name","active":false}' } + specify { expect(subject.to_json).to eq '{"name":"Test Name","active":false}' } end describe '.to_json' do @@ -330,8 +330,8 @@ end it 'returns nil when field is not found' do - ::Test::Resource.get_extension_field(-1).should be_nil - ::Test::Resource.get_extension_field(nil).should be_nil + expect(::Test::Resource.get_extension_field(-1)).to be_nil + expect(::Test::Resource.get_extension_field(nil)).to be_nil end end @@ -360,8 +360,8 @@ end it 'returns nil when field is not defined' do - ::Test::Resource.get_field(-1).should be_nil - ::Test::Resource.get_field(nil).should be_nil + expect(::Test::Resource.get_field(-1)).to be_nil + expect(::Test::Resource.get_field(nil)).to be_nil end end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 6de32c34..f65eca6c 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -20,7 +20,7 @@ it 'defaults the value to true' do OptionableSetOptionTest.set_option(:baz_enabled) - expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be_true + expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be_truthy end end diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index 6046386a..14b8ba34 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -10,29 +10,29 @@ before { reset_service_location(Test::ResourceService) } it 'should be able to get a client through the Service#client helper method' do - Test::ResourceService.client(:port => 9191).should eq(Protobuf::Rpc::Client.new(:service => Test::ResourceService, :port => 9191)) + expect(::Test::ResourceService.client(:port => 9191)).to eq(Protobuf::Rpc::Client.new(:service => Test::ResourceService, :port => 9191)) end it "should be able to override a service location's host and port" do Test::ResourceService.located_at 'somewheregreat.com:12345' clean_client = Test::ResourceService.client - clean_client.options[:host].should eq('somewheregreat.com') - clean_client.options[:port].should eq(12345) + expect(clean_client.options[:host]).to eq('somewheregreat.com') + expect(clean_client.options[:port]).to eq(12345) updated_client = Test::ResourceService.client(:host => 'amazing.com', :port => 54321) - updated_client.options[:host].should eq('amazing.com') - updated_client.options[:port].should eq(54321) + expect(updated_client.options[:host]).to eq('amazing.com') + expect(updated_client.options[:port]).to eq(54321) end it 'should be able to define which service to create itself for' do client = Protobuf::Rpc::Client.new :service => Test::ResourceService - client.options[:service].should eq(Test::ResourceService) + expect(client.options[:service]).to eq(Test::ResourceService) end it 'should have a hard default for host and port on a service that has not been configured' do client = Test::ResourceService.client - client.options[:host].should eq(Protobuf::Rpc::Service::DEFAULT_HOST) - client.options[:port].should eq(Protobuf::Rpc::Service::DEFAULT_PORT) + expect(client.options[:host]).to eq(Protobuf::Rpc::Service::DEFAULT_HOST) + expect(client.options[:port]).to eq(Protobuf::Rpc::Service::DEFAULT_PORT) end end @@ -45,7 +45,7 @@ it 'should respond to defined service methods' do client = Test::ResourceService.client - client.should_receive(:send_request).and_return(nil) + expect(client).to receive(:send_request).and_return(nil) expect { client.find(nil) }.to_not raise_error end end @@ -54,11 +54,11 @@ it 'should be able to create the correct request object if passed a hash' do client = Test::ResourceService.client - client.should_receive(:send_request) + expect(client).to receive(:send_request) client.find({:name => 'Test Name', :active => false}) - client.options[:request].should be_a(Test::ResourceFindRequest) - client.options[:request].name.should eq('Test Name') - client.options[:request].active.should eq(false) + expect(client.options[:request]).to be_a(Test::ResourceFindRequest) + expect(client.options[:request].name).to eq('Test Name') + expect(client.options[:request].active).to eq(false) end end diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb index 92637452..4092ce0f 100644 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -9,17 +9,17 @@ context 'Protobuf.connector_type is socket' do before { ::Protobuf.connector_type = :socket } - it { should eq ::Protobuf::Rpc::Connectors::Socket } + specify { expect(subject).to eq ::Protobuf::Rpc::Connectors::Socket } end context 'Protobuf.connector_type is not a known value' do - before { ::Protobuf.stub(:connector_type) { :foo } } - it { should eq ::Protobuf::Rpc::Connectors::Socket } + before { allow(::Protobuf).to receive(:connector_type).and_return(:foo) } + specify { expect(subject).to eq(::Protobuf::Rpc::Connectors::Socket) } end context 'Protobuf.connector_type is zmq' do before { ::Protobuf.connector_type = :zmq } - it { should eq ::Protobuf::Rpc::Connectors::Zmq } + specify { expect(subject).to eq(::Protobuf::Rpc::Connectors::Zmq) } end end diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 5dae92f6..fad03f4f 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -21,28 +21,28 @@ describe '.new' do it 'assigns passed options and initializes success/failure callbacks' do - subject.options.should eq(Protobuf::Rpc::Connectors::DEFAULT_OPTIONS.merge(options)) - subject.success_cb.should be_nil - subject.failure_cb.should be_nil + expect(subject.options).to eq(Protobuf::Rpc::Connectors::DEFAULT_OPTIONS.merge(options)) + expect(subject.success_cb).to be_nil + expect(subject.failure_cb).to be_nil end end describe '#success_cb' do it 'allows setting the success callback and calling it' do - subject.success_cb.should be_nil + expect(subject.success_cb).to be_nil cb = proc {|res| raise res } subject.success_cb = cb - subject.success_cb.should eq(cb) + expect(subject.success_cb).to eq(cb) expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb' end end describe '#failure_cb' do it 'allows setting the failure callback and calling it' do - subject.failure_cb.should be_nil + expect(subject.failure_cb).to be_nil cb = proc {|res| raise res } subject.failure_cb = cb - subject.failure_cb.should eq(cb) + expect(subject.failure_cb).to eq(cb) expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb' end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 9d75ce03..8f814a7f 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -15,15 +15,15 @@ subject { @subject ||= common_class.new(subject_options) } context "API" do - specify { subject.respond_to?(:any_callbacks?).should be_true } - specify { subject.respond_to?(:request_caller).should be_true } - specify { subject.respond_to?(:data_callback).should be_true } - specify { subject.respond_to?(:error).should be_true } - specify { subject.respond_to?(:fail).should be_true } - specify { subject.respond_to?(:complete).should be_true } - specify { subject.respond_to?(:parse_response).should be_true } - specify { subject.respond_to?(:verify_options!).should be_true } - specify { subject.respond_to?(:verify_callbacks).should be_true } + specify { expect(subject.respond_to?(:any_callbacks?)).to be_truthy } + specify { expect(subject.respond_to?(:request_caller)).to be_truthy } + specify { expect(subject.respond_to?(:data_callback)).to be_truthy } + specify { expect(subject.respond_to?(:error)).to be_truthy } + specify { expect(subject.respond_to?(:fail)).to be_truthy } + specify { expect(subject.respond_to?(:complete)).to be_truthy } + specify { expect(subject.respond_to?(:parse_response)).to be_truthy } + specify { expect(subject.respond_to?(:verify_options!)).to be_truthy } + specify { expect(subject.respond_to?(:verify_callbacks)).to be_truthy } end describe "#any_callbacks?" do @@ -31,7 +31,7 @@ [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| it "returns true if #{cb} is provided" do subject.instance_variable_set(cb, "something") - subject.any_callbacks?.should be_true + expect(subject.any_callbacks?).to be_truthy end end @@ -40,32 +40,32 @@ subject.instance_variable_set(:@success_cb, nil) subject.instance_variable_set(:@failure_cb, nil) - subject.any_callbacks?.should be_false + expect(subject.any_callbacks?).to be_falsey end end describe '#request_caller' do - its(:request_caller) { should eq ::Protobuf.client_host } + specify { expect(subject.request_caller).to eq ::Protobuf.client_host } context 'when "client_host" option is given to initializer' do let(:hostname) { 'myhost.myserver.com' } let(:subject_options) { { :client_host => hostname } } - its(:request_caller) { should_not eq ::Protobuf.client_host } - its(:request_caller) { should eq hostname } + specify { expect(subject.request_caller).to_not eq ::Protobuf.client_host } + specify { expect(subject.request_caller).to eq hostname } end end describe "#data_callback" do it "changes state to use the data callback" do subject.data_callback("data") - subject.instance_variable_get(:@used_data_callback).should be_true + expect(subject.instance_variable_get(:@used_data_callback)).to be_truthy end it "sets the data var when using the data_callback" do subject.data_callback("data") - subject.instance_variable_get(:@data).should eq("data") + expect(subject.instance_variable_get(:@data)).to eq("data") end end @@ -84,38 +84,38 @@ :request_proto => '', :caller => client_host }) } - before { subject.stub(:validate_request_type!).and_return(true) } - before { subject.should_not_receive(:fail) } + before { allow(subject).to receive(:validate_request_type!).and_return(true) } + before { expect(subject).not_to receive(:fail) } - its(:request_bytes) { should eq expected.encode } + specify { expect(subject.request_bytes).to eq expected.encode } end describe "#verify_callbacks" do it "sets @failure_cb to #data_callback when no callbacks are defined" do subject.verify_callbacks - subject.instance_variable_get(:@failure_cb).should eq(subject.method(:data_callback)) + expect(subject.instance_variable_get(:@failure_cb)).to eq(subject.method(:data_callback)) end it "sets @success_cb to #data_callback when no callbacks are defined" do subject.verify_callbacks - subject.instance_variable_get(:@success_cb).should eq(subject.method(:data_callback)) + expect(subject.instance_variable_get(:@success_cb)).to eq(subject.method(:data_callback)) end it "doesn't set @failure_cb when already defined" do set_cb = lambda{ true } subject.instance_variable_set(:@failure_cb, set_cb) subject.verify_callbacks - subject.instance_variable_get(:@failure_cb).should eq(set_cb) - subject.instance_variable_get(:@failure_cb).should_not eq(subject.method(:data_callback)) + expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb) + expect(subject.instance_variable_get(:@failure_cb)).to_not eq(subject.method(:data_callback)) end it "doesn't set @success_cb when already defined" do set_cb = lambda{ true } subject.instance_variable_set(:@success_cb, set_cb) subject.verify_callbacks - subject.instance_variable_get(:@success_cb).should eq(set_cb) - subject.instance_variable_get(:@success_cb).should_not eq(subject.method(:data_callback)) + expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb) + expect(subject.instance_variable_get(:@success_cb)).to_not eq(subject.method(:data_callback)) end end @@ -123,33 +123,31 @@ shared_examples "a ConnectorDisposition" do |meth, cb, *args| it "calls #complete before exit" do - stats = double("Object") - stats.stub(:stop) { true } - subject.stats = stats + subject.stats = double("Object", :stop => true) - subject.should_receive(:complete) + expect(subject).to receive(:complete) subject.method(meth).call(*args) end it "calls the #{cb} callback when provided" do stats = double("Object") - stats.stub(:stop) { true } + allow(stats).to receive(:stop).and_return(true) subject.stats = stats _cb = double("Object") subject.instance_variable_set("@#{cb}", _cb) - _cb.should_receive(:call).and_return(true) + expect(_cb).to receive(:call).and_return(true) subject.method(meth).call(*args) end it "calls the complete callback when provided" do stats = double("Object") - stats.stub(:stop) { true } + allow(stats).to receive(:stop).and_return(true) subject.stats = stats comp_cb = double("Object") subject.instance_variable_set(:@complete_cb, comp_cb) - comp_cb.should_receive(:call).and_return(true) + expect(comp_cb).to receive(:call).and_return(true) subject.method(meth).call(*args) end diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index 131d274a..ff18c2ee 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -6,10 +6,10 @@ context "API" do # Check the API - specify{ subject.respond_to?(:send_request, true).should be_true } - specify{ subject.respond_to?(:post_init, true).should be_true } - specify{ subject.respond_to?(:close_connection, true).should be_true } - specify{ subject.respond_to?(:error?, true).should be_true } + specify { expect(subject.respond_to?(:send_request, true)).to be_truthy } + specify { expect(subject.respond_to?(:post_init, true)).to be_truthy } + specify { expect(subject.respond_to?(:close_connection, true)).to be_truthy } + specify { expect(subject.respond_to?(:error?, true)).to be_truthy } end end @@ -18,19 +18,19 @@ it_behaves_like "a Protobuf Connector" - specify{ described_class.include?(Protobuf::Rpc::Connectors::Common).should be_true } + specify { expect(described_class.include?(Protobuf::Rpc::Connectors::Common)).to be_truthy } context "#read_response" do - let(:data){ "New data" } + let(:data) { "New data" } it "fills the buffer with data from the socket" do socket = StringIO.new("#{data.bytesize}-#{data}") subject.instance_variable_set(:@socket, socket) subject.instance_variable_set(:@stats, OpenStruct.new) - subject.should_receive(:parse_response).and_return(true) + expect(subject).to receive(:parse_response).and_return(true) subject.__send__(:read_response) - subject.instance_variable_get(:@response_data).should eq(data) + expect(subject.instance_variable_get(:@response_data)).to eq(data) end end end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index cff17ca1..707033c8 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -12,20 +12,11 @@ :port => "9400" }} - let(:socket_double) do - sm = double(::ZMQ::Socket) - sm.stub(:connect).and_return(0) - sm - end - - let(:zmq_context_double) do - zc = double(::ZMQ::Context) - zc.stub(:socket).and_return(socket_double) - zc - end + let(:socket_double) { double(::ZMQ::Socket, :connect => 0) } + let(:zmq_context_double) { double(::ZMQ::Context, :socket => socket_double) } before do - ::ZMQ::Context.stub(:new).and_return(zmq_context_double) + allow(::ZMQ::Context).to receive(:new).and_return(zmq_context_double) end before(:all) do @@ -42,19 +33,17 @@ let(:listings) { [listing] } let(:running?) { true } - before do - subject.stub(:service_directory) { service_directory } - end + before { allow(subject).to receive(:service_directory).and_return(service_directory) } context "when the service directory is running" do it "searches the service directory" do - service_directory.stub(:all_listings_for).and_return(listings) - subject.send(:lookup_server_uri).should eq "tcp://127.0.0.2:9399" + allow(service_directory).to receive(:all_listings_for).and_return(listings) + expect(subject.send(:lookup_server_uri)).to eq "tcp://127.0.0.2:9399" end it "defaults to the options" do - service_directory.stub(:all_listings_for).and_return([]) - subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" + allow(service_directory).to receive(:all_listings_for).and_return([]) + expect(subject.send(:lookup_server_uri)).to eq "tcp://127.0.0.1:9400" end end @@ -62,21 +51,21 @@ let(:running?) { false } it "defaults to the options" do - service_directory.stub(:all_listings_for).and_return([]) - subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" + allow(service_directory).to receive(:all_listings_for).and_return([]) + expect(subject.send(:lookup_server_uri)).to eq "tcp://127.0.0.1:9400" end end it "checks if the server is alive" do - service_directory.stub(:all_listings_for).and_return([]) - subject.should_receive(:host_alive?).with("127.0.0.1") { true } - subject.send(:lookup_server_uri).should eq "tcp://127.0.0.1:9400" + allow(service_directory).to receive(:all_listings_for).and_return([]) + expect(subject).to receive(:host_alive?).with("127.0.0.1") { true } + expect(subject.send(:lookup_server_uri)).to eq "tcp://127.0.0.1:9400" end context "when no host is alive" do it "raises an error" do - service_directory.stub(:all_listings_for).and_return(listings) - subject.stub(:host_alive?).and_return(false) + allow(service_directory).to receive(:all_listings_for).and_return(listings) + allow(subject).to receive(:host_alive?).and_return(false) expect { subject.send(:lookup_server_uri) }.to raise_error end end @@ -90,11 +79,11 @@ end it "returns true" do - subject.send(:host_alive?, "yip.yip").should be_true + expect(subject.send(:host_alive?, "yip.yip")).to be_truthy end it "does not attempt a connection" do - TCPSocket.should_not_receive(:new) + expect(TCPSocket).not_to receive(:new) subject.send(:host_alive?, "blargh.com") end end @@ -105,20 +94,20 @@ end it "returns true when the connection succeeds" do - TCPSocket.should_receive(:new).with("huzzah.com", 3307) { double(:close => nil) } - subject.send(:host_alive?, "huzzah.com").should be_true + expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil)) + expect(subject.send(:host_alive?, "huzzah.com")).to be_truthy end it "returns false when the connection fails" do - TCPSocket.should_receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) - subject.send(:host_alive?, "hayoob.com").should be_false + expect(TCPSocket).to receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) + expect(subject.send(:host_alive?, "hayoob.com")).to be_falsey end it "closes the socket" do socket = double("TCPSocket") - socket.should_receive(:close) - TCPSocket.should_receive(:new).with("absorbalof.com", 3307) { socket } - subject.send(:host_alive?, "absorbalof.com").should be_true + expect(socket).to receive(:close) + expect(TCPSocket).to receive(:new).with("absorbalof.com", 3307).and_return(socket) + expect(subject.send(:host_alive?, "absorbalof.com")).to be_truthy end end end diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index 532164d6..e7d3a79f 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -8,19 +8,19 @@ describe "#call" do it "calls the stack" do - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end it "returns the env" do - subject.call(env).should eq env + expect(subject.call(env)).to eq env end context "when exceptions occur" do let(:encoded_error) { error.encode } let(:error) { Protobuf::Rpc::MethodNotFound.new('Boom!') } - before { app.stub(:call).and_raise(error, 'Boom!') } + before { allow(app).to receive(:call).and_raise(error, 'Boom!') } it "rescues exceptions" do expect { subject.call(env) }.not_to raise_exception @@ -32,12 +32,12 @@ # Can't compare the error instances because the response has been # raised and thus has a backtrace while the error does not. - stack_env.response.class.should eq error.class + expect(stack_env.response.class).to eq error.class end it "encodes the response" do stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_error + expect(stack_env.encoded_response).to eq encoded_error end end @@ -45,16 +45,16 @@ let(:encoded_error) { error.encode } let(:error) { Protobuf::Rpc::RpcFailed.new('Boom!') } - before { app.stub(:call).and_raise(RuntimeError, 'Boom!') } + before { allow(app).to receive(:call).and_raise(RuntimeError, 'Boom!') } it "wraps the exception in a generic Protobuf error" do stack_env = subject.call(env) - stack_env.response.should eq error + expect(stack_env.response).to eq error end it "encodes the wrapped exception" do stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_error + expect(stack_env.encoded_response).to eq encoded_error end end end diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index 8220d416..fa938aa1 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -38,12 +38,12 @@ describe "#call" do it "calls the stack" do - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env).and_return(env) subject.call(env) end it "returns the env" do - subject.call(env).should eq env + expect(subject.call(env)).to eq env end end end diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 0572ace2..ae33afe8 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -31,51 +31,51 @@ describe "#call" do it "decodes the request" do stack_env = subject.call(env) - stack_env.request.should eq request + expect(stack_env.request).to eq request end it "calls the stack" do - app.should_receive(:call).with(env) + expect(app).to receive(:call).with(env) subject.call(env) end it "sets Env#client_host" do stack_env = subject.call(env) - stack_env.client_host.should eq client_host + expect(stack_env.client_host).to eq client_host end it "sets Env#service_name" do stack_env = subject.call(env) - stack_env.service_name.should eq service_name + expect(stack_env.service_name).to eq service_name end it "sets Env#method_name" do stack_env = subject.call(env) - stack_env.method_name.should eq method_name.to_sym + expect(stack_env.method_name).to eq method_name.to_sym end it "sets Env#request_type" do stack_env = subject.call(env) - stack_env.request_type.should eq request_type + expect(stack_env.request_type).to eq request_type end it "sets Env#response_type" do stack_env = subject.call(env) - stack_env.response_type.should eq response_type + expect(stack_env.response_type).to eq response_type end it "sets Env#rpc_method" do stack_env = subject.call(env) - stack_env.rpc_method.should eq rpc_method + expect(stack_env.rpc_method).to eq rpc_method end it "sets Env#rpc_service" do stack_env = subject.call(env) - stack_env.rpc_service.should eq rpc_service + expect(stack_env.rpc_service).to eq rpc_service end context "when decoding fails" do - before { Protobuf::Socketrpc::Request.stub(:decode).and_raise(RuntimeError) } + before { allow(Protobuf::Socketrpc::Request).to receive(:decode).and_raise(RuntimeError) } it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::BadRequestData) diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index dd58d7ba..9b9bb429 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -17,12 +17,12 @@ describe "#call" do it "encodes the response" do stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_response + expect(stack_env.encoded_response).to eq encoded_response end it "calls the stack" do stack_env = subject.call(env) - stack_env.response.should eq response + expect(stack_env.response).to eq response end context "when response is responds to :to_hash" do @@ -31,7 +31,7 @@ it "sets Env#response" do stack_env = subject.call(env) - stack_env.response.should eq response + expect(stack_env.response).to eq response end end @@ -41,7 +41,7 @@ it "sets Env#response" do stack_env = subject.call(env) - stack_env.response.should eq response + expect(stack_env.response).to eq response end end @@ -60,12 +60,12 @@ it "wraps and encodes the response" do stack_env = subject.call(env) - stack_env.encoded_response.should eq encoded_response + expect(stack_env.encoded_response).to eq encoded_response end end context "when encoding fails" do - before { Protobuf::Socketrpc::Response.any_instance.stub(:encode).and_raise(RuntimeError) } + before { allow_any_instance_of(Protobuf::Socketrpc::Response).to receive(:encode).and_raise(RuntimeError) } it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::PbError) diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 5257291b..6497641c 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -24,15 +24,15 @@ end it "Runner provides a stop method" do - @runner.should respond_to(:stop) + expect(@runner).to respond_to(:stop) end it "provides a stop method" do - @server.should respond_to(:stop) + expect(@server).to respond_to(:stop) end it "signals the Server is running" do - @server.should be_running + expect(@server).to be_running end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 17d6aaf9..9a8df8ce 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -22,12 +22,12 @@ describe '.running?' do it 'returns true if running' do subject.instance_variable_set(:@running, true) - subject.running?.should be_true + expect(subject.running?).to be_truthy end it 'returns false if not running' do subject.instance_variable_set(:@running, false) - subject.running?.should be_false + expect(subject.running?).to be_falsey end end @@ -35,7 +35,7 @@ it 'sets running to false' do subject.instance_variable_set(:@workers, []) subject.stop - subject.instance_variable_get(:@running).should be_false + expect(subject.instance_variable_get(:@running)).to be_falsey end end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index 7412d0d6..523297f8 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -18,7 +18,7 @@ class UtilTest end it 'retrieves the error string from ZeroMQ' do - ZMQ::Util.stub(:error_string).and_return('an error from zmq') + allow(ZMQ::Util).to receive(:error_string).and_return('an error from zmq') expect { subject.zmq_error_check(-1, :test) }.to raise_error(RuntimeError, /an error from zmq/i) @@ -39,7 +39,7 @@ class UtilTest describe '#log_signature' do it 'returns the signature for the log' do - subject.log_signature.should include('server', 'UtilTest') + expect(subject.log_signature).to include('server', 'UtilTest') end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index ada0adfc..1da51f5e 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -1,16 +1,16 @@ require 'spec_helper' describe ::Protobuf::Rpc::Zmq::Worker do - before(:each) do + before(:each) do load 'protobuf/zmq.rb' fake_socket = double - fake_socket.should_receive(:connect).and_return(0) - fake_socket.should_receive(:send_string).and_return(0) + expect(fake_socket).to receive(:connect).and_return(0) + expect(fake_socket).to receive(:send_string).and_return(0) fake_context = double - fake_context.should_receive(:socket).and_return( fake_socket ) - ::ZMQ::Context.should_receive(:new).and_return( fake_context ) + expect(fake_context).to receive(:socket).and_return(fake_socket) + expect(::ZMQ::Context).to receive(:new).and_return(fake_context) end subject do diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index c7bae230..350f9f74 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -56,10 +56,9 @@ end def expect_event_trigger(event) - ::ActiveSupport::Notifications - .should_receive(:instrument) - .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))) - .once + expect(::ActiveSupport::Notifications).to receive(:instrument) + .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))) + .once end def send_beacon(type, server) @@ -74,29 +73,29 @@ def send_beacon(type, server) end it "should be a singleton" do - subject.should be_a_kind_of(Singleton) + expect(subject).to be_a_kind_of(Singleton) end it "should be configured to listen to address 127.0.0.1" do - described_class.address.should eq '127.0.0.1' + expect(described_class.address).to eq '127.0.0.1' end it "should be configured to listen to port 33333" do - described_class.port.should eq 33333 + expect(described_class.port).to eq 33333 end it "should defer .start to the instance#start" do - described_class.instance.should_receive(:start) + expect(described_class.instance).to receive(:start) described_class.start end it "should yeild itself to blocks passed to .start" do - described_class.instance.stub(:start) + allow(described_class.instance).to receive(:start) expect { |b| described_class.start(&b) }.to yield_with_args(described_class) end it "should defer .stop to the instance#stop" do - described_class.instance.should_receive(:stop) + expect(described_class.instance).to receive(:stop) described_class.stop end @@ -106,20 +105,20 @@ def send_beacon(type, server) describe "#lookup" do it "should return nil" do send_beacon(:heartbeat, echo_server) - subject.lookup("EchoService").should be_nil + expect(subject.lookup("EchoService")).to be_nil end end describe "#restart" do it "should start the service" do subject.restart - subject.should be_running + expect(subject).to be_running end end describe "#running" do it "should be false" do - subject.should_not be_running + expect(subject).to_not be_running end end @@ -134,7 +133,7 @@ def send_beacon(type, server) before { subject.start } after { subject.stop } - it { should be_running } + specify { expect(subject).to be_running } it "should trigger added events" do expect_event_trigger("directory.listing.added") @@ -159,13 +158,13 @@ def send_beacon(type, server) send_beacon(:heartbeat, hello_server) send_beacon(:heartbeat, combo_server) - subject.all_listings_for("HelloService").size.should eq(2) + expect(subject.all_listings_for("HelloService").size).to eq(2) end end context "when no listings are present" do it "returns and empty array" do - subject.all_listings_for("HelloService").size.should eq(0) + expect(subject.all_listings_for("HelloService").size).to eq(0) end end end @@ -185,7 +184,7 @@ def send_beacon(type, server) describe "#lookup" do it "should provide listings by service" do send_beacon(:heartbeat, hello_server) - subject.lookup("HelloService").to_hash.should eq hello_server.to_hash + expect(subject.lookup("HelloService").to_hash).to eq hello_server.to_hash end it "should return random listings" do @@ -193,14 +192,14 @@ def send_beacon(type, server) send_beacon(:heartbeat, combo_server) uuids = 100.times.map { subject.lookup("HelloService").uuid } - uuids.count("hello").should be_within(25).of(50) - uuids.count("combo").should be_within(25).of(50) + expect(uuids.count("hello")).to be_within(25).of(50) + expect(uuids.count("combo")).to be_within(25).of(50) end it "should not return expired listings" do send_beacon(:heartbeat, hello_server_with_short_ttl) sleep 1 - subject.lookup("HelloService").should be_nil + expect(subject.lookup("HelloService")).to be_nil end it "should not return flatlined servers" do @@ -209,7 +208,7 @@ def send_beacon(type, server) send_beacon(:flatline, echo_server) uuids = 100.times.map { subject.lookup("EchoService").uuid } - uuids.count("combo").should eq 100 + expect(uuids.count("combo")).to eq 100 end it "should return up-to-date listings" do @@ -217,13 +216,13 @@ def send_beacon(type, server) echo_server.port = "7777" send_beacon(:heartbeat, echo_server) - subject.lookup("EchoService").port.should eq "7777" + expect(subject.lookup("EchoService").port).to eq "7777" end context 'when given service identifier is a class name' do it 'returns the listing corresponding to the class name' do send_beacon(:heartbeat, echo_server) - subject.lookup(EchoService).uuid.should eq echo_server.uuid + expect(subject.lookup(EchoService).uuid).to eq echo_server.uuid end end end @@ -233,13 +232,13 @@ def send_beacon(type, server) send_beacon(:heartbeat, echo_server) send_beacon(:heartbeat, combo_server) subject.restart - subject.lookup("EchoService").should be_nil + expect(subject.lookup("EchoService")).to be_nil end end describe "#running" do it "should be true" do - subject.should be_running + expect(subject).to be_running end end @@ -248,12 +247,12 @@ def send_beacon(type, server) send_beacon(:heartbeat, echo_server) send_beacon(:heartbeat, combo_server) subject.stop - subject.lookup("EchoService").should be_nil + expect(subject.lookup("EchoService")).to be_nil end it "should stop the server" do subject.stop - subject.should_not be_running + expect(subject).to_not be_running end end end diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 82616c82..1582b44c 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -23,14 +23,14 @@ subject { described_class.new(app) } - before { subject.stub(:rpc_service).and_return(rpc_service) } + before { allow(subject).to receive(:rpc_service).and_return(rpc_service) } describe '#call' do - before { rpc_service.stub(:response).and_return(response) } + before { allow(rpc_service).to receive(:response).and_return(response) } it "dispatches the request" do stack_env = subject.call(env) - stack_env.response.should eq response + expect(stack_env.response).to eq response end context "when the given RPC method is not implemented" do @@ -42,7 +42,7 @@ end context "when the given RPC method is implemented and a NoMethodError is raised" do - before { rpc_service.stub(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } + before { allow(rpc_service).to receive(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } it "raises the exeception" do expect { subject.call(env) }.to raise_exception(NoMethodError) diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index fd991822..14ce7ac7 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -55,13 +55,13 @@ def foo FilterTest.before_filter(:foo) end - specify { subject.class.should respond_to(:before_filter) } - specify { subject.class.should respond_to(:before_action) } + specify { expect(subject.class).to respond_to(:before_filter) } + specify { expect(subject.class).to respond_to(:before_action) } it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :foo, :endpoint ] - subject.before_filter_calls.should eq 1 + expect(subject.called).to eq [ :verify_before, :foo, :endpoint ] + expect(subject.before_filter_calls).to eq 1 end context 'when filter is configured with "only"' do @@ -82,14 +82,14 @@ def endpoint_with_verify context 'when invoking a method defined in "only" option' do it 'invokes the filter' do subject.__send__(:run_filters, :endpoint_with_verify) - subject.called.should eq [ :verify_before, :endpoint_with_verify ] + expect(subject.called).to eq [ :verify_before, :endpoint_with_verify ] end end context 'when invoking a method not defined by "only" option' do it 'does not invoke the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end end @@ -112,14 +112,14 @@ def endpoint_without_verify context 'when invoking a method not defined in "except" option' do it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end context 'when invoking a method defined by "except" option' do it 'does not invoke the filter' do subject.__send__(:run_filters, :endpoint_without_verify) - subject.called.should eq [ :endpoint_without_verify ] + expect(subject.called).to eq [ :endpoint_without_verify ] end end end @@ -142,7 +142,7 @@ def verify_before; @called << :verify_before; end it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end @@ -154,7 +154,7 @@ def verify_before; @called << :verify_before; end it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end @@ -166,7 +166,7 @@ def verify_before; @called << :verify_before; end it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end @@ -178,7 +178,7 @@ def verify_before; @called << :verify_before; end it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end end @@ -201,7 +201,7 @@ def verify_before; @called << :verify_before; end it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end @@ -213,7 +213,7 @@ def verify_before; @called << :verify_before; end it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [ :verify_before, :endpoint ] end end @@ -225,7 +225,7 @@ def verify_before; @called << :verify_before; end it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end @@ -237,7 +237,7 @@ def verify_before; @called << :verify_before; end it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint ] + expect(subject.called).to eq [ :endpoint ] end end end @@ -259,9 +259,9 @@ def short_circuit_filter end it 'does not invoke the rpc method' do - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :short_circuit_filter ] + expect(subject.called).to eq [ :short_circuit_filter ] end end end @@ -289,13 +289,13 @@ def foo FilterTest.after_filter(:foo) end - specify { subject.class.should respond_to(:after_filter) } - specify { subject.class.should respond_to(:after_action) } + specify { expect(subject.class).to respond_to(:after_filter) } + specify { expect(subject.class).to respond_to(:after_action) } it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq [ :endpoint, :verify_after, :foo ] - subject.after_filter_calls.should eq 1 + expect(subject.called).to eq [ :endpoint, :verify_after, :foo ] + expect(subject.after_filter_calls).to eq 1 end end @@ -326,12 +326,12 @@ def inner_around FilterTest.around_filter(:inner_around) end - specify { subject.class.should respond_to(:around_filter) } - specify { subject.class.should respond_to(:around_action) } + specify { expect(subject.class).to respond_to(:around_filter) } + specify { expect(subject.class).to respond_to(:around_action) } it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :outer_around_top, + expect(subject.called).to eq([ :outer_around_top, :inner_around_top, :endpoint, :inner_around_bottom, @@ -354,9 +354,9 @@ def inner_around end it 'cancels calling the rest of the filters and the endpoint' do - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :outer_around_top, + expect(subject.called).to eq([ :outer_around_top, :inner_around, :outer_around_bottom ]) end @@ -412,10 +412,10 @@ def custom_error_occurred(ex) it 'short-circuits the call stack' do expect { - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :filter_with_error3, :custom_error_occurred ]) - subject.ex_class.should eq CustomError3 + expect(subject.called).to eq([ :filter_with_error3, :custom_error_occurred ]) + expect(subject.ex_class).to eq CustomError3 }.not_to raise_error end end @@ -433,10 +433,10 @@ def custom_error_occurred(ex) it 'short-circuits the call stack' do expect { - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :filter_with_error1, :custom_error_occurred ]) - subject.ex_class.should eq CustomError1 + expect(subject.called).to eq([ :filter_with_error1, :custom_error_occurred ]) + expect(subject.ex_class).to eq CustomError1 }.not_to raise_error end end @@ -453,10 +453,10 @@ def custom_error_occurred(ex) it 'short-circuits the call stack' do expect { - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :filter_with_error1, :block_rescue_handler ]) - subject.ex_class.should eq CustomError1 + expect(subject.called).to eq([ :filter_with_error1, :block_rescue_handler ]) + expect(subject.ex_class).to eq CustomError1 }.not_to raise_error end end @@ -472,10 +472,10 @@ def custom_error_occurred(ex) it 'rescues with the given callable' do expect { - subject.should_not_receive(:endpoint) + expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - subject.called.should eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) - subject.ex_class.should eq RuntimeError + expect(subject.called).to eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) + expect(subject.ex_class).to eq RuntimeError }.not_to raise_error end end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 49b66a0e..1cef20be 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -11,73 +11,73 @@ end describe '.host' do - its(:host) { should eq described_class::DEFAULT_HOST } + specify { expect(subject.host).to eq described_class::DEFAULT_HOST } end describe '.host=' do before { subject.host = 'mynewhost.com' } - its(:host) { should eq 'mynewhost.com' } + specify { expect(subject.host).to eq 'mynewhost.com' } end describe '.port' do - its(:port) { should eq described_class::DEFAULT_PORT } + specify { expect(subject.port).to eq described_class::DEFAULT_PORT } end describe '.port=' do before { subject.port = 12345 } - its(:port) { should eq 12345 } + specify { expect(subject.port).to eq 12345 } end describe '.configure' do context 'when providing a host' do before { subject.configure(:host => 'mynewhost.com') } - its(:host) { should eq 'mynewhost.com' } + specify { expect(subject.host).to eq 'mynewhost.com' } end context 'when providing a port' do before { subject.configure(:port => 12345) } - its(:port) { should eq 12345 } + specify { expect(subject.port).to eq 12345 } end end describe '.located_at' do context 'when given location is empty' do before { subject.located_at(nil) } - its(:host) { should eq described_class::DEFAULT_HOST } - its(:port) { should eq described_class::DEFAULT_PORT } + specify { expect(subject.host).to eq described_class::DEFAULT_HOST } + specify { expect(subject.port).to eq described_class::DEFAULT_PORT } end context 'when given location is invalid' do before { subject.located_at('i like pie') } - its(:host) { should eq described_class::DEFAULT_HOST } - its(:port) { should eq described_class::DEFAULT_PORT } + specify { expect(subject.host).to eq described_class::DEFAULT_HOST } + specify { expect(subject.port).to eq described_class::DEFAULT_PORT } end context 'when given location contains a host and port' do before { subject.located_at('mynewdomain.com:12345') } - its(:host) { should eq 'mynewdomain.com' } - its(:port) { should eq 12345 } + specify { expect(subject.host).to eq 'mynewdomain.com' } + specify { expect(subject.port).to eq 12345 } end end describe '.client' do it 'initializes a client object for this service' do client = double('client') - ::Protobuf::Rpc::Client.should_receive(:new) - .with(hash_including({ :service => subject, - :host => subject.host, - :port => subject.port })) - .and_return(client) - subject.client.should eq client + expect(::Protobuf::Rpc::Client).to receive(:new) + .with(hash_including({ :service => subject, + :host => subject.host, + :port => subject.port })) + .and_return(client) + expect(subject.client).to eq client end end describe '.rpc' do before { Test::ResourceService.rpc(:update, Test::ResourceFindRequest, Test::Resource) } subject { Test::ResourceService.rpcs[:update] } - its(:method) { should eq :update } - its(:request_type) { should eq Test::ResourceFindRequest } - its(:response_type) { should eq Test::Resource } + specify { expect(subject.method).to eq :update } + specify { expect(subject.request_type).to eq Test::ResourceFindRequest } + specify { expect(subject.response_type).to eq Test::Resource } end describe '.rpc_method?' do @@ -85,13 +85,13 @@ context 'when given name is a pre-defined rpc method' do it 'returns true' do - subject.rpc_method?(:delete).should be_true + expect(subject.rpc_method?(:delete)).to be_truthy end end context 'when given name is not a pre-defined rpc method' do it 'returns false' do - subject.rpc_method?(:zoobaboo).should be_false + expect(subject.rpc_method?(:zoobaboo)).to be_falsey end end end @@ -137,8 +137,8 @@ def find_with_rpc_failed subject { NewTestService.new(env) } before { subject.find_with_implied_response } - its(:response) { should be_a(Test::Resource) } - specify { subject.response.name.should eq 'Implicit response' } + specify { expect(subject.response).to be_a(Test::Resource) } + specify { expect(subject.response.name).to eq 'Implicit response' } end context 'when using respond_with paradigm' do @@ -152,8 +152,8 @@ def find_with_rpc_failed subject { NewTestService.new(env) } before { subject.find_with_respond_with } - its(:response) { should be_a(Test::Resource) } - specify { subject.response.name.should eq 'Custom response' } + specify { expect(subject.response).to be_a(Test::Resource) } + specify { expect(subject.response.name).to eq 'Custom response' } end end end diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index ad6b7f8d..eafb3dd7 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -21,7 +21,7 @@ class BarService < ::Struct.new(:method_name); end ::Timecop.freeze(1.62.seconds.from_now) do stats.stop - stats.to_s.should eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - #{::Time.now.iso8601}" + expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/1302B - 1.62s - #{::Time.now.iso8601}" end end end @@ -32,7 +32,7 @@ class BarService < ::Struct.new(:method_name); end stats.client = 'myserver1' stats.dispatcher = double('dispatcher', :service => BarService.new(:find_bars)) stats.request_size = 43 - stats.to_s.should eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/-" + expect(stats.to_s).to eq "[SRV] - myserver1 - #{stats.trace_id} - BarService#find_bars - 43B/-" end end end @@ -49,7 +49,7 @@ class BarService < ::Struct.new(:method_name); end ::Timecop.freeze(0.832.seconds.from_now) do stats.stop - stats.to_s.should eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - #{::Time.now.iso8601}" + expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/12345B - 0.832s - #{::Time.now.iso8601}" end end @@ -62,7 +62,7 @@ class BarService < ::Struct.new(:method_name); end stats.service = 'Foo::BarService' stats.method_name = 'find_bars' stats.request_size = 37 - stats.to_s.should eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/-" + expect(stats.to_s).to eq "[CLT] - myserver1.myhost.com:30000 - #{stats.trace_id} - Foo::BarService#find_bars - 37B/-" end end end diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index e2f50e8e..458bcde8 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -23,13 +23,13 @@ before { described_class.instance_variable_set(:@_connector_type, nil) } it 'defaults to socket' do - described_class.connector_type.should eq :socket + expect(described_class.connector_type).to eq :socket end it 'accepts socket or zmq' do [:socket, :zmq].each do |type| described_class.connector_type = type - described_class.connector_type.should eq type + expect(described_class.connector_type).to eq type end end @@ -46,12 +46,12 @@ before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) } it 'defaults to a false value' do - described_class.gc_pause_server_request?.should be_false + expect(described_class.gc_pause_server_request?).to be_falsey end it 'is settable' do described_class.gc_pause_server_request = true - described_class.gc_pause_server_request?.should be_true + expect(described_class.gc_pause_server_request?).to be_truthy end end @@ -59,18 +59,18 @@ before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) } it 'defaults to a true value' do - described_class.print_deprecation_warnings?.should be_true + expect(described_class.print_deprecation_warnings?).to be_truthy end it 'is settable' do described_class.print_deprecation_warnings = false - described_class.print_deprecation_warnings?.should be_false + expect(described_class.print_deprecation_warnings?).to be_falsey end context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do it 'defaults to a false value' do ENV['PB_IGNORE_DEPRECATIONS'] = '1' - described_class.print_deprecation_warnings?.should be_false + expect(described_class.print_deprecation_warnings?).to be_falsey end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 61e94631..f2e3efbf 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -6,6 +6,7 @@ require 'bundler' Bundler.setup :default, :development, :test require 'pry' +# require 'rspec/its' $: << ::File.expand_path('../..', __FILE__) $: << ::File.expand_path('../support', __FILE__) diff --git a/spec/support/packed_field.rb b/spec/support/packed_field.rb index 84e46847..79bb7655 100644 --- a/spec/support/packed_field.rb +++ b/spec/support/packed_field.rb @@ -16,7 +16,7 @@ class PackableFieldTest < ::Protobuf::Message; end subject { PackableFieldTest.get_field(field_name) } - it { should be_packed } + specify { expect(subject).to be_packed } end end From f015c5597b16a6b9add91282743c39808eb01e46 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Sun, 29 Jun 2014 20:52:59 -0600 Subject: [PATCH 004/298] Add ruby 2.1.1 to travis yml --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 33c3265f..b2e5e625 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ language: ruby rvm: - "1.9.3" - "2.0.0" + - "2.1.1" script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec/lib notifications: webhooks: From a1e9a677820dd9a5f4dc909e5d7234fb9827c1eb Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 7 Jul 2014 16:41:53 -0600 Subject: [PATCH 005/298] check the socket after we get it from the context so it is actually usable, any network failures will cause the context to not issue a socket and it should be re-created also go to only 5 iterations through servers before failing out and no wait time between, the entire server cluster is traversed each time so 5 should be enough also added timeouts to snd/rcv of the first alive ping as it should be very quick to determine which server the work is for and fail quickly to move on --- lib/protobuf/rpc/connectors/zmq.rb | 31 ++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index b8121a11..e7966761 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -68,21 +68,26 @@ def create_socket begin server_uri = lookup_server_uri - socket = zmq_context.socket(::ZMQ::REQ) - socket.setsockopt(::ZMQ::LINGER, 0) - log_debug { sign_message("Establishing connection: #{server_uri}") } - zmq_error_check(socket.connect(server_uri), :socket_connect) - log_debug { sign_message("Connection established to #{server_uri}") } + if socket # Make sure the context builds the socket + socket.setsockopt(::ZMQ::LINGER, 0) + + log_debug { sign_message("Establishing connection: #{server_uri}") } + zmq_error_check(socket.connect(server_uri), :socket_connect) + log_debug { sign_message("Connection established to #{server_uri}") } - if first_alive_load_balance? - check_available_response = "" - zmq_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) - zmq_error_check(socket.recv_string(check_available_response), :socket_recv_string) + if first_alive_load_balance? + check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, 100) + socket.setsockopt(::ZMQ::SNDTIMEO, 100) - if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE - zmq_error_check(socket.close, :socket_close) + zmq_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_error_check(socket.close, :socket_close) + end end end end while socket.try(:socket).nil? @@ -101,7 +106,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 50.times do + 5.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -111,8 +116,6 @@ def lookup_server_uri host = options[:host] port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - - sleep(1.0/10.0) # not sure why sleeping at all, but should be way less than 1 second end raise "Host not found for service #{service}" From 8ffe90109d703077da39f47d3b2690a1dc2a9022 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 7 Jul 2014 18:29:51 -0600 Subject: [PATCH 006/298] add the idea of a recoverable error check as zmq should not crash on the timeouts --- lib/protobuf/rpc/connectors/zmq.rb | 34 +++++++++++++++++++++--------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index e7966761..957ddc1d 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -5,8 +5,8 @@ module Protobuf module Rpc module Connectors class Zmq < Base - RequestTimeout = Class.new(RuntimeError) + ZmqRecoverableError = Class.new(RuntimeError) ## # Included Modules @@ -78,15 +78,19 @@ def create_socket log_debug { sign_message("Connection established to #{server_uri}") } if first_alive_load_balance? - check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, 100) - socket.setsockopt(::ZMQ::SNDTIMEO, 100) - - zmq_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) - zmq_error_check(socket.recv_string(check_available_response), :socket_recv_string) - - if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE - zmq_error_check(socket.close, :socket_close) + begin + check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, 50) + socket.setsockopt(::ZMQ::SNDTIMEO, 50) + + zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_recoverable_error_check(socket.close, :socket_close) + end + rescue ZmqRecoverableError + socket = nil # couldn't make a connection and need to try again end end end @@ -202,6 +206,16 @@ def zmq_error_check(return_code, source) ERROR end end + + def zmq_recoverable_error_check(return_code, source) + unless ::ZMQ::Util.resultcode_ok?(return_code || -1) + raise ZmqRecoverableError, <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + end + end end end end From 1bb42ac9095c3a19f217dc9f38142e765444b599 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 7 Jul 2014 18:52:24 -0600 Subject: [PATCH 007/298] add back a sleep and no linger on host_live --- lib/protobuf/rpc/connectors/zmq.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 957ddc1d..15a4766c 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -110,7 +110,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 5.times do + 10.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -120,6 +120,8 @@ def lookup_server_uri host = options[:host] port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) + + sleep(1.0/60.0) end raise "Host not found for service #{service}" @@ -129,6 +131,8 @@ def host_alive?(host) return true unless ping_port_enabled? socket = TCPSocket.new(host, ping_port.to_i) + linger = [1,0].pack('ii') + socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, linger) true rescue From 4ac09dbdab7e2b15cb548d26edbe80ac87f268f7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 12:58:14 -0600 Subject: [PATCH 008/298] remove sleeping and set timeo to 10ms --- lib/protobuf/rpc/connectors/zmq.rb | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 15a4766c..756c5baa 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -11,15 +11,14 @@ class Zmq < Base ## # Included Modules # - include Protobuf::Rpc::Connectors::Common include Protobuf::Logger::LogMethods ## # Class Constants # - CLIENT_RETRIES = (ENV['PB_CLIENT_RETRIES'] || 3) + LINGER = [0,0].pack('ii') ## # Class Methods @@ -80,8 +79,8 @@ def create_socket if first_alive_load_balance? begin check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, 50) - socket.setsockopt(::ZMQ::SNDTIMEO, 50) + socket.setsockopt(::ZMQ::RCVTIMEO, 10) + socket.setsockopt(::ZMQ::SNDTIMEO, 10) zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) @@ -110,7 +109,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 10.times do + 5.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -120,8 +119,6 @@ def lookup_server_uri host = options[:host] port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - - sleep(1.0/60.0) end raise "Host not found for service #{service}" @@ -130,9 +127,13 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? - socket = TCPSocket.new(host, ping_port.to_i) - linger = [1,0].pack('ii') - socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, linger) + socket = Socket.new(:INET, :STREAM) + socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, LINGER) + socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) + socket.setsockopt(:SOCKET, :SNDBUF, 1) + socket.setsockopt(:SOCKET, :REUSEADDR, true) + address = Socket.sockaddr_in(ping_port.to_i, host) + socket.connect(address) true rescue From ab333dd41109c6f817ee93122755b50ae2ce36b5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 14:19:16 -0600 Subject: [PATCH 009/298] remove rcv and snd timeout as to not change too much and let the local queue expand to 5 entries --- lib/protobuf/rpc/connectors/zmq.rb | 3 --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 756c5baa..3123dacf 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -79,9 +79,6 @@ def create_socket if first_alive_load_balance? begin check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, 10) - socket.setsockopt(::ZMQ::SNDTIMEO, 10) - zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 9b77aa5c..4b6be48f 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -102,7 +102,7 @@ def process_frontend address, _, message, *frames = read_from_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE - if @idle_workers.any? || local_queue.empty? + if @idle_workers.any? || local_queue.size < 5 # Should make queue a SizedQueue and allow users to configure queue size write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) From 2decd6457c14f074092322503788f34a8df0a51e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 14:23:24 -0600 Subject: [PATCH 010/298] use plain tcpsocket for now --- lib/protobuf/rpc/connectors/zmq.rb | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 3123dacf..916608c2 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -123,14 +123,7 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? - - socket = Socket.new(:INET, :STREAM) - socket.setsockopt(Socket::SOL_SOCKET, Socket::SO_LINGER, LINGER) - socket.setsockopt(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1) - socket.setsockopt(:SOCKET, :SNDBUF, 1) - socket.setsockopt(:SOCKET, :REUSEADDR, true) - address = Socket.sockaddr_in(ping_port.to_i, host) - socket.connect(address) + socket = TCPSocket.new(host, ping_port.to_i) true rescue From 58d86e50f487e9a12f935d5b414498ebbbbb5f4f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 15:48:58 -0600 Subject: [PATCH 011/298] remove old linger --- lib/protobuf/rpc/connectors/zmq.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 916608c2..7097759f 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -18,7 +18,6 @@ class Zmq < Base # Class Constants # CLIENT_RETRIES = (ENV['PB_CLIENT_RETRIES'] || 3) - LINGER = [0,0].pack('ii') ## # Class Methods From fc9b239f380c66f10397c9467a3ccaac903e74f1 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 8 Jul 2014 16:04:52 -0600 Subject: [PATCH 012/298] bump to 3.0.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 36c544a6..18f0a4c9 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.4' + VERSION = '3.0.5' end From cf6264d7fb5fdf674cd4db6cb9d912d8b52d49fe Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Sat, 19 Jul 2014 16:25:08 -0700 Subject: [PATCH 013/298] Elide unknown enum values when decoding --- lib/protobuf/field/enum_field.rb | 6 ++++ spec/lib/protobuf/message_spec.rb | 59 +++++++++++++++++++++++++++++++ 2 files changed, 65 insertions(+) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 7322c21e..fb386a98 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -16,6 +16,12 @@ def encode(value) super(value.to_i) end + def decode(value) + if acceptable?(value) + value + end + end + def enum? true end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 67e173bf..17fdbce0 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -8,6 +8,65 @@ it 'creates a new message object decoded from the given bytes' do expect(::Test::Resource.decode(message.encode)).to eq message end + + context 'with a new enum value' do + let(:older_message) do + Class.new(Protobuf::Message) do + enum_class = Class.new(::Protobuf::Enum) do + define :YAY, 1 + end + + optional enum_class, :enum_field, 1 + repeated enum_class, :enum_list, 2 + end + end + + let(:newer_message) do + Class.new(Protobuf::Message) do + enum_class = Class.new(::Protobuf::Enum) do + define :YAY, 1 + define :HOORAY, 2 + end + + optional enum_class, :enum_field, 1 + repeated enum_class, :enum_list, 2 + end + end + + context 'with a singular field' do + it 'treats the field as if it was unset when decoding' do + newer = newer_message.new(:enum_field => :HOORAY).serialize + + expect(older_message.decode(newer).enum_field!).to be_nil + end + + it 'rejects an unknown value when using the constructor' do + expect { older_message.new(:enum_field => :HOORAY) }.to raise_error + end + + it 'rejects an unknown value when the setter' do + older = older_message.new + expect { older.enum_field = :HOORAY }.to raise_error + end + end + + context 'with a repeated field' do + it 'treats the field as if it was unset when decoding' do + newer = newer_message.new(:enum_list => [ :HOORAY ]).serialize + + expect(older_message.decode(newer).enum_list).to eq([]) + end + + it 'rejects an unknown value when using the constructor' do + expect { older_message.new(:enum_list => [ :HOORAY ]) }.to raise_error + end + + it 'rejects an unknown value when the setter' do + older = older_message.new + expect { older.enum_field = [ :HOORAY ] }.to raise_error + end + end + end end describe 'defining a new field' do From 66d82bcb1e1367043ccb15c624cdc89684e5d205 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 28 Jul 2014 09:50:37 -0600 Subject: [PATCH 014/298] Bump version 3.1.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 18f0a4c9..d7d20206 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.0.5' + VERSION = '3.1.0' end From 9e4a43f37c996196b84f350e8fc982c8d29ddf4d Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Wed, 30 Jul 2014 17:22:35 -0700 Subject: [PATCH 015/298] Make sure all enum values have names (including defaults) --- lib/protobuf/field/enum_field.rb | 3 ++- spec/lib/protobuf/message_spec.rb | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index fb386a98..c9b90f57 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -53,7 +53,8 @@ def typed_default_value if default.is_a?(Symbol) type_class.const_get(default) else - self.class.default + tag = self.class.default + type_class.new(self.class.default, type_class.name_for_tag(tag), tag) end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 17fdbce0..1dd0df4a 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -131,6 +131,11 @@ expect(test_enum.non_default_enum).to eq(0) end + it "initializes the enum getter with a name" do + test_enum = Test::EnumTestMessage.new + expect { test_enum.non_default_enum.name }.to_not raise_error + end + it "exposes the enum getter raw value through ! method" do test_enum = Test::EnumTestMessage.new expect(test_enum.non_default_enum!).to be_nil From 49ac6acec462cf0a40f57634f495abe75313eed3 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Wed, 30 Jul 2014 18:13:26 -0700 Subject: [PATCH 016/298] Per protobuf spec, unset enums default to first enum value > For enums, the default value is the first value listed in the > enum's type definition. Source: https://developers.google.com/protocol-buffers/docs/proto#optional --- lib/protobuf/field/enum_field.rb | 3 +-- spec/lib/protobuf/message_spec.rb | 8 ++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index c9b90f57..ae6dc51b 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -53,8 +53,7 @@ def typed_default_value if default.is_a?(Symbol) type_class.const_get(default) else - tag = self.class.default - type_class.new(self.class.default, type_class.name_for_tag(tag), tag) + type_class.enums.first end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 1dd0df4a..4ea9fb33 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -126,14 +126,14 @@ end describe '#initialize' do - it "initializes the enum getter to 0" do + it "defaults to the first value listed in the enum's type definition" do test_enum = Test::EnumTestMessage.new - expect(test_enum.non_default_enum).to eq(0) + expect(test_enum.non_default_enum).to eq(1) end - it "initializes the enum getter with a name" do + it "defaults to a a value with a name" do test_enum = Test::EnumTestMessage.new - expect { test_enum.non_default_enum.name }.to_not raise_error + expect(test_enum.non_default_enum.name).to eq(:ONE) end it "exposes the enum getter raw value through ! method" do From 5bdc9d1047c11ba30a12669c8582751a6d721f18 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Thu, 31 Jul 2014 09:56:30 -0700 Subject: [PATCH 017/298] Use type_class.fetch to get a default value if it exists --- lib/protobuf/field/enum_field.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index ae6dc51b..5f0c65e1 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -53,7 +53,7 @@ def typed_default_value if default.is_a?(Symbol) type_class.const_get(default) else - type_class.enums.first + type_class.fetch(default) || type_class.enums.first end end From be8882ee916f09aac23e007b00724cb68aea858a Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Thu, 31 Jul 2014 09:56:44 -0700 Subject: [PATCH 018/298] Prevent using Protobuf::Enum.default, it must be on an instance --- lib/protobuf/field/enum_field.rb | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 5f0c65e1..15bfd94c 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -4,6 +4,14 @@ module Protobuf module Field class EnumField < VarintField + ## + # Class Methods + # + + def self.default + raise NoMethodError, "#{self}.#{__method__} must be called on an instance" + end + ## # Public Instance Methods # From 2d6e1c3623fb39b90321e8ac4fdf239c3e89711a Mon Sep 17 00:00:00 2001 From: Wesley Kim Date: Fri, 1 Aug 2014 10:53:01 -0700 Subject: [PATCH 019/298] Add ignore_unknown_fields config to explicitly configure permitting an unknown field on Message initialization --- lib/protobuf.rb | 13 ++++++++ lib/protobuf/message.rb | 8 +++-- spec/lib/protobuf/message_spec.rb | 49 +++++++++++++++++++++++++++++++ spec/lib/protobuf_spec.rb | 20 +++++++++++++ 4 files changed, 88 insertions(+), 2 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 913e6601..4520ae06 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -83,6 +83,19 @@ def self.print_deprecation_warnings=(value) @_print_deprecation_warnings = !!value end + # Permit unknown field on Message initialization + # + # Default: true + # + # Simple boolean to define whether we want to permit unknown fields + # on Message intialization; otherwise a ::Protobuf::FieldNotDefinedError is thrown. + def self.ignore_unknown_fields? + !defined?(@_ignore_unknown_fields) || @_ignore_unknown_fields + end + + def self.ignore_unknown_fields=(value) + @_ignore_unknown_fields = !!value + end end unless ENV.key?('PB_NO_NETWORKING') diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 71caf733..c7aad381 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -30,7 +30,7 @@ def initialize(fields = {}) @values = {} fields.to_hash.each_pair do |name, value| - self[name] = value unless value.nil? + self[name] = value end end @@ -135,7 +135,11 @@ def [](name) def []=(name, value) if field = self.class.get_field(name, true) - __send__(field.setter_method_name, value) + __send__(field.setter_method_name, value) unless value.nil? + else + unless ::Protobuf.ignore_unknown_fields? + raise ::Protobuf::FieldNotDefinedError, name + end end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 17fdbce0..2ec20ac3 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -157,6 +157,55 @@ test_enum = Test::EnumTestMessage.new(hashie_object) expect(test_enum.non_default_enum).to eq(2) end + + context 'ignoring unknown fields' do + before { ::Protobuf.ignore_unknown_fields = true } + + context 'with valid fields' do + let(:values) { { :name => "Jim" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + + context 'with non-existent field' do + let(:values) { { :name => "Jim", :othername => "invalid" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + end + + context 'not ignoring unknown fields' do + before { ::Protobuf.ignore_unknown_fields = false } + after { ::Protobuf.ignore_unknown_fields = true } + + context 'with valid fields' do + let(:values) { { :name => "Jim" } } + + it "does not raise an error" do + expect { ::Test::Resource.new(values) }.to_not raise_error + end + end + + context 'with non-existent field' do + let(:values) { { :name => "Jim", :othername => "invalid" } } + + it "raises an error and mentions the erroneous field" do + expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/) + end + + context 'with a nil value' do + let(:values) { { :name => "Jim", :othername => nil } } + + it "raises an error and mentions the erroneous field" do + expect { ::Test::Resource.new(values) }.to raise_error(::Protobuf::FieldNotDefinedError, /othername/) + end + end + end + end end describe '#encode' do diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 458bcde8..a484dc57 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -75,4 +75,24 @@ end end + describe '.ignore_unknown_fields?' do + before do + if described_class.instance_variable_defined?(:@_ignore_unknown_fields) + described_class.send(:remove_instance_variable, :@_ignore_unknown_fields) + end + end + + it 'defaults to a true value' do + expect(described_class.ignore_unknown_fields?).to be true + end + + it 'is settable' do + expect { + described_class.ignore_unknown_fields = false + }.to change { + described_class.ignore_unknown_fields? + }.from(true).to(false) + end + end + end From 1864c9b19b13640ae3655a67cd612cb5164f1447 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 1 Aug 2014 17:02:55 -0600 Subject: [PATCH 020/298] Bump version 3.2.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index d7d20206..9a30eed9 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.1.0' + VERSION = '3.2.0' end From 7a2e36ce58373971cb1ca87541426ab87cbbc732 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:00:40 -0700 Subject: [PATCH 021/298] use stronger boolean rspec matchers --- spec/lib/protobuf/cli_spec.rb | 12 +++++----- spec/lib/protobuf/enum_spec.rb | 10 ++++---- spec/lib/protobuf/message_spec.rb | 22 ++++++++--------- spec/lib/protobuf/optionable_spec.rb | 2 +- .../protobuf/rpc/connectors/common_spec.rb | 24 +++++++++---------- .../protobuf/rpc/connectors/socket_spec.rb | 10 ++++---- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 8 +++---- .../protobuf/rpc/servers/zmq/server_spec.rb | 6 ++--- spec/lib/protobuf/rpc/service_spec.rb | 4 ++-- spec/lib/protobuf_spec.rb | 10 ++++---- 10 files changed, 54 insertions(+), 54 deletions(-) diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index c33dba9a..9d8280c1 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -128,7 +128,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - expect(::Protobuf.print_deprecation_warnings?).to be_truthy + expect(::Protobuf.print_deprecation_warnings?).to be true end end @@ -138,7 +138,7 @@ it 'sets the deprecation warning flag to false ' do described_class.start(args) - expect(::Protobuf.print_deprecation_warnings?).to be_falsey + expect(::Protobuf.print_deprecation_warnings?).to be false end end end @@ -148,7 +148,7 @@ it 'sets the deprecation warning flag to true' do described_class.start(args) - expect(::Protobuf.print_deprecation_warnings?).to be_truthy + expect(::Protobuf.print_deprecation_warnings?).to be true end end @@ -157,7 +157,7 @@ it 'sets the deprecation warning flag to false' do described_class.start(args) - expect(::Protobuf.print_deprecation_warnings?).to be_falsey + expect(::Protobuf.print_deprecation_warnings?).to be false end end end @@ -200,7 +200,7 @@ it 'is activated by the --workers_only switch' do expect(runner).to receive(:new) do |options| - expect(options[:workers_only]).to be_truthy + expect(options[:workers_only]).to be true end.and_return(zmq_runner) described_class.start(args) @@ -209,7 +209,7 @@ it 'is activated by PB_WORKERS_ONLY=1 ENV variable' do ENV['PB_WORKERS_ONLY'] = "1" expect(runner).to receive(:new) do |options| - expect(options[:workers_only]).to be_truthy + expect(options[:workers_only]).to be true end.and_return(zmq_runner) described_class.start(args) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 21ebfdd0..3c280fbd 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -21,8 +21,8 @@ end describe '.aliases_allowed?' do - it 'is false when the option is not set' do - expect(Test::EnumTestType.aliases_allowed?).to be_falsey + it 'is nil when the option is not set' do + expect(Test::EnumTestType.aliases_allowed?).to be nil end end @@ -155,15 +155,15 @@ describe '.valid_tag?' do context 'when tag is defined' do - specify { expect(Test::EnumTestType.valid_tag?(tag)).to be_truthy } + specify { expect(Test::EnumTestType.valid_tag?(tag)).to be true } end context 'when tag is not defined' do - specify { expect(Test::EnumTestType.valid_tag?(300)).to be_falsey } + specify { expect(Test::EnumTestType.valid_tag?(300)).to be false } end context 'is true for aliased enums' do - specify { expect(EnumAliasTest.valid_tag?(1)).to be_truthy } + specify { expect(EnumAliasTest.valid_tag?(1)).to be true } end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 2ec20ac3..3a3ea913 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -222,7 +222,7 @@ message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) - expect(new_message.name == name).to be_truthy + expect(new_message.name == name).to be true end it "trims binary when binary is input for string fields" do @@ -231,7 +231,7 @@ message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) - expect(new_message.name == "my name").to be_truthy + expect(new_message.name == "my name").to be true end end @@ -287,12 +287,12 @@ it "sets the predicate to true when the boolean value is true" do subject.active = true - expect(subject.active?).to be_truthy + expect(subject.active?).to be true end it "sets the predicate to false when the boolean value is false" do subject.active = false - expect(subject.active?).to be_falsey + expect(subject.active?).to be false end it "does not put predicate methods on non-boolean fields" do @@ -304,11 +304,11 @@ subject { Test::EnumTestMessage.new(:non_default_enum => 2) } it "is false when the message does not have the field" do - expect(subject.respond_to_and_has?(:other_field)).to be_falsey + expect(subject.respond_to_and_has?(:other_field)).to be false end it "is true when the message has the field" do - expect(subject.respond_to_and_has?(:non_default_enum)).to be_truthy + expect(subject.respond_to_and_has?(:non_default_enum)).to be true end end @@ -316,25 +316,25 @@ subject { Test::EnumTestMessage.new(:non_default_enum => 2) } it "is false when the message does not have the field" do - expect(subject.respond_to_and_has_and_present?(:other_field)).to be_falsey + expect(subject.respond_to_and_has_and_present?(:other_field)).to be false end it "is false when the field is repeated and a value is not present" do - expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_falsey + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be false end it "is false when the field is repeated and the value is empty array" do subject.repeated_enums = [] - expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_falsey + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be false end it "is true when the field is repeated and a value is present" do subject.repeated_enums = [2] - expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be_truthy + expect(subject.respond_to_and_has_and_present?(:repeated_enums)).to be true end it "is true when the message has the field" do - expect(subject.respond_to_and_has_and_present?(:non_default_enum)).to be_truthy + expect(subject.respond_to_and_has_and_present?(:non_default_enum)).to be true end context "#API" do diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index f65eca6c..d6237f14 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -20,7 +20,7 @@ it 'defaults the value to true' do OptionableSetOptionTest.set_option(:baz_enabled) - expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be_truthy + expect(OptionableSetOptionTest.get_option(:baz_enabled)).to be true end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 8f814a7f..ce839263 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -15,15 +15,15 @@ subject { @subject ||= common_class.new(subject_options) } context "API" do - specify { expect(subject.respond_to?(:any_callbacks?)).to be_truthy } - specify { expect(subject.respond_to?(:request_caller)).to be_truthy } - specify { expect(subject.respond_to?(:data_callback)).to be_truthy } - specify { expect(subject.respond_to?(:error)).to be_truthy } - specify { expect(subject.respond_to?(:fail)).to be_truthy } - specify { expect(subject.respond_to?(:complete)).to be_truthy } - specify { expect(subject.respond_to?(:parse_response)).to be_truthy } - specify { expect(subject.respond_to?(:verify_options!)).to be_truthy } - specify { expect(subject.respond_to?(:verify_callbacks)).to be_truthy } + specify { expect(subject.respond_to?(:any_callbacks?)).to be true } + specify { expect(subject.respond_to?(:request_caller)).to be true } + specify { expect(subject.respond_to?(:data_callback)).to be true } + specify { expect(subject.respond_to?(:error)).to be true } + specify { expect(subject.respond_to?(:fail)).to be true } + specify { expect(subject.respond_to?(:complete)).to be true } + specify { expect(subject.respond_to?(:parse_response)).to be true } + specify { expect(subject.respond_to?(:verify_options!)).to be true } + specify { expect(subject.respond_to?(:verify_callbacks)).to be true } end describe "#any_callbacks?" do @@ -31,7 +31,7 @@ [:@complete_cb, :@success_cb, :@failure_cb].each do |cb| it "returns true if #{cb} is provided" do subject.instance_variable_set(cb, "something") - expect(subject.any_callbacks?).to be_truthy + expect(subject.any_callbacks?).to be true end end @@ -40,7 +40,7 @@ subject.instance_variable_set(:@success_cb, nil) subject.instance_variable_set(:@failure_cb, nil) - expect(subject.any_callbacks?).to be_falsey + expect(subject.any_callbacks?).to be false end end @@ -60,7 +60,7 @@ describe "#data_callback" do it "changes state to use the data callback" do subject.data_callback("data") - expect(subject.instance_variable_get(:@used_data_callback)).to be_truthy + expect(subject.instance_variable_get(:@used_data_callback)).to be true end it "sets the data var when using the data_callback" do diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index ff18c2ee..38aeea2a 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -6,10 +6,10 @@ context "API" do # Check the API - specify { expect(subject.respond_to?(:send_request, true)).to be_truthy } - specify { expect(subject.respond_to?(:post_init, true)).to be_truthy } - specify { expect(subject.respond_to?(:close_connection, true)).to be_truthy } - specify { expect(subject.respond_to?(:error?, true)).to be_truthy } + specify { expect(subject.respond_to?(:send_request, true)).to be true } + specify { expect(subject.respond_to?(:post_init, true)).to be true } + specify { expect(subject.respond_to?(:close_connection, true)).to be true } + specify { expect(subject.respond_to?(:error?, true)).to be true } end end @@ -18,7 +18,7 @@ it_behaves_like "a Protobuf Connector" - specify { expect(described_class.include?(Protobuf::Rpc::Connectors::Common)).to be_truthy } + specify { expect(described_class.include?(Protobuf::Rpc::Connectors::Common)).to be true } context "#read_response" do let(:data) { "New data" } diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 707033c8..16bd8ca4 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -79,7 +79,7 @@ end it "returns true" do - expect(subject.send(:host_alive?, "yip.yip")).to be_truthy + expect(subject.send(:host_alive?, "yip.yip")).to be true end it "does not attempt a connection" do @@ -95,19 +95,19 @@ it "returns true when the connection succeeds" do expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil)) - expect(subject.send(:host_alive?, "huzzah.com")).to be_truthy + expect(subject.send(:host_alive?, "huzzah.com")).to be true end it "returns false when the connection fails" do expect(TCPSocket).to receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) - expect(subject.send(:host_alive?, "hayoob.com")).to be_falsey + expect(subject.send(:host_alive?, "hayoob.com")).to be false end it "closes the socket" do socket = double("TCPSocket") expect(socket).to receive(:close) expect(TCPSocket).to receive(:new).with("absorbalof.com", 3307).and_return(socket) - expect(subject.send(:host_alive?, "absorbalof.com")).to be_truthy + expect(subject.send(:host_alive?, "absorbalof.com")).to be true end end end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 9a8df8ce..0fbb0024 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -22,12 +22,12 @@ describe '.running?' do it 'returns true if running' do subject.instance_variable_set(:@running, true) - expect(subject.running?).to be_truthy + expect(subject.running?).to be true end it 'returns false if not running' do subject.instance_variable_set(:@running, false) - expect(subject.running?).to be_falsey + expect(subject.running?).to be false end end @@ -35,7 +35,7 @@ it 'sets running to false' do subject.instance_variable_set(:@workers, []) subject.stop - expect(subject.instance_variable_get(:@running)).to be_falsey + expect(subject.instance_variable_get(:@running)).to be false end end end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 1cef20be..545e90ee 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -85,13 +85,13 @@ context 'when given name is a pre-defined rpc method' do it 'returns true' do - expect(subject.rpc_method?(:delete)).to be_truthy + expect(subject.rpc_method?(:delete)).to be true end end context 'when given name is not a pre-defined rpc method' do it 'returns false' do - expect(subject.rpc_method?(:zoobaboo)).to be_falsey + expect(subject.rpc_method?(:zoobaboo)).to be false end end end diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index a484dc57..3c79956f 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -46,12 +46,12 @@ before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) } it 'defaults to a false value' do - expect(described_class.gc_pause_server_request?).to be_falsey + expect(described_class.gc_pause_server_request?).to be false end it 'is settable' do described_class.gc_pause_server_request = true - expect(described_class.gc_pause_server_request?).to be_truthy + expect(described_class.gc_pause_server_request?).to be true end end @@ -59,18 +59,18 @@ before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) } it 'defaults to a true value' do - expect(described_class.print_deprecation_warnings?).to be_truthy + expect(described_class.print_deprecation_warnings?).to be true end it 'is settable' do described_class.print_deprecation_warnings = false - expect(described_class.print_deprecation_warnings?).to be_falsey + expect(described_class.print_deprecation_warnings?).to be false end context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do it 'defaults to a false value' do ENV['PB_IGNORE_DEPRECATIONS'] = '1' - expect(described_class.print_deprecation_warnings?).to be_falsey + expect(described_class.print_deprecation_warnings?).to be false end end end From bdede9a660703764edda987b048d24fcc9456abd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:03:50 -0700 Subject: [PATCH 022/298] remove unneeded custom matcher --- spec/spec_helper.rb | 1 - spec/support/all.rb | 1 - spec/support/tolerance_matcher.rb | 40 ------------------------------- 3 files changed, 42 deletions(-) delete mode 100644 spec/support/tolerance_matcher.rb diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index f2e3efbf..07b4c16b 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,7 +28,6 @@ ENV.delete("PB_IGNORE_DEPRECATIONS") ::RSpec.configure do |c| - c.include(::Sander6::CustomMatchers) c.mock_with :rspec c.before(:suite) do diff --git a/spec/support/all.rb b/spec/support/all.rb index 8cde33a9..889143a5 100644 --- a/spec/support/all.rb +++ b/spec/support/all.rb @@ -1,5 +1,4 @@ require 'support/packed_field' -require 'support/tolerance_matcher' require 'support/server' def now diff --git a/spec/support/tolerance_matcher.rb b/spec/support/tolerance_matcher.rb deleted file mode 100644 index 50eba4eb..00000000 --- a/spec/support/tolerance_matcher.rb +++ /dev/null @@ -1,40 +0,0 @@ -# -# courtesy of sander 6 -# - http://github.com/sander6/custom_matchers/blob/master/lib/matchers/tolerance_matchers.rb -# -module Sander6 - module CustomMatchers - - class ToleranceMatcher - def initialize(tolerance) - @tolerance = tolerance - @target = 0 - end - - def of(target) - @target = target - self - end - - def matches?(value) - @value = value - ((@target - @tolerance)..(@target + @tolerance)).include?(@value) - end - - def failure_message - "Expected #{@value.inspect} to be within #{@tolerance.inspect} of #{@target.inspect}, but it wasn't.\n" + - "Difference: #{@value - @target}" - end - - def negative_failure_message - "Expected #{@value.inspect} not to be within #{@tolerance.inspect} of #{@target.inspect}, but it was.\n" + - "Difference: #{@value - @target}" - end - end - - def be_within(value) - Sander6::CustomMatchers::ToleranceMatcher.new(value) - end - - end -end From 0887cf4f8a575323b5d7fbdcab65e99e3ca87718 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:07:53 -0700 Subject: [PATCH 023/298] remove unused dependency --- protobuf.gemspec | 1 - 1 file changed, 1 deletion(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index da98eee5..bfec5bdb 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -21,7 +21,6 @@ require "protobuf/version" s.add_dependency 'activesupport', '>= 3.2' s.add_dependency 'middleware' - s.add_dependency 'multi_json' s.add_dependency 'thor' s.add_development_dependency 'ffi-rzmq' From c4eda8e9862b4734172c92f76e264ccebbe120d5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:09:49 -0700 Subject: [PATCH 024/298] Convert specs to RSpec 3.0.3 syntax with Transpec This conversion is done by Transpec 2.3.6 with the following command: transpec -b true,false -f -s * 11 conversions from: it { should ... } to: it { is_expected.to ... } * 1 conversion from: obj.should to: expect(obj).to For more details: https://github.com/yujinakayama/transpec#supported-conversions --- spec/bin/protoc-gen-ruby_spec.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 2 +- spec/lib/protobuf/logger_spec.rb | 14 +++++++------- spec/lib/protobuf/message_spec.rb | 2 +- spec/lib/protobuf_spec.rb | 4 ++-- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/spec/bin/protoc-gen-ruby_spec.rb b/spec/bin/protoc-gen-ruby_spec.rb index a38f165f..36cd7add 100644 --- a/spec/bin/protoc-gen-ruby_spec.rb +++ b/spec/bin/protoc-gen-ruby_spec.rb @@ -11,7 +11,7 @@ it 'reads the serialized request bytes and outputs serialized response bytes' do ::IO.popen(binpath, 'w+') do |pipe| pipe.write(request_bytes) - pipe.read(expected_response_bytes.size).should eq expected_response_bytes + expect(pipe.read(expected_response_bytes.size)).to eq expected_response_bytes end end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 3c280fbd..3de2ab40 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -230,7 +230,7 @@ context 'when coercing from enum' do subject { Test::StatusType::PENDING } - it { should eq(0) } + it { is_expected.to eq(0) } end context 'when coercing from integer' do diff --git a/spec/lib/protobuf/logger_spec.rb b/spec/lib/protobuf/logger_spec.rb index 15eaaebe..6a28aa3f 100644 --- a/spec/lib/protobuf/logger_spec.rb +++ b/spec/lib/protobuf/logger_spec.rb @@ -104,13 +104,13 @@ class MyTestClass subject { MyTestClass.new } - it { should respond_to(:log_debug) } - it { should respond_to(:log_info) } - it { should respond_to(:log_warn) } - it { should respond_to(:log_error) } - it { should respond_to(:log_fatal) } - it { should respond_to(:log_add) } - it { should respond_to(:log_log) } + it { is_expected.to respond_to(:log_debug) } + it { is_expected.to respond_to(:log_info) } + it { is_expected.to respond_to(:log_warn) } + it { is_expected.to respond_to(:log_error) } + it { is_expected.to respond_to(:log_fatal) } + it { is_expected.to respond_to(:log_add) } + it { is_expected.to respond_to(:log_log) } context '#log_exception' do it 'logs the exception message as an error and backtrace as debug' do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 3a3ea913..313cc886 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -283,7 +283,7 @@ describe "boolean predicate methods" do subject { Test::ResourceFindRequest.new(:name => "resource") } - it { should respond_to(:active?) } + it { is_expected.to respond_to(:active?) } it "sets the predicate to true when the boolean value is true" do subject.active = true diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 3c79956f..b828f53c 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -9,13 +9,13 @@ subject { ::Protobuf.client_host } context 'when client_host is not pre-configured' do - it { should eq `hostname`.chomp } + it { is_expected.to eq `hostname`.chomp } end context 'when client_host is pre-configured' do let(:hostname) { 'override.myhost.com' } before { ::Protobuf.client_host = hostname } - it { should eq hostname } + it { is_expected.to eq hostname } end end From c26af1441f28571adeb9ec5228bb45e89d1a61b8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:39:03 -0700 Subject: [PATCH 025/298] prefer constants to strings --- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/field/string_field.rb | 2 +- spec/lib/protobuf/message_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 7505d6e5..ae669e64 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -8,7 +8,7 @@ class BytesField < BaseField # Constants # - BYTES_ENCODING = "ASCII-8BIT".freeze + BYTES_ENCODING = Encoding::BINARY ## # Class Methods diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 7861e128..83fbd4ae 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -8,7 +8,7 @@ class StringField < BytesField # Constants # - ENCODING = 'UTF-8'.freeze + ENCODING = Encoding::UTF_8 ## # Public Instance Methods diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 2ec20ac3..777eb373 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -218,7 +218,7 @@ it "keeps utf-8 when utf-8 is input for string fields" do name = "my name\xC3" - name.force_encoding("UTF-8") + name.force_encoding(Encoding::UTF_8) message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) @@ -227,7 +227,7 @@ it "trims binary when binary is input for string fields" do name = "my name\xC3" - name.force_encoding("ASCII-8BIT") + name.force_encoding(Encoding::BINARY) message = ::Test::Resource.new(:name => name) new_message = ::Test::Resource.decode(message.encode) From e706e76c9e2f1ed888e03df1735723cbdceb37fd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 16:39:20 -0700 Subject: [PATCH 026/298] Use valid UTF-8 in UTF-8 spec Fixes #191 --- spec/lib/protobuf/message_spec.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 777eb373..e4346623 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + require 'spec_helper' describe Protobuf::Message do @@ -217,7 +219,7 @@ end it "keeps utf-8 when utf-8 is input for string fields" do - name = "my name\xC3" + name = 'my name๐Ÿ’ฉ' name.force_encoding(Encoding::UTF_8) message = ::Test::Resource.new(:name => name) From c037b007702f15f18a40f73874d6be26c966ddea Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 12:07:00 -0700 Subject: [PATCH 027/298] use methods instead of mutable state --- lib/protobuf/field/base_field.rb | 28 ++++++---------------------- 1 file changed, 6 insertions(+), 22 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 739e1aaa..c650b498 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -20,8 +20,8 @@ class BaseField # attr_reader :default, :default_value, :deprecated, :extension, - :getter_method_name, :message_class, :name, :optional, - :packed, :repeated, :required, :rule, :setter_method_name, + :getter_method_name, :message_class, :name, + :packed, :rule, :setter_method_name, :tag, :type_class ## @@ -40,8 +40,6 @@ def initialize(message_class, rule, type_class, name, tag, options) @message_class, @rule, @type_class, @name, @tag = \ message_class, rule, type_class, name, tag - set_rule_predicates - @getter_method_name = name @setter_method_name = "#{name}=" @default = options.delete(:default) @@ -116,7 +114,7 @@ def extension? # Is this a repeated field? def repeated? - !! repeated + rule == :repeated end # Is this a repeated message field? @@ -126,12 +124,12 @@ def repeated_message? # Is this a required field? def required? - !! required + rule == :required end - # Is this a optional field? + # Is this an optional field? def optional? - !! optional + rule == :optional end # Is this a deprecated field? @@ -246,20 +244,6 @@ def set_default_value end end - def set_rule_predicates - case rule - when :repeated then - @required = @optional = false - @repeated = true - when :required then - @repeated = @optional = false - @required = true - when :optional then - @repeated = @required = false - @optional = true - end - end - def typed_default_value if default.nil? self.class.default From f809b9c52e25fb2eea69d0151076ecabe1198cd8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Sun, 3 Aug 2014 12:07:19 -0700 Subject: [PATCH 028/298] use default method instead of mutable state --- lib/protobuf/field/base_field.rb | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index c650b498..78f63576 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -19,7 +19,7 @@ class BaseField # Attributes # - attr_reader :default, :default_value, :deprecated, :extension, + attr_reader :default, :deprecated, :extension, :getter_method_name, :message_class, :name, :packed, :rule, :setter_method_name, :tag, :type_class @@ -47,7 +47,6 @@ def initialize(message_class, rule, type_class, name, tag, options) @packed = repeated? && options.delete(:packed) @deprecated = options.delete(:deprecated) - set_default_value warn_excess_options(options) unless options.empty? validate_packed_field if packed? define_accessor @@ -73,6 +72,14 @@ def message? false end + def default_value + @default_value ||= case + when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze + when required? then nil + when optional? then typed_default_value + end + end + # Decode +bytes+ and pass to +message_instance+. def set(message_instance, bytes) if packed? @@ -236,14 +243,6 @@ def define_setter end end - def set_default_value - @default_value = case - when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze - when required? then nil - when optional? then typed_default_value - end - end - def typed_default_value if default.nil? self.class.default From 1610fbfe07ce071d8778556d8905d662c9e4ce35 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 4 Aug 2014 16:17:39 -0600 Subject: [PATCH 029/298] More state cleanup in BaseField, alphabetizing Alphabetize all methods in BaseField. Rather than deleting values out of the options hash, reference the hash from predicate functions. Rename `getter_method_name` and `setter_method_name` to simpler `getter` and `setter`. Remove the excess options warning since we are generating all field definitions. --- lib/protobuf/field/base_field.rb | 135 +++++++++++++++--------------- lib/protobuf/field/bool_field.rb | 2 +- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/message.rb | 8 +- 4 files changed, 72 insertions(+), 75 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 78f63576..6a13e6d9 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -19,10 +19,7 @@ class BaseField # Attributes # - attr_reader :default, :deprecated, :extension, - :getter_method_name, :message_class, :name, - :packed, :rule, :setter_method_name, - :tag, :type_class + attr_reader :message_class, :name, :options, :rule, :tag, :type_class ## # Class Methods @@ -37,17 +34,13 @@ def self.default # def initialize(message_class, rule, type_class, name, tag, options) - @message_class, @rule, @type_class, @name, @tag = \ - message_class, rule, type_class, name, tag + @message_class = message_class + @name = name + @rule = rule + @tag = tag + @type_class = type_class + @options = options - @getter_method_name = name - @setter_method_name = "#{name}=" - @default = options.delete(:default) - @extension = options.delete(:extension) - @packed = repeated? && options.delete(:packed) - @deprecated = options.delete(:deprecated) - - warn_excess_options(options) unless options.empty? validate_packed_field if packed? define_accessor end @@ -64,12 +57,12 @@ def coerce!(value) value end - def enum? - false + def decode(bytes) + raise NotImplementedError, "#{self.class.name}\#decode" end - def message? - false + def default + options[:default] end def default_value @@ -80,73 +73,77 @@ def default_value end end - # Decode +bytes+ and pass to +message_instance+. - def set(message_instance, bytes) - if packed? - array = message_instance.__send__(getter_method_name) - method = \ - case wire_type - when ::Protobuf::WireType::FIXED32 then :read_fixed32 - when ::Protobuf::WireType::FIXED64 then :read_fixed64 - when ::Protobuf::WireType::VARINT then :read_varint - end - stream = StringIO.new(bytes) - - until stream.eof? - array << decode(::Protobuf::Decoder.__send__(method, stream)) - end - else - value = decode(bytes) - if repeated? - message_instance.__send__(getter_method_name) << value - else - message_instance.__send__(setter_method_name, value) - end - end - end - - # Decode +bytes+ and return a field value. - def decode(bytes) - raise NotImplementedError, "#{self.class.name}\#decode" + def deprecated? + options.key?(:deprecated) end - # Encode +value+ and return a byte string. def encode(value) raise NotImplementedError, "#{self.class.name}\#encode" end def extension? - !! extension + options.key?(:extension) + end + + def enum? + false + end + + def getter + name + end + + def message? + false + end + + def optional? + rule == :optional + end + + def packed? + repeated? && options.key?(:packed) end - # Is this a repeated field? def repeated? rule == :repeated end - # Is this a repeated message field? def repeated_message? repeated? && message? end - # Is this a required field? def required? rule == :required end - # Is this an optional field? - def optional? - rule == :optional - end + # Decode +bytes+ and pass to +message_instance+. + def set(message_instance, bytes) + if packed? + array = message_instance.__send__(getter) + method = \ + case wire_type + when ::Protobuf::WireType::FIXED32 then :read_fixed32 + when ::Protobuf::WireType::FIXED64 then :read_fixed64 + when ::Protobuf::WireType::VARINT then :read_varint + end + stream = StringIO.new(bytes) - # Is this a deprecated field? - def deprecated? - !! deprecated + until stream.eof? + array << decode(::Protobuf::Decoder.__send__(method, stream)) + end + else + value = decode(bytes) + if repeated? + message_instance.__send__(getter) << value + else + message_instance.__send__(setter, value) + end + end end - # Is this a packed repeated field? - def packed? - !! packed + def setter + @setter ||= "#{name}=" end def to_s @@ -164,6 +161,10 @@ def warn_if_deprecated end end + def wire_type + ::Protobuf::WireType::VARINT + end + private ## @@ -183,7 +184,7 @@ def define_accessor def define_array_getter field = self message_class.class_eval do - define_method(field.getter_method_name) do + define_method(field.getter) do field.warn_if_deprecated @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) end @@ -193,7 +194,7 @@ def define_array_getter def define_array_setter field = self message_class.class_eval do - define_method(field.setter_method_name) do |val| + define_method(field.setter) do |val| field.warn_if_deprecated if val.is_a?(Array) @@ -219,7 +220,7 @@ def define_array_setter def define_getter field = self message_class.class_eval do - define_method(field.getter_method_name) do + define_method(field.getter) do field.warn_if_deprecated @values.fetch(field.name, field.default_value) end @@ -229,7 +230,7 @@ def define_getter def define_setter field = self message_class.class_eval do - define_method(field.setter_method_name) do |val| + define_method(field.setter) do |val| field.warn_if_deprecated if val.nil? || (val.respond_to?(:empty?) && val.empty?) @@ -257,10 +258,6 @@ def validate_packed_field end end - def warn_excess_options(options) - warn "WARNING: Invalid options: #{options.inspect} (in #{message_class.name}##{name})" - end - end end end diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 0827b17d..a002bbf7 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -40,7 +40,7 @@ def define_getter field = self message_class.class_eval do - define_method("#{field.getter_method_name}?") do + define_method("#{field.getter}?") do field.warn_if_deprecated @values.fetch(field.name, field.default_value) end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index ae669e64..6f7c86c4 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -54,7 +54,7 @@ def wire_type def define_setter field = self message_class.class_eval do - define_method(field.setter_method_name) do |val| + define_method(field.setter) do |val| begin field.warn_if_deprecated val = "#{val}" if val.is_a?(Symbol) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index c7aad381..4d1df27c 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -62,7 +62,7 @@ def dup # def each_field self.class.all_fields.each do |field| - value = __send__(field.name) + value = __send__(field.getter) yield(field, value) end end @@ -71,7 +71,7 @@ def each_field_for_serialization self.class.all_fields.each do |field| next unless field_must_be_serialized?(field) - value = @values[field.name] + value = @values[field.getter] if value.nil? raise ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." @@ -129,13 +129,13 @@ def ==(obj) def [](name) if field = self.class.get_field(name, true) - __send__(field.name) + __send__(field.getter) end end def []=(name, value) if field = self.class.get_field(name, true) - __send__(field.setter_method_name, value) unless value.nil? + __send__(field.setter, value) unless value.nil? else unless ::Protobuf.ignore_unknown_fields? raise ::Protobuf::FieldNotDefinedError, name From c6e013dfba52d76d5a149b403e9bb0e1ee0f069f Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 4 Aug 2014 16:37:10 -0600 Subject: [PATCH 030/298] Add FIXME comments to BaseField --- lib/protobuf/field/base_field.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 6a13e6d9..378daa1c 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -117,7 +117,7 @@ def required? rule == :required end - # Decode +bytes+ and pass to +message_instance+. + # FIXME need to cleanup (rename) this warthog of a method. def set(message_instance, bytes) if packed? array = message_instance.__send__(getter) @@ -146,6 +146,7 @@ def setter @setter ||= "#{name}=" end + # FIXME add packed, deprecated, extension options to to_s output def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" end From 9486341f0a32e908dba325deb2216b7059f7e94e Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Mon, 4 Aug 2014 16:37:58 -0600 Subject: [PATCH 031/298] Bump version 3.2.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 9a30eed9..da2f061f 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.2.0' + VERSION = '3.2.1' end From 406ce63e10175ccfb9199167e41400aea811ce36 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Sat, 23 Aug 2014 14:06:39 -0600 Subject: [PATCH 032/298] Make logging a pluggable component of Protobuf This refactors logging to make the logger a pluggable component of Protobuf. The logger can be changed by using `::Protobuf::Logging.logger = new_logger`. Any object that complies with the API of the ruby standard logger may be used. All the spec's in spec/lib are passing. I had some errors in the zmq library when trying to run the others. I also uncovered a bug that appears when running specs with DEBUG=1. The `RequestDecoder` and the `ResponseDecoder` referred to `env.signature` when they should have been referring to `env.log_signature`. That is now fixed. I used the logging in [mperham's sidekiq](https://github.com/mperham/sidekiq) as a reference. --- lib/protobuf/cli.rb | 30 ++-- lib/protobuf/field/base_field.rb | 4 +- lib/protobuf/field/bytes_field.rb | 4 +- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/logger.rb | 86 ----------- lib/protobuf/logging.rb | 49 +++++++ lib/protobuf/rpc/client.rb | 20 +-- lib/protobuf/rpc/connectors/base.rb | 4 +- lib/protobuf/rpc/connectors/common.rb | 24 ++-- lib/protobuf/rpc/connectors/socket.rb | 12 +- lib/protobuf/rpc/connectors/zmq.rb | 18 +-- .../rpc/middleware/exception_handler.rb | 2 +- lib/protobuf/rpc/middleware/logger.rb | 2 +- .../rpc/middleware/request_decoder.rb | 6 +- .../rpc/middleware/response_encoder.rb | 6 +- lib/protobuf/rpc/server.rb | 2 +- lib/protobuf/rpc/servers/socket/server.rb | 14 +- lib/protobuf/rpc/servers/socket/worker.rb | 4 +- lib/protobuf/rpc/servers/zmq/server.rb | 6 +- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- lib/protobuf/rpc/servers/zmq_runner.rb | 8 +- lib/protobuf/rpc/service.rb | 4 +- lib/protobuf/rpc/service_directory.rb | 16 +-- lib/protobuf/rpc/service_dispatcher.rb | 4 +- lib/protobuf/rpc/stat.rb | 2 +- spec/benchmark/tasks.rb | 4 +- spec/lib/protobuf/cli_spec.rb | 12 +- spec/lib/protobuf/logger_spec.rb | 136 ------------------ spec/spec_helper.rb | 11 +- spec/support/server.rb | 6 +- 30 files changed, 170 insertions(+), 330 deletions(-) delete mode 100644 lib/protobuf/logger.rb create mode 100644 lib/protobuf/logging.rb delete mode 100644 spec/lib/protobuf/logger_spec.rb diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 01f92af8..ad0716c6 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,12 +1,13 @@ require 'thor' require 'protobuf/version' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq_runner' module Protobuf class CLI < ::Thor include ::Thor::Actions + include ::Protobuf::Logging attr_accessor :runner, :mode @@ -21,7 +22,7 @@ class CLI < ::Thor option :threshold, :type => :numeric, :default => 100, :aliases => %w(-t), :desc => 'Multi-threaded Socket Server cleanup threshold.' option :threads, :type => :numeric, :default => 5, :aliases => %w(-r), :desc => 'Number of worker threads to run. Only applicable in --zmq mode.' - option :log, :type => :string, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.' + option :log, :type => :string, :default => STDOUT, :aliases => %w(-l), :desc => 'Log file or device. Default is STDOUT.' option :level, :type => :numeric, :default => ::Logger::INFO, :aliases => %w(-v), :desc => 'Log level to use, 0-5 (see http://www.ruby-doc.org/stdlib/libdoc/logger/rdoc/)' option :socket, :type => :boolean, :aliases => %w(-s), :desc => 'Socket Mode for server and client connections.' @@ -86,12 +87,14 @@ def configure_gc # Setup the protobuf logger. def configure_logger debug_say('Configuring logger') - ::Protobuf::Logger.configure({ :file => options.log || STDOUT, - :level => options.debug? ? ::Logger::DEBUG : options.level }) + + log_level = options.debug? ? ::Logger::DEBUG : options.level + + ::Protobuf::Logging.initialize_logger(options.log, log_level) # Debug output the server options to the log file. - ::Protobuf::Logger.debug { 'Debugging options:' } - ::Protobuf::Logger.debug { options.inspect } + logger.debug { 'Debugging options:' } + logger.debug { options.inspect } end # Re-write the $0 var to have a nice process name in ps. @@ -185,15 +188,16 @@ def runner_options end def say_and_exit(message, exception = nil) - message = set_color(message, :red) if ::Protobuf::Logger.file == STDOUT + message = set_color(message, :red) if options.log == STDOUT + + logger.error { message } - ::Protobuf::Logger.error { message } if exception $stderr.puts "[#{exception.class.name}] #{exception.message}" $stderr.puts exception.backtrace.join("\n") - ::Protobuf::Logger.error { "[#{exception.class.name}] #{exception.message}" } - ::Protobuf::Logger.debug { exception.backtrace.join("\n") } + logger.error { "[#{exception.class.name}] #{exception.message}" } + logger.debug { exception.backtrace.join("\n") } end exit(1) @@ -212,10 +216,10 @@ def create_zmq_runner end def shutdown_server - ::Protobuf::Logger.info { 'RPC Server shutting down...' } + logger.info { 'RPC Server shutting down...' } @runner.try(:stop) ::Protobuf::Rpc::ServiceDirectory.instance.stop - ::Protobuf::Logger.info { 'Shutdown complete' } + logger.info { 'Shutdown complete' } end # Start the runner and log the relevant options. @@ -223,7 +227,7 @@ def start_server debug_say('Running server') @runner.run do - ::Protobuf::Logger.info { + logger.info { "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" } diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 378daa1c..b688f180 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,9 +1,11 @@ -require 'protobuf/wire_type' require 'protobuf/field/field_array' +require 'protobuf/logging' +require 'protobuf/wire_type' module Protobuf module Field class BaseField + include ::Protobuf::Logging ## # Constants diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 6f7c86c4..6b7e6c17 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -67,8 +67,8 @@ def define_setter raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end rescue NoMethodError => ex - ::Protobuf::Logger.error { ex.message } - ::Protobuf::Logger.error { ex.backtrace.join("\n") } + logger.error { ex.message } + logger.error { ex.backtrace.join("\n") } raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 145784b6..b1c2fa2c 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -1,6 +1,6 @@ module Protobuf class Lifecycle - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging def self.register(event_name, &blk) raise "Lifecycle register must have a block" unless block_given? diff --git a/lib/protobuf/logger.rb b/lib/protobuf/logger.rb deleted file mode 100644 index 30397c27..00000000 --- a/lib/protobuf/logger.rb +++ /dev/null @@ -1,86 +0,0 @@ -require 'logger' - -module Protobuf - class Logger < ::Logger - - class << self - attr_accessor :file, :level - - # Stub out the log methods for Protobuf::Logger as singleton methods - [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| - define_method(m) do |*params, &block| - instance && instance.__send__(m, *params, &block) - end - end - end - - # One-line file/level configuration - def self.configure(options) - self.file = options.fetch(:file, false) - self.level = options.fetch(:level, false) - end - - # Use to reset the instance - def self.reset_device! - self.file = self.level = @__instance = nil - end - - # Singleton instance - def self.instance - @__instance ||= begin - log = nil - - if @file && @level - log = new(self.file) - log.level = self.level - end - - log - end - end - - # - # LogMethods module for log method including, e.g.: - # - # class MyClass - # include Protobuf::Logger::LogMethods - # ... - # end - # - # Produce a module to allow "include" in other classes to avoid - # cluttering the namespace of the including class with the other methods defined above - # - module LogMethods - [:debug, :info, :warn, :error, :fatal, :any, :add, :log].each do |m| - define_method("log_#{m}") do |*params, &block| - params.map! { |message| sign_message(message) } - ::Protobuf::Logger.__send__(m, *params, &block) - end - end - - # When included, also extend the LogMethods module for class access. - def self.included(base) - base.extend(LogMethods) - end - - # We often want to log an exception, so let's make that a core - # concern of the logger. - # - def log_exception(ex) - log_error { ex.message } - log_error { ex.backtrace[0..5].join("\n") } - log_debug { ex.backtrace.join("\n") } - end - - def log_signature - @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]" - end - - def sign_message(message) - "#{log_signature} #{message}" - end - - end - - end -end diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb new file mode 100644 index 00000000..47f5b8f3 --- /dev/null +++ b/lib/protobuf/logging.rb @@ -0,0 +1,49 @@ +module Protobuf + module Logging + def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) + @counter ||= 0 + @counter = @counter + 1 + old_logger = defined?(@logger) ? @logger : nil + @logger = Logger.new(log_target) + @logger.level = log_level + old_logger.close if old_logger and close_old_logger? + @logger + end + + def self.close_old_logger=(boolean) + @close_old_logger = !!boolean + end + + def self.close_old_logger? + defined?(@close_old_logger) ? @close_old_logger : true + end + + def self.logger + defined?(@logger) ? @logger : initialize_logger + end + + def self.logger=(new_logger) + @logger = new_logger + end + + def logger + ::Protobuf::Logging.logger + end + + def log_exception(ex) + logger.error { ex.message } + logger.error { ex.backtrace[0..5].join("\n") } + logger.debug { ex.backtrace.join("\n") } + end + + def log_signature + @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]" + end + + def sign_message(message) + "#{log_signature} #{message}" + end + end +end + +# Inspired by [mperham](https://github.com/mperham/sidekiq) diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 0d0c0d4e..373e3b0e 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -1,6 +1,6 @@ require 'forwardable' require 'protobuf' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/error' require 'protobuf/rpc/connector' @@ -8,7 +8,7 @@ module Protobuf module Rpc class Client extend Forwardable - include Protobuf::Logger::LogMethods + include Protobuf::Logging def_delegators :@connector, :options, :complete_cb, :success_cb, :failure_cb attr_reader :connector @@ -29,7 +29,7 @@ class Client def initialize(options = {}) raise "Invalid client configuration. Service must be defined." if options[:service].nil? @connector = Connector.connector_for_client.new(options) - log_debug { sign_message("Initialized with options: #{options.inspect}") } + logger.debug { sign_message("Initialized with options: #{options.inspect}") } end def log_signature @@ -106,28 +106,28 @@ def on_success=(callable) def method_missing(method_name, *params) service = options[:service] unless service.rpc_method?(method_name) - log_error { sign_message("#{service.name}##{method_name.to_s} not rpc method, passing to super") } + logger.error { sign_message("#{service.name}##{method_name.to_s} not rpc method, passing to super") } super(method_name, *params) else - log_debug { sign_message("#{service.name}##{method_name.to_s}") } + logger.debug { sign_message("#{service.name}##{method_name.to_s}") } rpc = service.rpcs[method_name.to_sym] options[:request_type] = rpc.request_type - log_debug { sign_message("Request Type: #{options[:request_type].name}") } + logger.debug { sign_message("Request Type: #{options[:request_type].name}") } options[:response_type] = rpc.response_type - log_debug { sign_message("Response Type: #{options[:response_type].name}") } + logger.debug { sign_message("Response Type: #{options[:response_type].name}") } options[:method] = method_name.to_s options[:request] = params[0].is_a?(Hash) ? options[:request_type].new(params[0]) : params[0] - log_debug { sign_message("Request Data: #{options[:request].inspect}") } + logger.debug { sign_message("Request Data: #{options[:request].inspect}") } # Call client to setup on_success and on_failure event callbacks if block_given? - log_debug { sign_message("client setup callback given, invoking") } + logger.debug { sign_message("client setup callback given, invoking") } yield(self) else - log_debug { sign_message("no block given for callbacks") } + logger.debug { sign_message("no block given for callbacks") } end send_request diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index d846d974..9f7735ab 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -1,5 +1,5 @@ require 'timeout' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' require 'protobuf/rpc/error' @@ -23,7 +23,7 @@ module Connectors } class Base - include Protobuf::Logger::LogMethods + include Protobuf::Logging attr_reader :options attr_accessor :success_cb, :failure_cb, :complete_cb diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 4db2bc28..8c7a84cd 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -19,17 +19,17 @@ def request_caller def complete @stats.stop - log_info { @stats.to_s } - log_debug { sign_message('Response proceessing complete') } + logger.info { @stats.to_s } + logger.debug { sign_message('Response proceessing complete') } @complete_cb.call(self) unless @complete_cb.nil? rescue => e - log_error { sign_message('Complete callback error encountered') } + logger.error { sign_message('Complete callback error encountered') } log_exception(e) raise end def data_callback(data) - log_debug { sign_message('Using data_callback') } + logger.debug { sign_message('Using data_callback') } @used_data_callback = true @data = data end @@ -42,11 +42,11 @@ def fail(code, message) @error = ClientError.new @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message - log_debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } + logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } @failure_cb.call(@error) unless @failure_cb.nil? rescue => e - log_error { sign_message("Failure callback error encountered") } + logger.error { sign_message("Failure callback error encountered") } log_exception(e) raise ensure @@ -71,7 +71,7 @@ def parse_response # Close up the connection as we no longer need it close_connection - log_debug { sign_message("Parsing response from server (connection closed)") } + logger.debug { sign_message("Parsing response from server (connection closed)") } # Parse out the raw response @stats.response_size = @response_data.size unless @response_data.nil? @@ -79,13 +79,13 @@ def parse_response # Determine success or failure based on parsed data if response_wrapper.has_field?(:error_reason) - log_debug { sign_message("Error response parsed") } + logger.debug { sign_message("Error response parsed") } # fail the call if we already know the client is failed # (don't try to parse out the response payload) fail(response_wrapper.error_reason, response_wrapper.error) else - log_debug { sign_message("Successful response parsed") } + logger.debug { sign_message("Successful response parsed") } # Ensure client_response is an instance parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) @@ -125,10 +125,10 @@ def setup_connection end def succeed(response) - log_debug { sign_message("Server succeeded request (invoking on_success)") } + logger.debug { sign_message("Server succeeded request (invoking on_success)") } @success_cb.call(response) unless @success_cb.nil? rescue => e - log_error { sign_message("Success callback error encountered") } + logger.error { sign_message("Success callback error encountered") } log_exception(e) fail(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") ensure @@ -153,7 +153,7 @@ def validate_request_type! def verify_callbacks unless any_callbacks? - log_debug { sign_message("No callbacks set, using data_callback") } + logger.debug { sign_message("No callbacks set, using data_callback") } @success_cb = @failure_cb = self.method(:data_callback) end end diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 1507acc7..26fd0e97 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -5,7 +5,7 @@ module Rpc module Connectors class Socket < Base include Protobuf::Rpc::Connectors::Common - include Protobuf::Logger::LogMethods + include Protobuf::Logging def send_request timeout_wrap do @@ -24,18 +24,18 @@ def log_signature def close_connection @socket.close - log_debug { sign_message('Connector closed') } + logger.debug { sign_message('Connector closed') } end def connect_to_rpc_server @socket = TCPSocket.new(options[:host], options[:port]) - log_debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } + logger.debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } end # Method to determine error state, must be used with Connector api def error? return true if @error - log_debug { sign_message("Error state : #{@socket.closed?}") } + logger.debug { sign_message("Error state : #{@socket.closed?}") } @socket.closed? end @@ -51,7 +51,7 @@ def read_data end def read_response - log_debug { sign_message("error? is #{error?}") } + logger.debug { sign_message("error? is #{error?}") } return if error? response_buffer = ::Protobuf::Rpc::Buffer.new(:read) response_buffer << read_data @@ -65,7 +65,7 @@ def send_data request_buffer.set_data(@request_data) @socket.write(request_buffer.write) @socket.flush - log_debug { sign_message("write closed") } + logger.debug { sign_message("write closed") } end end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 7097759f..84a4f190 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -12,7 +12,7 @@ class Zmq < Base # Included Modules # include Protobuf::Rpc::Connectors::Common - include Protobuf::Logger::LogMethods + include Protobuf::Logging ## # Class Constants @@ -71,9 +71,9 @@ def create_socket if socket # Make sure the context builds the socket socket.setsockopt(::ZMQ::LINGER, 0) - log_debug { sign_message("Establishing connection: #{server_uri}") } + logger.debug { sign_message("Establishing connection: #{server_uri}") } zmq_error_check(socket.connect(server_uri), :socket_connect) - log_debug { sign_message("Connection established to #{server_uri}") } + logger.debug { sign_message("Connection established to #{server_uri}") } if first_alive_load_balance? begin @@ -155,21 +155,21 @@ def send_request_with_timeout(timeout, attempt = 0) poller = ::ZMQ::Poller.new poller.register_readable(socket) - log_debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } zmq_error_check(socket.send_string(@request_data), :socket_send_string) - log_debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } if poller.poll(timeout * 1000) == 1 zmq_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) - log_debug { sign_message("Response received (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Response received (attempt #{attempt}, #{socket})") } else - log_debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } raise RequestTimeout end ensure - log_debug { sign_message("Closing Socket") } + logger.debug { sign_message("Closing Socket") } zmq_error_check(socket.close, :socket_close) if socket - log_debug { sign_message("Socket closed") } + logger.debug { sign_message("Socket closed") } end # The service we're attempting to connect to diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index 010a1b8f..b29ea29b 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class ExceptionHandler - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging attr_reader :app diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb index 93dd17b1..9f4bd308 100644 --- a/lib/protobuf/rpc/middleware/logger.rb +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -42,7 +42,7 @@ class Instrumenter attr_reader :env def flush(env) - Protobuf::Logger.info { to_s(env) } + ::Protobuf::Logging.logger.info { to_s(env) } end def start diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index fa74ad5d..de42a77b 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class RequestDecoder - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging attr_reader :app, :env @@ -27,7 +27,7 @@ def call(env) end def log_signature - env.signature || super + env.log_signature || super end private @@ -57,7 +57,7 @@ def request # def request_wrapper @request_wrapper ||= begin - log_debug { sign_message("Decoding request: #{env.encoded_request}") } + logger.debug { sign_message("Decoding request: #{env.encoded_request}") } Socketrpc::Request.decode(env.encoded_request) end rescue => exception diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 5d6188ab..11c53613 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -2,7 +2,7 @@ module Protobuf module Rpc module Middleware class ResponseEncoder - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging attr_reader :app, :env @@ -19,7 +19,7 @@ def call(env) end def log_signature - env.signature || super + env.log_signature || super end private @@ -27,7 +27,7 @@ def log_signature # Encode the response wrapper to return to the client # def encoded_response - log_debug { sign_message("Encoding response: #{response.inspect}") } + logger.debug { sign_message("Encoding response: #{response.inspect}") } env.encoded_response = wrapped_response.encode rescue => exception diff --git a/lib/protobuf/rpc/server.rb b/lib/protobuf/rpc/server.rb index f76bcd58..27dbaf8a 100644 --- a/lib/protobuf/rpc/server.rb +++ b/lib/protobuf/rpc/server.rb @@ -1,5 +1,5 @@ require 'protobuf' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/rpc.pb' require 'protobuf/rpc/buffer' require 'protobuf/rpc/env' diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 7efdd65b..e184c9d8 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -5,7 +5,7 @@ module Protobuf module Rpc module Socket class Server - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging AUTO_COLLECT_TIMEOUT = 5 # seconds @@ -19,7 +19,7 @@ def cleanup? end def cleanup_threads - log_debug { sign_message("Thread cleanup - #{@threads.size} - start") } + logger.debug { sign_message("Thread cleanup - #{@threads.size} - start") } @threads = @threads.select do |t| if t[:thread].alive? @@ -31,7 +31,7 @@ def cleanup_threads end end - log_debug { sign_message("Thread cleanup - #{@threads.size} - complete") } + logger.debug { sign_message("Thread cleanup - #{@threads.size} - complete") } end def log_signature @@ -47,7 +47,7 @@ def new_worker(socket) end def run - log_debug { sign_message("Run") } + logger.debug { sign_message("Run") } host = @options[:host] port = @options[:port] backlog = @options[:backlog] @@ -63,7 +63,7 @@ def run @running = true while running? - log_debug { sign_message("Waiting for connections") } + logger.debug { sign_message("Waiting for connections") } ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) rescue nil if ready_cnxns @@ -73,13 +73,13 @@ def run when !running? then # no-op when client == @server then - log_debug { sign_message("Accepted new connection") } + logger.debug { sign_message("Accepted new connection") } client, sockaddr = @server.accept @listen_fds << client else unless @working.include?(client) @working << @listen_fds.delete(client) - log_debug { sign_message("Working") } + logger.debug { sign_message("Working") } @threads << { :thread => new_worker(client), :socket => client } cleanup_threads if cleanup? diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index aa443347..984ae01e 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -1,12 +1,12 @@ require 'protobuf/rpc/server' -require 'protobuf/logger' +require 'protobuf/logging' module Protobuf module Rpc module Socket class Worker include ::Protobuf::Rpc::Server - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging def initialize(sock, &complete_cb) @socket = sock diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 51a5d1ae..c45c487f 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -100,7 +100,7 @@ def broadcast_heartbeat @beacon_socket.send(heartbeat.encode, 0) - log_debug { sign_message("sent heartbeat to #{beacon_uri}") } + logger.debug { sign_message("sent heartbeat to #{beacon_uri}") } end def broadcast_heartbeat? @@ -204,7 +204,7 @@ def start_missing_workers if missing_workers > 0 missing_workers.times { start_worker } - log_debug { sign_message("#{total_workers} workers started") } + logger.debug { sign_message("#{total_workers} workers started") } end end @@ -303,7 +303,7 @@ def start_worker rescue => e message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" $stderr.puts(message) - log_error { message } + logger.error { message } end end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 3d95ce0f..af7dcde5 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -11,7 +11,7 @@ module Zmq WORKERS_AVAILABLE = "\5" module Util - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging def self.included(base) base.extend(::Protobuf::Rpc::Zmq::Util) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 2ed1ab52..70b53548 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -3,7 +3,7 @@ module Protobuf module Rpc class ZmqRunner - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging def initialize(options) @options = case @@ -38,12 +38,12 @@ def stop def register_signals trap(:TTIN) do @server.add_worker - log_info { "Increased worker size to: #{@server.total_workers}" } + logger.info { "Increased worker size to: #{@server.total_workers}" } end trap(:TTOU) do - log_info { "Current worker size: #{@server.workers.size}" } - log_info { "Current worker size: #{@server.busy_worker_count}" } + logger.info { "Current worker size: #{@server.workers.size}" } + logger.info { "Current worker size: #{@server.busy_worker_count}" } end end end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 12efbc10..1c5f1e8c 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -1,4 +1,4 @@ -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/client' require 'protobuf/rpc/error' require 'protobuf/rpc/service_filters' @@ -10,7 +10,7 @@ module Rpc RpcMethod = Struct.new("RpcMethod", :method, :request_type, :response_type) class Service - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging include ::Protobuf::Rpc::ServiceFilters DEFAULT_HOST = '127.0.0.1'.freeze diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index bc7874d4..868e53be 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -11,7 +11,7 @@ module Protobuf module Rpc class ServiceDirectory include ::Singleton - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging DEFAULT_ADDRESS = "0.0.0.0" DEFAULT_PORT = 53000 @@ -116,7 +116,7 @@ def running? def start unless running? init_socket - log_info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } + logger.info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } @thread = Thread.new { self.send(:run) } end @@ -124,7 +124,7 @@ def start end def stop - log_info { sign_message("Stopping directory") } + logger.info { sign_message("Stopping directory") } @thread.try(:kill).try(:join) @socket.try(:close) @@ -151,7 +151,7 @@ def add_or_update_listing(uuid, server) end trigger(action, listing) - log_debug { sign_message("#{action} server: #{server.inspect}") } + logger.debug { sign_message("#{action} server: #{server.inspect}") } end def init_socket @@ -177,7 +177,7 @@ def process_beacon(beacon) remove_listing(uuid) end else - log_info { sign_message("Ignoring incomplete beacon: #{beacon.inspect}") } + logger.info { sign_message("Ignoring incomplete beacon: #{beacon.inspect}") } end end @@ -193,7 +193,7 @@ def read_beacon end def remove_expired_listings - log_debug { sign_message("Removing expired listings") } + logger.debug { sign_message("Removing expired listings") } @listings_by_uuid.each do |uuid, listing| remove_listing(uuid) if listing.expired? end @@ -202,7 +202,7 @@ def remove_expired_listings def remove_listing(uuid) listing = @listings_by_uuid[uuid] or return - log_debug { sign_message("Removing listing: #{listing.inspect}") } + logger.debug { sign_message("Removing listing: #{listing.inspect}") } @listings_by_service.each do |service, listings| listings.delete(listing) @@ -233,7 +233,7 @@ def run end end rescue => e - log_debug { sign_message("ERROR: (#{e.class}) #{e.message}\n#{e.backtrace.join("\n")}") } + logger.debug { sign_message("ERROR: (#{e.class}) #{e.message}\n#{e.backtrace.join("\n")}") } retry end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 469af8e7..91dacb42 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -1,9 +1,9 @@ -require 'protobuf/logger' +require 'protobuf/logging' module Protobuf module Rpc class ServiceDispatcher - include ::Protobuf::Logger::LogMethods + include ::Protobuf::Logging attr_reader :env diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 5dd504ca..5ab9407e 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -1,6 +1,6 @@ require 'date' require 'time' -require 'protobuf/logger' +require 'protobuf/logging' module Protobuf module Rpc diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 8c45d685..f90554fd 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -13,8 +13,8 @@ # Including a way to turn on debug logger for spec runs if ENV["DEBUG"] puts 'debugging' - debug_log = File.expand_path('../debug_bench.log', File.dirname(__FILE__) ) - Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) + debug_log = File.expand_path('../../../debug_bench.log', __FILE__) + Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG) end namespace :benchmark do diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 9d8280c1..24fde5e0 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -19,6 +19,12 @@ runner } + around(:each) do |example| + logger = ::Protobuf::Logging.logger + example.run + ::Protobuf::Logging.logger = logger + end + before(:each) do allow(::Protobuf::Rpc::SocketRunner).to receive(:new).and_return(sock_runner) allow(::Protobuf::Rpc::ZmqRunner).to receive(:new).and_return(zmq_runner) @@ -88,9 +94,9 @@ let(:test_args) { [ '--log=mylog.log', '--level=0' ] } it 'sends the log file and level options to the runner' do - expect(::Protobuf::Logger).to receive(:configure) do |options| - expect(options[:file]).to eq 'mylog.log' - expect(options[:level]).to eq 0 + expect(::Protobuf::Logging).to receive(:initialize_logger) do |file, level| + expect(file).to eq 'mylog.log' + expect(level).to eq 0 end described_class.start(args) end diff --git a/spec/lib/protobuf/logger_spec.rb b/spec/lib/protobuf/logger_spec.rb deleted file mode 100644 index 6a28aa3f..00000000 --- a/spec/lib/protobuf/logger_spec.rb +++ /dev/null @@ -1,136 +0,0 @@ -require 'protobuf/logger' -require 'stringio' -require 'fileutils' - -describe Protobuf::Logger do - - subject { Protobuf::Logger } - - before(:each) do - Protobuf::Logger.reset_device! - Protobuf::Logger.file = '/dev/null' - Protobuf::Logger.level = ::Logger::INFO - end - - after(:all) do - ::FileUtils.rm_f('myfile.log') - end - - describe '.instance' do - - it 'doesn\'t create a logger if the file was not set' do - subject.file = nil - expect(subject.instance).to be_nil - end - - it 'doesn\'t create a logger if the level was not set' do - subject.level = nil - expect(subject.instance).to be_nil - end - - it 'gets a new instance of the logger when file and level are set' do - expect(subject.file).to_not be_nil - expect(subject.level).to_not be_nil - expect(subject.instance).to_not be_nil - end - - it 'keeps the same object from multiple calls to instance' do - expect(subject.instance).to equal(subject.instance) - end - - end - - describe '.configure' do - before(:each) { subject.reset_device! } - it 'sets the file and level in one call' do - expect(subject.file).to_not be - expect(subject.level).to_not be - expect(subject.instance).to_not be - subject.configure :file => 'myfile.log', :level => ::Logger::WARN - expect(subject.file).to eq('myfile.log') - expect(subject.level).to eq(::Logger::WARN) - expect(subject.instance.level).to eq(::Logger::WARN) - end - - end - - describe '.reset_device!' do - - it 'resets the logger instance, file, and level' do - expect(subject.instance).to be - expect(subject.file).to be - expect(subject.level).to be - subject.reset_device! - expect(subject.instance).to_not be - expect(subject.file).to_not be - expect(subject.level).to_not be - end - - end - - context 'when logging' do - - it 'doesn\'t raise errors when log instance is nil' do - subject.reset_device! - expect(subject.instance).to be_nil - expect { - subject.debug 'No errors here' - subject.info 'No errors here' - subject.warn 'No errors here' - subject.error 'No errors here' - subject.fatal 'No errors here' - subject.add 'No errors here' - subject.log 'No errors here' - }.to_not raise_error - end - - it 'logs correctly when instance is valid' do - expect(subject.instance).to_not be_nil - expect(subject.instance).to receive(:info).with('Should log great') - subject.info 'Should log great' - end - - end - - describe Protobuf::Logger::LogMethods do - - context 'when included in another class' do - - before(:all) do - class MyTestClass - include Protobuf::Logger::LogMethods - end - end - - subject { MyTestClass.new } - - it { is_expected.to respond_to(:log_debug) } - it { is_expected.to respond_to(:log_info) } - it { is_expected.to respond_to(:log_warn) } - it { is_expected.to respond_to(:log_error) } - it { is_expected.to respond_to(:log_fatal) } - it { is_expected.to respond_to(:log_add) } - it { is_expected.to respond_to(:log_log) } - - context '#log_exception' do - it 'logs the exception message as an error and backtrace as debug' do - expect(subject).to receive(:log_error).twice - expect(subject).to receive(:log_debug) - subject.log_exception(RuntimeError.new('this is an exception')) - end - end - - specify { expect(subject.log_signature).to eq "[MyTestClass]" } - describe '#sign_message' do - specify { expect(subject.sign_message("this is a test")).to eq "[MyTestClass] this is a test" } - specify { expect(subject.class.sign_message("this is a test")).to eq "[MyTestClass] this is a test" } - end - - it 'passes all embedded log calls to Logger instance' do - expect(Protobuf::Logger.instance).to receive(:debug).with('[MyTestClass] log this') - subject.log_debug('log this') - end - - end - end -end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07b4c16b..414f80d5 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,6 +1,3 @@ -require 'simplecov' -SimpleCov.start - require 'timeout' require 'rubygems' require 'bundler' @@ -20,10 +17,14 @@ # Including a way to turn on debug logger for spec runs if ENV.key?('DEBUG') - debug_log = ::File.expand_path('../debug_specs.log', File.dirname(__FILE__) ) - ::Protobuf::Logger.configure(:file => debug_log, :level => ::Logger::DEBUG) + debug_log = ::File.expand_path('../../debug_specs.log', __FILE__ ) + ::Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG) +else + ::Protobuf::Logging.initialize_logger('/dev/null') end +::Protobuf::Logging.close_old_logger = false + # Get rid of the deprecation env var if present (messes with specs). ENV.delete("PB_IGNORE_DEPRECATIONS") diff --git a/spec/support/server.rb b/spec/support/server.rb index a88db354..55e4dbea 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -1,5 +1,5 @@ require 'ostruct' -require 'protobuf/logger' +require 'protobuf/logging' require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/servers/socket_runner' @@ -33,7 +33,7 @@ def post_init end class StubServer - include Protobuf::Logger::LogMethods + include Protobuf::Logging attr_accessor :options @@ -58,7 +58,7 @@ def start else start_socket_server end - log_debug { sign_message("Server started #{@options.host}:#{@options.port}") } + logger.debug { sign_message("Server started #{@options.host}:#{@options.port}") } end def start_socket_server From 623c05bb47e38d4a176dd0794a2d0d1f59666c98 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 24 Aug 2014 12:44:46 -0600 Subject: [PATCH 033/298] allow queue size to be configurable and use an array as local queue as the broker is single threaded --- lib/protobuf/rpc/connectors/zmq.rb | 2 ++ lib/protobuf/rpc/servers/zmq/broker.rb | 14 +++++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 7097759f..015f83b0 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -123,6 +123,8 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? socket = TCPSocket.new(host, ping_port.to_i) + socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) + socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1,0].pack('ii')) true rescue diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 4b6be48f..717b1dd0 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -67,7 +67,7 @@ def init_frontend_socket end def init_local_queue - @local_queue = ::Queue.new + @local_queue = [] end def init_poller @@ -88,6 +88,10 @@ def inproc? !!@server.try(:inproc?) end + def local_queue_max_size + @local_queue_max_size ||= [ENV["PB_LOCAL_QUEUE_MAX_SIZE"].to_i, 5].max + end + def process_backend worker, ignore, *frames = read_from_backend @@ -102,16 +106,16 @@ def process_frontend address, _, message, *frames = read_from_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE - if @idle_workers.any? || local_queue.size < 5 # Should make queue a SizedQueue and allow users to configure queue size + if local_queue.size < local_queue_max_size write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) end else - if @idle_workers.any? - write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) - else + if @idle_workers.empty? local_queue.push([address, "", message ] + frames) + else + write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) end end end From 492f950443ca67ad4687d8cc69c4269c510f15c5 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 26 Aug 2014 15:26:18 -0600 Subject: [PATCH 034/298] updating name to reflect zmq serverness --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 717b1dd0..93ef6e5e 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -89,7 +89,7 @@ def inproc? end def local_queue_max_size - @local_queue_max_size ||= [ENV["PB_LOCAL_QUEUE_MAX_SIZE"].to_i, 5].max + @local_queue_max_size ||= [ENV["PB_ZMQ_SERVER_QUEUE_MAX_SIZE"].to_i, 5].max end def process_backend From e942d61767c722a744378f27ab3ba422a320a3e7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 26 Aug 2014 16:46:00 -0600 Subject: [PATCH 035/298] bump to 3.3.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index da2f061f..155fcc11 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.2.1' + VERSION = '3.3.0' end From dc9647b40529e64fa71f75cbdb350d2c36fd2867 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 27 Aug 2014 14:09:16 -0600 Subject: [PATCH 036/298] Never close $stdout --- lib/protobuf/logging.rb | 10 +--------- spec/spec_helper.rb | 2 -- 2 files changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 47f5b8f3..5ee649b9 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -6,18 +6,10 @@ def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) old_logger = defined?(@logger) ? @logger : nil @logger = Logger.new(log_target) @logger.level = log_level - old_logger.close if old_logger and close_old_logger? + old_logger.close if old_logger and log_target != $stdout @logger end - def self.close_old_logger=(boolean) - @close_old_logger = !!boolean - end - - def self.close_old_logger? - defined?(@close_old_logger) ? @close_old_logger : true - end - def self.logger defined?(@logger) ? @logger : initialize_logger end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 414f80d5..fa22f2ce 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -23,8 +23,6 @@ ::Protobuf::Logging.initialize_logger('/dev/null') end -::Protobuf::Logging.close_old_logger = false - # Get rid of the deprecation env var if present (messes with specs). ENV.delete("PB_IGNORE_DEPRECATIONS") From a8e071c80621fd9ab463b6672b9e46e8acc036cd Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 27 Aug 2014 14:22:54 -0600 Subject: [PATCH 037/298] Never close old logger There's not a great way to handle automatically closing old file descriptors, so I'm just going to leave it out for now. --- lib/protobuf/logging.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 5ee649b9..78a5aea6 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -3,10 +3,8 @@ module Logging def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) @counter ||= 0 @counter = @counter + 1 - old_logger = defined?(@logger) ? @logger : nil @logger = Logger.new(log_target) @logger.level = log_level - old_logger.close if old_logger and log_target != $stdout @logger end From 8b62b4260bc275d7af085484bffc550b081f4714 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 27 Aug 2014 16:27:05 -0600 Subject: [PATCH 038/298] Bump version to 3.3.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 155fcc11..d0ad3c81 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.0' + VERSION = '3.3.1' end From 1e55916e3a258042bc48bc824d51ee4b0ecc0d50 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 27 Aug 2014 17:35:19 -0600 Subject: [PATCH 039/298] Ensure Logger (Stdlib) is properly required Since we're referencing Logger::INFO in the Protobuf::Logging module, we need to ensure that Logger is properly required to avoid any load order issues. --- lib/protobuf/logging.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 78a5aea6..273d159d 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -1,3 +1,5 @@ +require 'logger' + module Protobuf module Logging def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) From 3105a05a287264e5e2bc47ff6c6421ec26dcdc71 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 27 Aug 2014 17:40:10 -0600 Subject: [PATCH 040/298] fix setsockopt use in specs --- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 16bd8ca4..7bec5332 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -17,6 +17,7 @@ before do allow(::ZMQ::Context).to receive(:new).and_return(zmq_context_double) + allow(socket_double).to receive(:setsockopt) end before(:all) do @@ -94,7 +95,7 @@ end it "returns true when the connection succeeds" do - expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil)) + expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil, :setsockopt => nil)) expect(subject.send(:host_alive?, "huzzah.com")).to be true end @@ -104,7 +105,7 @@ end it "closes the socket" do - socket = double("TCPSocket") + socket = double("TCPSocket", :setsockopt => nil) expect(socket).to receive(:close) expect(TCPSocket).to receive(:new).with("absorbalof.com", 3307).and_return(socket) expect(subject.send(:host_alive?, "absorbalof.com")).to be true From 27b38676a677d0f9fd7029f7259a53bc014ef136 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 27 Aug 2014 17:40:30 -0600 Subject: [PATCH 041/298] bump to 3.3.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index d0ad3c81..44438e84 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.1' + VERSION = '3.3.2' end From c4f1badaa7859aab2ac1ae08359668e84fa2e1f0 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 28 Aug 2014 14:37:02 -0600 Subject: [PATCH 042/298] Update to MIT license --- LICENSE.txt | 26 +++++++++++++++++--------- protobuf.gemspec | 2 +- 2 files changed, 18 insertions(+), 10 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index dd94252a..cddcfe29 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,14 +1,22 @@ - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - Version 2, December 2004 +The MIT License (MIT) -Copyright (C) 2004 Sam Hocevar +Copyright (c) 2014 BJ Neilsen -Everyone is permitted to copy and distribute verbatim or modified -copies of this license document, and changing it is allowed as long -as the name is changed. +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: - DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. - 0. You just DO WHAT THE FUCK YOU WANT TO. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/protobuf.gemspec b/protobuf.gemspec index bfec5bdb..0071c58a 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -6,7 +6,7 @@ require "protobuf/version" s.name = 'protobuf' s.version = ::Protobuf::VERSION s.date = ::Time.now.strftime('%Y-%m-%d') - s.license = 'WTFPL' + s.license = 'MIT' s.authors = ['BJ Neilsen', 'Brandon Dewitt', 'Devin Christensen', 'Adam Hutchison'] s.email = ['bj.neilsen+protobuf@gmail.com', 'brandonsdewitt+protobuf@gmail.com', 'quixoten@gmail.com', 'liveh2o@gmail.com'] From f7d0bbd4d4dcfcc4ecb6937943c12b9152fa61ca Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 12 Sep 2014 17:53:36 -0600 Subject: [PATCH 043/298] try to cut down on ping port traffic with health check interval --- lib/protobuf/rpc/connectors/zmq.rb | 25 ++++++++++++++++++++++++- protobuf.gemspec | 1 + 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a8499b1c..f097c450 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -1,3 +1,4 @@ +require 'thread_safe' require 'protobuf/rpc/connectors/base' require 'protobuf/rpc/service_directory' @@ -30,6 +31,10 @@ def self.zmq_context @zmq_contexts[Process.pid] end + def self.ping_port_responses + @ping_port_responses ||= ::ThreadSafe::Cache.new + end + ## # Instance methods # @@ -105,7 +110,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 5.times do + 15.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -115,6 +120,8 @@ def lookup_server_uri host = options[:host] port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) + + sleep (5.0/100.0) end raise "Host not found for service #{service}" @@ -122,6 +129,22 @@ def lookup_server_uri def host_alive?(host) return true unless ping_port_enabled? + + if (last_response = self.class.ping_port_responses[host]) + if (Time.now.to_i - last_response[:at]) <= 2 + return last_response[:ping_port_open] + end + end + + ping_port_open = ping_port_open?(host) + self.class.ping_port_responses[host] = { + :at => Time.now.to_i, + :ping_port_open => ping_port_open + } + ping_port_open + end + + def ping_port_open?(host) socket = TCPSocket.new(host, ping_port.to_i) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1,0].pack('ii')) diff --git a/protobuf.gemspec b/protobuf.gemspec index 0071c58a..2e3b254f 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -22,6 +22,7 @@ require "protobuf/version" s.add_dependency 'activesupport', '>= 3.2' s.add_dependency 'middleware' s.add_dependency 'thor' + s.add_dependency 'thread_safe' s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'pry-nav' From 646e5a13fa9e7727f00d18ea8af0ead749cabab2 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 12 Sep 2014 18:33:43 -0600 Subject: [PATCH 044/298] sweep every 5 instead of 1 and check backend before frontend and local_queue in between --- lib/protobuf/rpc/servers/zmq/broker.rb | 17 ++++------------- lib/protobuf/rpc/service_directory.rb | 2 +- 2 files changed, 5 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 93ef6e5e..0b759ae7 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -25,26 +25,17 @@ def run @idle_workers = [] loop do - unless local_queue.empty? - process_local_queue - end - + process_local_queue rc = @poller.poll(500) # The server was shutdown and no requests are pending break if rc == 0 && !running? - # Something went wrong break if rc == -1 - @poller.readables.each do |readable| - case readable - when @frontend_socket - process_frontend - when @backend_socket - process_backend - end - end + process_backend if @poller.readables.include?(@backend_socket) + process_local_queue # Fair ordering so queued requests get in before new requests + process_frontend if @poller.readables.include?(@frontend_socket) end ensure teardown diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 868e53be..cddc7a53 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -219,7 +219,7 @@ def reset end def run - sweep_interval = 1 # sweep expired listings every 1 second + sweep_interval = 5 # sweep expired listings every 5 seconds next_sweep = Time.now.to_i + sweep_interval loop do From 0987d524601964e372c750e7f62d87335d451196 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 10:18:21 -0600 Subject: [PATCH 045/298] shift off of local queue for ordered processing and concat instead of + for less copy --- lib/protobuf/rpc/servers/zmq/broker.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 0b759ae7..474217ff 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -104,9 +104,9 @@ def process_frontend end else if @idle_workers.empty? - local_queue.push([address, "", message ] + frames) + local_queue << [address, "", message ].concat(frames) else - write_to_backend([@idle_workers.shift, ""] + [address, "", message ] + frames) + write_to_backend([@idle_workers.shift, ""].concat([address, "", message ]).concat(frames)) end end end @@ -115,7 +115,7 @@ def process_local_queue return if local_queue.empty? return if @idle_workers.empty? - write_to_backend([@idle_workers.shift, ""] + local_queue.pop) + write_to_backend([@idle_workers.shift, ""].concat(local_queue.shift)) process_local_queue end From 71e59a99c344e019604548fa1c06652683a325dc Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 10:31:40 -0600 Subject: [PATCH 046/298] constantize the empty string --- lib/protobuf/rpc/servers/zmq/broker.rb | 10 +++++----- lib/protobuf/rpc/servers/zmq/util.rb | 1 + lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 474217ff..ce110592 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -98,15 +98,15 @@ def process_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE if local_queue.size < local_queue_max_size - write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) + write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else - write_to_frontend([address, "", ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) + write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) end else if @idle_workers.empty? - local_queue << [address, "", message ].concat(frames) + local_queue << [address, , message ].concat(frames) else - write_to_backend([@idle_workers.shift, ""].concat([address, "", message ]).concat(frames)) + write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ]).concat(frames)) end end end @@ -115,7 +115,7 @@ def process_local_queue return if local_queue.empty? return if @idle_workers.empty? - write_to_backend([@idle_workers.shift, ""].concat(local_queue.shift)) + write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat(local_queue.shift)) process_local_queue end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index af7dcde5..f16bbcfd 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -9,6 +9,7 @@ module Zmq CHECK_AVAILABLE_MESSAGE = "\3" NO_WORKERS_AVAILABLE = "\4" WORKERS_AVAILABLE = "\5" + EMPTY_STRING = "" module Util include ::Protobuf::Logging diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 6b3d5582..7ee35afc 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -31,7 +31,7 @@ def process_request gc_pause do encoded_response = handle_request(data) - write_to_backend([client_address, "", encoded_response]) + write_to_backend([client_address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, encoded_response]) end end From 278a297a57197110195928b3993df6982fb5a337 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 10:41:58 -0600 Subject: [PATCH 047/298] add empty to broker --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index ce110592..83eb41ab 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -104,7 +104,7 @@ def process_frontend end else if @idle_workers.empty? - local_queue << [address, , message ].concat(frames) + local_queue << [address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ].concat(frames) else write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ]).concat(frames)) end From 6df180f88552a067337e62ce5090483d79928380 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 11:42:09 -0600 Subject: [PATCH 048/298] let server shutdown the context when using a shared context via inproc --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- lib/protobuf/rpc/servers/zmq/worker.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 83eb41ab..5e86148c 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -134,7 +134,7 @@ def read_from_frontend def teardown @frontend_socket.try(:close) @backend_socket.try(:close) - @zmq_context.try(:terminate) + @zmq_context.try(:terminate) unless inproc? end def write_to_backend(frames) diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 7ee35afc..e0c28357 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -93,7 +93,7 @@ def read_from_backend def teardown @backend_socket.try(:close) - @zmq_context.try(:terminate) + @zmq_context.try(:terminate) unless inproc? end def write_to_backend(frames) From c5d73e91ed272f0e2225614a744b91778d421648 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 13 Sep 2014 12:10:05 -0600 Subject: [PATCH 049/298] bump to 3.3.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 44438e84..68723b0d 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.2' + VERSION = '3.3.3' end From 7452e8a7f0d49fceb1421cafa84d1a764bec8115 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 10:40:19 -0600 Subject: [PATCH 050/298] add configuration ENV vars for the values that have been hard-coded in the connector for zmq and the broker for zmq the poll weight influences how many messages will be pulled from the polling socket before it moves on to check the other socket, this is currently 2/1 weighted in favor of the backend socket (the work complete) Also made a configuration value of the number of attempts to make on getting the server uri on the client side --- lib/protobuf/rpc/connectors/zmq.rb | 17 +++++++++------ lib/protobuf/rpc/servers/zmq/broker.rb | 29 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index f097c450..f4fd0c67 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -75,10 +75,7 @@ def create_socket if socket # Make sure the context builds the socket socket.setsockopt(::ZMQ::LINGER, 0) - - logger.debug { sign_message("Establishing connection: #{server_uri}") } zmq_error_check(socket.connect(server_uri), :socket_connect) - logger.debug { sign_message("Connection established to #{server_uri}") } if first_alive_load_balance? begin @@ -110,7 +107,7 @@ def error? # to the host and port in the options # def lookup_server_uri - 15.times do + server_lookup_attempts.times do service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) @@ -121,7 +118,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep (5.0/100.0) + sleep (1.0/100.0) end raise "Host not found for service #{service}" @@ -131,7 +128,7 @@ def host_alive?(host) return true unless ping_port_enabled? if (last_response = self.class.ping_port_responses[host]) - if (Time.now.to_i - last_response[:at]) <= 2 + if (Time.now.to_i - last_response[:at]) <= host_alive_check_interval return last_response[:ping_port_open] end end @@ -144,6 +141,10 @@ def host_alive?(host) ping_port_open end + def host_alive_check_interval + @host_alive_check_interval ||= [ENV["PB_ZMQ_CLIENT_HOST_ALIVE_CHECK_INTERVAL"].to_i, 1].max + end + def ping_port_open?(host) socket = TCPSocket.new(host, ping_port.to_i) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) @@ -197,6 +198,10 @@ def send_request_with_timeout(timeout, attempt = 0) logger.debug { sign_message("Socket closed") } end + def server_lookup_attempts + @server_lookup_attempts ||= [ENV["PB_ZMQ_CLIENT_SERVER_LOOKUP_ATTEMPTS"].to_i, 5].max + end + # The service we're attempting to connect to # def service diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 5e86148c..2fed7b85 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -33,9 +33,26 @@ def run # Something went wrong break if rc == -1 - process_backend if @poller.readables.include?(@backend_socket) + readables_include_backend = @poller.readables.include?(@backend_socket) + message_count_read_from_backend = 0 + + while readables_include_backend && message_count_read_from_backend < backend_poll_weight do + message_count_read_from_backend = message_count_read_from_backend + 1 + process_backend + @poller.poll_nonblock + readables_include_backend = @poller.readables.include?(@backend_socket) + end + process_local_queue # Fair ordering so queued requests get in before new requests - process_frontend if @poller.readables.include?(@frontend_socket) + readables_include_frontend = @poller.readables.include?(@frontend_socket) + message_count_read_from_frontend = 0 + + while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do + message_count_read_from_frontend = message_count_read_from_frontend + 1 + process_frontend + @poller.poll_nonblock + readables_include_frontend = @poller.readables.include?(@frontend_socket) + end end ensure teardown @@ -47,6 +64,14 @@ def running? private + def backend_poll_weight + @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 2].max + end + + def frontend_poll_weight + @frontend_poll_weight ||= [ENV["PB_ZMQ_SERVER_FRONTEND_POLL_WEIGHT"].to_i, 1].max + end + def init_backend_socket @backend_socket = @zmq_context.socket(ZMQ::ROUTER) zmq_error_check(@backend_socket.bind(@server.backend_uri)) From f11bc3faeadd67acfcfdb498855609b34e62b47d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 13:25:58 -0600 Subject: [PATCH 051/298] set default backend poll weight to 1 to not change behavior of current --- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 2fed7b85..e398dfe5 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -65,7 +65,7 @@ def running? private def backend_poll_weight - @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 2].max + @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 1].max end def frontend_poll_weight From 0a6a86e32ca9bba8aaa676bb76d3546bfa42e5e4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 14:29:41 -0600 Subject: [PATCH 052/298] break from frontend poll if queue is full --- lib/protobuf/rpc/servers/zmq/broker.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index e398dfe5..140e4bda 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -50,6 +50,7 @@ def run while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do message_count_read_from_frontend = message_count_read_from_frontend + 1 process_frontend + break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full @poller.poll_nonblock readables_include_frontend = @poller.readables.include?(@frontend_socket) end @@ -104,6 +105,10 @@ def inproc? !!@server.try(:inproc?) end + def local_queue_available? + local_queue.size < local_queue_max_size + end + def local_queue_max_size @local_queue_max_size ||= [ENV["PB_ZMQ_SERVER_QUEUE_MAX_SIZE"].to_i, 5].max end @@ -122,7 +127,7 @@ def process_frontend address, _, message, *frames = read_from_frontend if message == ::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE - if local_queue.size < local_queue_max_size + if local_queue_available? write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::WORKERS_AVAILABLE]) else write_to_frontend([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE]) From eeb4e2977323071c61eb4526e8e1847bcb0d2a5a Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 17:12:15 -0600 Subject: [PATCH 053/298] clean up the `run` method --- lib/protobuf/rpc/servers/zmq/broker.rb | 47 +++++++++++++++----------- 1 file changed, 27 insertions(+), 20 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 140e4bda..89333742 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -33,27 +33,9 @@ def run # Something went wrong break if rc == -1 - readables_include_backend = @poller.readables.include?(@backend_socket) - message_count_read_from_backend = 0 - - while readables_include_backend && message_count_read_from_backend < backend_poll_weight do - message_count_read_from_backend = message_count_read_from_backend + 1 - process_backend - @poller.poll_nonblock - readables_include_backend = @poller.readables.include?(@backend_socket) - end - + check_and_process_backend process_local_queue # Fair ordering so queued requests get in before new requests - readables_include_frontend = @poller.readables.include?(@frontend_socket) - message_count_read_from_frontend = 0 - - while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do - message_count_read_from_frontend = message_count_read_from_frontend + 1 - process_frontend - break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full - @poller.poll_nonblock - readables_include_frontend = @poller.readables.include?(@frontend_socket) - end + check_and_process_frontend end ensure teardown @@ -69,6 +51,31 @@ def backend_poll_weight @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 1].max end + def check_and_process_backend + readables_include_backend = @poller.readables.include?(@backend_socket) + message_count_read_from_backend = 0 + + while readables_include_backend && message_count_read_from_backend < backend_poll_weight do + message_count_read_from_backend += 1 + process_backend + @poller.poll_nonblock + readables_include_backend = @poller.readables.include?(@backend_socket) + end + end + + def check_and_process_frontend + readables_include_frontend = @poller.readables.include?(@frontend_socket) + message_count_read_from_frontend = 0 + + while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do + message_count_read_from_frontend += 1 + process_frontend + break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full + @poller.poll_nonblock + readables_include_frontend = @poller.readables.include?(@frontend_socket) + end + end + def frontend_poll_weight @frontend_poll_weight ||= [ENV["PB_ZMQ_SERVER_FRONTEND_POLL_WEIGHT"].to_i, 1].max end From 7fd71e34b6fe6e4019c256340038121cab719aae Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 18:29:07 -0600 Subject: [PATCH 054/298] bump to 3.3.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 68723b0d..bd177730 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.3' + VERSION = '3.3.4' end From c096805c688d8c79639863b8c88aeaee98f7034e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 21:28:19 -0600 Subject: [PATCH 055/298] set timeout on socket when checking work avail --- lib/protobuf/rpc/connectors/zmq.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index f4fd0c67..efbc99d4 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -80,6 +80,8 @@ def create_socket if first_alive_load_balance? begin check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, 200) + socket.setsockopt(::ZMQ::SNDTIMEO, 200) zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) @@ -88,6 +90,9 @@ def create_socket end rescue ZmqRecoverableError socket = nil # couldn't make a connection and need to try again + else + socket.setsockopt(::ZMQ::RCVTIMEO, -1) + socket.setsockopt(::ZMQ::SNDTIMEO, -1) end end end From 811f727e510fc57658eda753dd04072aa8374daf Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 15 Sep 2014 22:52:00 -0600 Subject: [PATCH 056/298] add a global timeout that can be set for connections and move timeout mgmt to zeromq as it has facilities to handle timeout --- lib/protobuf/rpc/connectors/zmq.rb | 70 ++++++++++++++++++++++++------ 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index efbc99d4..58331536 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -8,6 +8,7 @@ module Connectors class Zmq < Base RequestTimeout = Class.new(RuntimeError) ZmqRecoverableError = Class.new(RuntimeError) + ZmqEagainError = Class.new(RuntimeError) ## # Included Modules @@ -58,6 +59,13 @@ def log_signature ## # Private Instance methods # + def check_available_rcv_timeout + @check_available_rcv_timeout ||= [ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_RCV_TIMEOUT"].to_i, 200].max + end + + def check_available_snd_timeout + @check_available_snd_timeout ||= [ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_SND_TIMEOUT"].to_i, 200].max + end def close_connection # The socket is automatically closed after every request. @@ -80,8 +88,8 @@ def create_socket if first_alive_load_balance? begin check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, 200) - socket.setsockopt(::ZMQ::SNDTIMEO, 200) + socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) + socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) @@ -180,23 +188,39 @@ def send_request_with_lazy_pirate end end + def rcv_timeout + @rcv_timeout ||= begin + if ENV.has_key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") + ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i + else + 300_000 # 300 seconds + end + end + end + + def snd_timeout + @snd_timeout ||= begin + if ENV.has_key?("PB_ZMQ_CLIENT_SND_TIMEOUT") + ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i + else + 300_000 # 300 seconds + end + end + end + def send_request_with_timeout(timeout, attempt = 0) socket = create_socket - - poller = ::ZMQ::Poller.new - poller.register_readable(socket) + socket.setsockopt(::ZMQ::RCVTIMEO, rcv_timeout) + socket.setsockopt(::ZMQ::SNDTIMEO, snd_timeout) logger.debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } - zmq_error_check(socket.send_string(@request_data), :socket_send_string) + zmq_eagain_error_check(socket.send_string(@request_data), :socket_send_string) logger.debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } - - if poller.poll(timeout * 1000) == 1 - zmq_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) - logger.debug { sign_message("Response received (attempt #{attempt}, #{socket})") } - else - logger.debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } - raise RequestTimeout - end + zmq_eagain_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) + logger.debug { sign_message("Response received (attempt #{attempt}, #{socket})") } + rescue ZmqEagainError + logger.debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } + raise RequestTimeout ensure logger.debug { sign_message("Closing Socket") } zmq_error_check(socket.close, :socket_close) if socket @@ -226,6 +250,24 @@ def zmq_context self.class.zmq_context end + def zmq_eagain_error_check(return_code, source) + unless ::ZMQ::Util.resultcode_ok?(return_code || -1) + if ::ZMQ::Util.errno == ::ZMQ::EAGAIN + raise ZmqEagainError, <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + else + raise <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($/)} + ERROR + end + end + end + def zmq_error_check(return_code, source) unless ::ZMQ::Util.resultcode_ok?(return_code || -1) raise <<-ERROR From 68bac991e4060eba29702f241d924a66eff8365c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 16 Sep 2014 09:48:41 -0600 Subject: [PATCH 057/298] move "default timeout" out of options and have it be env and overridable --- lib/protobuf/rpc/connectors/base.rb | 4 ++-- lib/protobuf/rpc/connectors/common.rb | 12 ++++++++++-- lib/protobuf/rpc/connectors/zmq.rb | 17 +++++++++++------ 3 files changed, 23 insertions(+), 10 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 9f7735ab..c2a6b9d6 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -17,9 +17,9 @@ module Connectors :request => nil, # The request object sent by the client :request_type => nil, # The request type expected by the client :response_type => nil, # The response type expected by the client - :timeout => 300, # The default timeout for the request, also handled by client.rb + :timeout => nil, # The timeout for the request, also handled by client.rb :client_host => nil, # The hostname or address of this client - :first_alive_load_balance => false, # Do we want to use check_avail frames before request + :first_alive_load_balance => false, # Do we want to use check_avail frames before request } class Base diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 8c7a84cd..2ef5b9a1 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -135,12 +135,20 @@ def succeed(response) complete end + def timeout + if options[:timeout] + options[:timeout] + else + 300 # seconds + end + end + # Wrap the given block in a timeout of the configured number of seconds. # def timeout_wrap(&block) - ::Timeout.timeout(options[:timeout], &block) + ::Timeout.timeout(timeout, &block) rescue ::Timeout::Error - fail(:RPC_FAILED, "The server took longer than #{options[:timeout]} seconds to respond") + fail(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond") end def validate_request_type! diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 58331536..da7e9cd3 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -176,11 +176,10 @@ def ping_port_open?(host) # def send_request_with_lazy_pirate attempt = 0 - timeout = options[:timeout].to_f begin attempt += 1 - send_request_with_timeout(timeout, attempt) + send_request_with_timeout(attempt) parse_response rescue RequestTimeout retry if attempt < CLIENT_RETRIES @@ -190,7 +189,10 @@ def send_request_with_lazy_pirate def rcv_timeout @rcv_timeout ||= begin - if ENV.has_key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") + case + when options[:timeout] then + options[:timeout] + when ENV.has_key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i else 300_000 # 300 seconds @@ -200,7 +202,10 @@ def rcv_timeout def snd_timeout @snd_timeout ||= begin - if ENV.has_key?("PB_ZMQ_CLIENT_SND_TIMEOUT") + case + when options[:timeout] then + options[:timeout] + when ENV.has_key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i else 300_000 # 300 seconds @@ -208,14 +213,14 @@ def snd_timeout end end - def send_request_with_timeout(timeout, attempt = 0) + def send_request_with_timeout(attempt = 0) socket = create_socket socket.setsockopt(::ZMQ::RCVTIMEO, rcv_timeout) socket.setsockopt(::ZMQ::SNDTIMEO, snd_timeout) logger.debug { sign_message("Sending Request (attempt #{attempt}, #{socket})") } zmq_eagain_error_check(socket.send_string(@request_data), :socket_send_string) - logger.debug { sign_message("Waiting #{timeout} seconds for response (attempt #{attempt}, #{socket})") } + logger.debug { sign_message("Waiting #{rcv_timeout}ms for response (attempt #{attempt}, #{socket})") } zmq_eagain_error_check(socket.recv_string(@response_data = ""), :socket_recv_string) logger.debug { sign_message("Response received (attempt #{attempt}, #{socket})") } rescue ZmqEagainError From dbf700a05b394e26da31b38ecb8697ec975d1240 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 16 Sep 2014 11:26:00 -0600 Subject: [PATCH 058/298] bump to 3.3.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index bd177730..b5918f09 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.4' + VERSION = '3.3.5' end From 720a8624293c815ac7b8ba25cc2219c145aae731 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 09:56:28 -0700 Subject: [PATCH 059/298] Travis tests latest 2.1 --- .travis.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index b2e5e625..58ed2fde 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,8 +1,8 @@ language: ruby rvm: - - "1.9.3" - - "2.0.0" - - "2.1.1" + - 1.9.3 + - 2.0.0 + - 2.1 script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec/lib notifications: webhooks: From 731f61b8902aea758eb42b63ff83c5e5b71b708f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 09:56:45 -0700 Subject: [PATCH 060/298] PerfTools is dead, long live RubyProf --- protobuf.gemspec | 8 +++++--- spec/benchmark/tasks.rb | 38 ++++++++++++++++++++++++++++++-------- 2 files changed, 35 insertions(+), 11 deletions(-) diff --git a/protobuf.gemspec b/protobuf.gemspec index 2e3b254f..0a105c7d 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -25,11 +25,13 @@ require "protobuf/version" s.add_dependency 'thread_safe' s.add_development_dependency 'ffi-rzmq' - s.add_development_dependency 'pry-nav' + s.add_development_dependency 'pry' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' s.add_development_dependency 'simplecov' - s.add_development_dependency 'yard' s.add_development_dependency 'timecop' - s.add_development_dependency 'perftools.rb' + s.add_development_dependency 'yard' + + s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby + s.add_development_dependency 'pry-nav' unless RUBY_ENGINE.to_sym == :rbx end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index f90554fd..313a9da8 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -3,11 +3,13 @@ require 'support/all' require 'support/test/resource_service' -begin - require 'perftools' -rescue LoadError - $stderr.puts 'perftools must be uncommented in the gemspec before you can run this benchmark task' - exit(1) +case RUBY_ENGINE.to_sym +when :ruby + require 'ruby-prof' +when :rbx + require 'rubinius/profiler' +when :jruby + require 'jruby/profiler' end # Including a way to turn on debug logger for spec runs @@ -66,7 +68,8 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) desc "benchmark ZMQ client with ZMQ server and profile" task :zmq_profile, [:number, :length, :profile_output] do |t, args| args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}") - ::PerfTools::CpuProfiler.start(args[:profile_output]) do + + profile_code(args[:profile_output]) do zmq_client_zmq_server(args[:number], args[:length]) end @@ -77,7 +80,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) task :profile_protobuf_new, [:number, :profile_output] do |t, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } - ::PerfTools::CpuProfiler.start(args[:profile_output]) do + profile_code(args[:profile_output]) do args[:number].to_i.times { Test::Resource.new(create_params) } end @@ -88,13 +91,32 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) task :profile_protobuf_serialize, [:number, :profile_output] do |t, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } - ::PerfTools::CpuProfiler.start(args[:profile_output]) do + profile_code(args[:profile_output]) do args[:number].to_i.times { Test::Resource.new(create_params).serialize } end puts args[:profile_output] end + def profile_code(output, &block) + case RUBY_ENGINE.to_sym + when :ruby + profile_data = RubyProf.profile(&block) + RubyProf::FlatPrinter.new(profile_data).print(:path => output) + when :rbx + profiler = Rubinius::Profiler::Instrumenter.new + profiler.profile(false, &block) + File.open(output, 'w') do |f| + profiler.show(f) + end + when :jruby + profile_data = JRuby::Profiler.profile(&block) + File.open(output, 'w') do |f| + JRuby::Profiler::FlatProfilePrinter.new(profile_data).printProfile(f) + end + end + end + desc "benchmark Socket client with Socket server" task :sock_client_sock_server, [:number, :length] do |t, args| args.with_defaults(:number => 1000, :length => 100) From 78940bc8e3e1aeaebe941457046e82084335118a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 10:04:48 -0700 Subject: [PATCH 061/298] Actually run tests in travis --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 58ed2fde..ba6460cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ rvm: - 1.9.3 - 2.0.0 - 2.1 -script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake spec/lib +script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake notifications: webhooks: urls: From 3bd041450a1e09c700c566e8b3967de87235430c Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 10:08:36 -0700 Subject: [PATCH 062/298] These error messages were updated --- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index ffeecc7b..51784817 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -42,7 +42,7 @@ c.on_failure {|e| error = e} end - expect(error.message).to match(/name.*required/) + expect(error.message).to match(/Required field.*does not have a value/) end it 'calls the on_failure callback when the request type is wrong' do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 053eb383..c2fbcd79 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -69,7 +69,7 @@ c.on_success { raise "shouldn't pass" } c.on_failure {|e| error = e } end - expect(error.message).to match(/name.*required/) + expect(error.message).to match(/Required field.*does not have a value/) end end From 1dc660deec27728ad244e39c9b00b5405405e85d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 11:26:57 -0700 Subject: [PATCH 063/298] 646e5a1 changed this check interval to 5 seconds --- spec/lib/protobuf/rpc/service_directory_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 350f9f74..577fbe8e 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -198,7 +198,7 @@ def send_beacon(type, server) it "should not return expired listings" do send_beacon(:heartbeat, hello_server_with_short_ttl) - sleep 1 + sleep 5 expect(subject.lookup("HelloService")).to be_nil end From 6dcb0fa3c94ef2ff2fbe85c1bdeff74acbbb5923 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 22:37:06 -0700 Subject: [PATCH 064/298] Order matters! --- lib/protobuf/message/fields.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 2e6afab8..30023e6a 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -45,7 +45,7 @@ def extensions(range) # def all_fields - @all_fields ||= field_store.values.uniq + @all_fields ||= field_store.values.uniq.sort_by(&:tag) end def extension_fields From 8e087ce31b472d4b3bc8c86f0852dc703f3fe188 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 22:45:41 -0700 Subject: [PATCH 065/298] Need some libzmq --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index ba6460cf..63fdd050 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,3 +1,4 @@ +before_install: sudo apt-get install libzmq3-dev language: ruby rvm: - 1.9.3 From aeb77c17218053d0316703f0eca5a4b243150c2a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 29 Sep 2014 22:48:38 -0700 Subject: [PATCH 066/298] More rubies --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index 63fdd050..8cbe3331 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,12 @@ rvm: - 1.9.3 - 2.0.0 - 2.1 + - jruby + - rbx-2 +matrix: + allow_failures: + - rvm: jruby + - rvm: rbx-2 script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake notifications: webhooks: From b378b738b2f529936ea8b346f9ef15c245bab102 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 30 Sep 2014 00:05:31 -0700 Subject: [PATCH 067/298] `StringIO#set_encoding` returns a string in RBX --- lib/protobuf/message/serialization.rb | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index bfe58faf..05e3c1b8 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -44,8 +44,10 @@ def decode_from(stream) # Encode this message # def encode - stream = ::StringIO.new.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream).string + ::StringIO.new.tap do |stream| + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + end.string end # Encode this message to the given stream. @@ -81,4 +83,3 @@ def set_field_bytes(tag, bytes) end end end - From c5572080e7d9d643c4922e9b289282cc39bea987 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Wed, 1 Oct 2014 23:20:57 -0600 Subject: [PATCH 068/298] Fix flakey spec by closing write pipe, generating an empty test module Signed-off-by: Tamir Duberstein --- spec/bin/protoc-gen-ruby_spec.rb | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/spec/bin/protoc-gen-ruby_spec.rb b/spec/bin/protoc-gen-ruby_spec.rb index 36cd7add..cbbce0da 100644 --- a/spec/bin/protoc-gen-ruby_spec.rb +++ b/spec/bin/protoc-gen-ruby_spec.rb @@ -4,15 +4,20 @@ describe 'protoc-gen-ruby' do let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) } - let(:request_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.new(:file_to_generate => [ "test/foo.proto" ]) } - let(:expected_file) { ::Google::Protobuf::Compiler::CodeGeneratorResponse::File.new(:name => 'test/foo.pb.rb') } - let(:expected_response_bytes) { ::Google::Protobuf::Compiler::CodeGeneratorRequest.encode(:files => [ expected_file ]) } + let(:package) { 'test' } + let(:request_bytes) do + ::Google::Protobuf::Compiler::CodeGeneratorRequest.encode( + :proto_file => [{ :package => package }], + ) + end it 'reads the serialized request bytes and outputs serialized response bytes' do ::IO.popen(binpath, 'w+') do |pipe| pipe.write(request_bytes) - expect(pipe.read(expected_response_bytes.size)).to eq expected_response_bytes + pipe.close_write # needed so we can implicitly read until EOF + response_bytes = pipe.read + response = ::Google::Protobuf::Compiler::CodeGeneratorResponse.decode(response_bytes) + expect(response.file.first.content).to include("module #{package.titleize}") end end end - From 432e68b87adc3e70379e1fd17e792b090fc3c568 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Thu, 2 Oct 2014 22:43:15 -0600 Subject: [PATCH 069/298] Cleanup shutdown procedure --- lib/protobuf/rpc/servers/zmq/broker.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 89333742..7f79e5be 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -29,7 +29,7 @@ def run rc = @poller.poll(500) # The server was shutdown and no requests are pending - break if rc == 0 && !running? + break if rc == 0 && !running? && @server.workers.empty? # Something went wrong break if rc == -1 @@ -42,7 +42,7 @@ def run end def running? - @server.running? || @server.workers.any? + @server.running? end private @@ -113,7 +113,7 @@ def inproc? end def local_queue_available? - local_queue.size < local_queue_max_size + local_queue.size < local_queue_max_size && running? end def local_queue_max_size From 4aa9f04e19d6d8305462c345c152914c6d475cef Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 8 Oct 2014 18:36:30 -0600 Subject: [PATCH 070/298] Force exit after clean shutdown --- lib/protobuf/cli.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index ad0716c6..2eb72218 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -219,7 +219,6 @@ def shutdown_server logger.info { 'RPC Server shutting down...' } @runner.try(:stop) ::Protobuf::Rpc::ServiceDirectory.instance.stop - logger.info { 'Shutdown complete' } end # Start the runner and log the relevant options. @@ -233,6 +232,10 @@ def start_server ::ActiveSupport::Notifications.instrument("after_server_bind") end + + logger.info { 'Shutdown complete' } + + exit 0 end end end From 0a357a5f11aa5bc5ef0792cc36c7f6535fd6676f Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Fri, 10 Oct 2014 15:45:42 -0600 Subject: [PATCH 071/298] Bump version to v3.3.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index b5918f09..8dfbb929 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.5' + VERSION = '3.3.6' end From 96248f5667fa63a947452b4200a66eb668d664db Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:42:27 -0700 Subject: [PATCH 072/298] actually compile the protos --- .travis.yml | 6 ++++-- install-protobuf.sh | 8 ++++++++ spec/spec_helper.rb | 11 +++-------- 3 files changed, 15 insertions(+), 10 deletions(-) create mode 100755 install-protobuf.sh diff --git a/.travis.yml b/.travis.yml index 8cbe3331..61185537 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,7 @@ -before_install: sudo apt-get install libzmq3-dev +before_install: + - sudo apt-get update -qq + - sudo apt-get install -y libzmq3-dev + - sudo ./install-protobuf.sh language: ruby rvm: - 1.9.3 @@ -10,7 +13,6 @@ matrix: allow_failures: - rvm: jruby - rvm: rbx-2 -script: NO_COMPILE_TEST_PROTOS=1 bundle exec rake notifications: webhooks: urls: diff --git a/install-protobuf.sh b/install-protobuf.sh new file mode 100755 index 00000000..22488b28 --- /dev/null +++ b/install-protobuf.sh @@ -0,0 +1,8 @@ +set -ex + +basename=protobuf-2.6.0 +tarball=$basename.tar.bz2 + +wget https://protobuf.googlecode.com/svn/rc/$tarball +tar -xvf $tarball +cd $basename && ./configure --prefix=/usr && make && make install diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index fa22f2ce..20cd2fe4 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -27,15 +27,10 @@ ENV.delete("PB_IGNORE_DEPRECATIONS") ::RSpec.configure do |c| - c.mock_with :rspec - c.before(:suite) do - unless ENV['NO_COMPILE_TEST_PROTOS'] - require 'rake' - load ::File.expand_path('../../Rakefile', __FILE__) - $stdout.puts 'Compiling test protos (use NO_COMPILE_TEST_PROTOS=1 to skip)' - ::Rake::Task['compile:spec'] - end + require 'rake' + load ::File.expand_path('../../Rakefile', __FILE__) + ::Rake::Task['compile:spec'].invoke end end From f4d14bd86df9f7d40c9791602b2f30411b16caab Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:21:34 -0700 Subject: [PATCH 073/298] Add RuboCop --- .rubocop.yml | 13 ++ .rubocop_todo.yml | 422 ++++++++++++++++++++++++++++++++++++++++++++++ Rakefile | 7 +- protobuf.gemspec | 1 + 4 files changed, 440 insertions(+), 3 deletions(-) create mode 100644 .rubocop.yml create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 00000000..20b78655 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,13 @@ +inherit_from: .rubocop_todo.yml + +Lint/Loop: + Enabled: false + +Style/CaseIndentation: + IndentWhenRelativeTo: end + +Style/IndentHash: + EnforcedStyle: consistent + +Style/TrailingComma: + EnforcedStyleForMultiline: comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000..8ffb2799 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,422 @@ +# This configuration was generated by `rubocop --auto-gen-config` +# on 2014-10-14 08:30:47 -0700 using RuboCop version 0.26.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 3 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Lint/BlockAlignment: + Enabled: false + +# Offense count: 2 +Lint/ParenthesesAsGroupedExpression: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Lint/StringConversionInInterpolation: + Enabled: false + +# Offense count: 1 +Lint/UnderscorePrefixedVariableName: + Enabled: false + +# Offense count: 27 +# Cop supports --auto-correct. +Lint/UnusedBlockArgument: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Lint/UnusedMethodArgument: + Enabled: false + +# Offense count: 8 +Lint/UselessAssignment: + Enabled: false + +# Offense count: 3 +Metrics/BlockNesting: + Max: 5 + +# Offense count: 9 +# Configuration parameters: CountComments. +Metrics/ClassLength: + Max: 236 + +# Offense count: 3 +Metrics/CyclomaticComplexity: + Max: 11 + +# Offense count: 515 +# Configuration parameters: AllowURI, URISchemes. +Metrics/LineLength: + Max: 196 + +# Offense count: 45 +# Configuration parameters: CountComments. +Metrics/MethodLength: + Max: 41 + +# Offense count: 2 +# Configuration parameters: CountKeywordArgs. +Metrics/ParameterLists: + Max: 6 + +# Offense count: 2 +Metrics/PerceivedComplexity: + Max: 12 + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/AccessModifierIndentation: + Enabled: false + +# Offense count: 2 +Style/AccessorMethodName: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Style/AlignArray: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/AndOr: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/BarePercentLiterals: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +Style/BlockEndNewline: + Enabled: false + +# Offense count: 67 +# Cop supports --auto-correct. +Style/Blocks: + Enabled: false + +# Offense count: 15 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/BracesAroundHashParameters: + Enabled: false + +# Offense count: 4 +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/ClassAndModuleChildren: + Enabled: false + +# Offense count: 9 +# Cop supports --auto-correct. +# Configuration parameters: PreferredMethods. +Style/CollectionMethods: + Enabled: false + +# Offense count: 5 +# Configuration parameters: Keywords. +Style/CommentAnnotation: + Enabled: false + +# Offense count: 5 +# Cop supports --auto-correct. +Style/DeprecatedHashMethods: + Enabled: false + +# Offense count: 191 +Style/Documentation: + Enabled: false + +# Offense count: 15 +Style/DoubleNegation: + Enabled: false + +# Offense count: 2 +Style/EachWithObject: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: AllowAdjacentOneLineDefs. +Style/EmptyLineBetweenDefs: + Enabled: false + +# Offense count: 35 +# Cop supports --auto-correct. +Style/EmptyLines: + Enabled: false + +# Offense count: 10 +# Cop supports --auto-correct. +Style/EmptyLinesAroundAccessModifier: + Enabled: false + +# Offense count: 146 +# Cop supports --auto-correct. +Style/EmptyLinesAroundBody: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/EmptyLiteral: + Enabled: false + +# Offense count: 2 +# Configuration parameters: Exclude. +Style/FileName: + Enabled: false + +# Offense count: 20 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Enabled: false + +# Offense count: 672 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/HashSyntax: + Enabled: false + +# Offense count: 2 +# Configuration parameters: MaxLineLength. +Style/IfUnlessModifier: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Style/IndentationConsistency: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/IndentationWidth: + Enabled: false + +# Offense count: 14 +Style/Lambda: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/LeadingCommentSpace: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/MethodDefParentheses: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Style/MultilineBlockLayout: + Enabled: false + +# Offense count: 3 +# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. +Style/Next: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: IncludeSemanticChanges. +Style/NonNilCheck: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/Not: + Enabled: false + +# Offense count: 46 +# Cop supports --auto-correct. +Style/NumericLiterals: + MinDigits: 21 + +# Offense count: 1 +Style/OpMethod: + Enabled: false + +# Offense count: 15 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Enabled: false + +# Offense count: 7 +# Configuration parameters: NamePrefix, NamePrefixBlacklist. +Style/PredicateName: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +Style/Proc: + Enabled: false + +# Offense count: 8 +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/RaiseArgs: + Enabled: false + +# Offense count: 1 +Style/RedundantException: + Enabled: false + +# Offense count: 20 +# Cop supports --auto-correct. +# Configuration parameters: AllowMultipleReturnValues. +Style/RedundantReturn: + Enabled: false + +# Offense count: 26 +# Cop supports --auto-correct. +Style/RedundantSelf: + Enabled: false + +# Offense count: 2 +Style/RescueModifier: + Enabled: false + +# Offense count: 1 +Style/SelfAssignment: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: AllowAsExpressionSeparator. +Style/Semicolon: + Enabled: false + +# Offense count: 66 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SignalException: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: AllowIfMethodIsEmpty. +Style/SingleLineMethods: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/SpaceAfterColon: + Enabled: false + +# Offense count: 9 +# Cop supports --auto-correct. +Style/SpaceAfterComma: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Style/SpaceAfterNot: + Enabled: false + +# Offense count: 17 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SpaceAroundEqualsInParameterDefault: + Enabled: false + +# Offense count: 1 +# Cop supports --auto-correct. +Style/SpaceAroundOperators: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/SpaceBeforeBlockBraces: + Enabled: false + +# Offense count: 14 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +Style/SpaceInsideBlockBraces: + Enabled: false + +# Offense count: 134 +# Cop supports --auto-correct. +Style/SpaceInsideBrackets: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. +Style/SpaceInsideHashLiteralBraces: + Enabled: false + +# Offense count: 8 +# Cop supports --auto-correct. +Style/SpaceInsideParens: + Enabled: false + +# Offense count: 12 +# Cop supports --auto-correct. +Style/SpecialGlobalVars: + Enabled: false + +# Offense count: 464 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/StringLiterals: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +Style/Tab: + Enabled: false + +# Offense count: 57 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/TrailingBlankLines: + Enabled: false + +# Offense count: 35 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. +Style/TrailingComma: + Enabled: false + +# Offense count: 12 +# Cop supports --auto-correct. +# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist. +Style/TrivialAccessors: + Enabled: false + +# Offense count: 1 +Style/UnlessElse: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Style/UnneededPercentQ: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/WhileUntilDo: + Enabled: false + +# Offense count: 4 +# Cop supports --auto-correct. +Style/WordArray: + MinSize: 2 diff --git a/Rakefile b/Rakefile index d32e29e3..d5feb73f 100644 --- a/Rakefile +++ b/Rakefile @@ -8,11 +8,12 @@ require 'bundler/gem_tasks' require 'benchmark/tasks' require 'rspec/core/rake_task' - -desc 'Default: run specs.' -task :default => :spec +require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) +RuboCop::RakeTask.new + +task :default => [:spec, :rubocop] desc 'Run specs' namespace :compile do diff --git a/protobuf.gemspec b/protobuf.gemspec index 0a105c7d..495a8aa7 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -28,6 +28,7 @@ require "protobuf/version" s.add_development_dependency 'pry' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' + s.add_development_dependency 'rubocop' s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' s.add_development_dependency 'yard' From 3f8587a617479737e298541619228d3fe9955642 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:27:25 -0700 Subject: [PATCH 074/298] Lint/AssignmentInCondition --- .rubocop_todo.yml | 5 ----- lib/protobuf/message.rb | 4 ++-- lib/protobuf/rpc/servers/zmq/server.rb | 13 ++++--------- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8ffb2799..bbb5b46a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 3 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Enabled: false - # Offense count: 1 # Cop supports --auto-correct. Lint/BlockAlignment: diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 4d1df27c..a608898a 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -128,13 +128,13 @@ def ==(obj) end def [](name) - if field = self.class.get_field(name, true) + if (field = self.class.get_field(name, true)) __send__(field.getter) end end def []=(name, value) - if field = self.class.get_field(name, true) + if (field = self.class.get_field(name, true)) __send__(field.setter, value) unless value.nil? else unless ::Protobuf.ignore_unknown_fields? diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c45c487f..2264f44b 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -62,15 +62,10 @@ def beacon_ip end def beacon_port - unless @beacon_port - unless port = options[:beacon_port] - port = ::Protobuf::Rpc::ServiceDirectory.port - end - - @beacon_port = port.to_i - end - - @beacon_port + @beacon_port ||= options.fetch( + :beacon_port, + ::Protobuf::Rpc::ServiceDirectory.port, + ).to_i end def beacon_uri From 2d89a19582847ed425fef93dcd38fffcc655d00c Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:28:41 -0700 Subject: [PATCH 075/298] Lint/BlockAlignment --- .rubocop_todo.yml | 5 ----- .../protobuf/generators/enum_generator_spec.rb | 15 ++++++++------- 2 files changed, 8 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bbb5b46a..45bf1278 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -# Cop supports --auto-correct. -Lint/BlockAlignment: - Enabled: false - # Offense count: 2 Lint/ParenthesesAsGroupedExpression: Enabled: false diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index a2dbbb0d..1521ced4 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -22,23 +22,25 @@ describe '#compile' do let(:compiled) { - %q{class TestEnum < ::Protobuf::Enum + <<-RUBY +class TestEnum < ::Protobuf::Enum define :FOO, 1 define :BAR, 2 define :BAZ, 3 end -} + RUBY } - it 'compiles the enum and it\'s field values' do + it 'compiles the enum and its field values' do subject.compile expect(subject.to_s).to eq(compiled) end context 'when allow_alias option is set' do let(:compiled) { - %q{class TestEnum < ::Protobuf::Enum + <<-RUBY +class TestEnum < ::Protobuf::Enum set_option :allow_alias define :FOO, 1 @@ -46,8 +48,8 @@ define :BAZ, 3 end -} - } + RUBY + } let(:options) { { :allow_alias => true } } @@ -65,4 +67,3 @@ end end - From 8c5a073b7d5b2d3e61141496fc150a4b2c5e5aad Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:31:37 -0700 Subject: [PATCH 076/298] Lint/ParenthesesAsGroupedExpression --- .rubocop_todo.yml | 4 ---- lib/protobuf/rpc/connectors/zmq.rb | 2 +- spec/support/test/resource_service.rb | 2 +- 3 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 45bf1278..87ea6d32 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,10 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -Lint/ParenthesesAsGroupedExpression: - Enabled: false - # Offense count: 2 # Cop supports --auto-correct. Lint/StringConversionInInterpolation: diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index da7e9cd3..5b2dbd24 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -131,7 +131,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep (1.0/100.0) + sleep(1.0/100.0) end raise "Host not found for service #{service}" diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb index 226ea0da..41e2f93a 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/test/resource_service.rb @@ -13,7 +13,7 @@ def find # request -> Test::ResourceSleepRequest # response -> Test::Resource def find_with_sleep - sleep (request.sleep || 1) + sleep(request.sleep || 1) response.name = 'Request should have timed out' end From c01eccf18d8cb1dd37a99a0ee172688be0f2faf1 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:32:04 -0700 Subject: [PATCH 077/298] Lint/StringConversionInInterpolation --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/client.rb | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 87ea6d32..dc358eec 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 2 -# Cop supports --auto-correct. -Lint/StringConversionInInterpolation: - Enabled: false - # Offense count: 1 Lint/UnderscorePrefixedVariableName: Enabled: false diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 373e3b0e..57fc6b57 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -106,10 +106,10 @@ def on_success=(callable) def method_missing(method_name, *params) service = options[:service] unless service.rpc_method?(method_name) - logger.error { sign_message("#{service.name}##{method_name.to_s} not rpc method, passing to super") } + logger.error { sign_message("#{service.name}##{method_name} not rpc method, passing to super") } super(method_name, *params) else - logger.debug { sign_message("#{service.name}##{method_name.to_s}") } + logger.debug { sign_message("#{service.name}##{method_name}") } rpc = service.rpcs[method_name.to_sym] options[:request_type] = rpc.request_type From 1c568743e8a9b9f65077e8b182c21d936d83075f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:33:06 -0700 Subject: [PATCH 078/298] Lint/UnderscorePrefixedVariableName --- .rubocop_todo.yml | 4 ---- spec/lib/protobuf/rpc/connectors/common_spec.rb | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index dc358eec..6e1bb454 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,10 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 1 -Lint/UnderscorePrefixedVariableName: - Enabled: false - # Offense count: 27 # Cop supports --auto-correct. Lint/UnusedBlockArgument: diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index ce839263..1b945222 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -133,10 +133,10 @@ stats = double("Object") allow(stats).to receive(:stop).and_return(true) subject.stats = stats - _cb = double("Object") + some_cb = double("Object") - subject.instance_variable_set("@#{cb}", _cb) - expect(_cb).to receive(:call).and_return(true) + subject.instance_variable_set("@#{cb}", some_cb) + expect(some_cb).to receive(:call).and_return(true) subject.method(meth).call(*args) end From 2d72baafe11b4635734495bcb5a2e01199521123 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:39:00 -0700 Subject: [PATCH 079/298] Lint/UnusedBlockArgument --- .rubocop_todo.yml | 5 ----- Rakefile | 4 ++-- lib/protobuf/generators/file_generator.rb | 9 ++++----- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- lib/protobuf/tasks/compile.rake | 4 ++-- spec/benchmark/tasks.rb | 14 +++++++------- spec/functional/zmq_server_spec.rb | 4 ++-- spec/lib/protobuf/rpc/service_filters_spec.rb | 8 ++++---- 10 files changed, 25 insertions(+), 31 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6e1bb454..4799377e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 27 -# Cop supports --auto-correct. -Lint/UnusedBlockArgument: - Enabled: false - # Offense count: 6 # Cop supports --auto-correct. Lint/UnusedMethodArgument: diff --git a/Rakefile b/Rakefile index d5feb73f..30f57c70 100644 --- a/Rakefile +++ b/Rakefile @@ -19,7 +19,7 @@ desc 'Run specs' namespace :compile do desc 'Compile spec protos in spec/supprt/ directory' - task :spec do |task, args| + task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} @@ -28,7 +28,7 @@ namespace :compile do end desc 'Compile rpc protos in protos/ directory' - task :rpc do |task, args| + task :rpc do proto_path = ::File.expand_path('../proto', __FILE__) output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 86ee0b44..63fb9412 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -23,7 +23,6 @@ def file_name def compile run_once(:compile) do map_extensions(descriptor, [ descriptor.package ]) - extract_dangling_extensions print_file_comment print_generic_requires @@ -34,7 +33,7 @@ def compile group.add_enums(descriptor.enum_type, :namespace => [ descriptor.package ]) group.add_message_declarations(descriptor.message_type) group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [ descriptor.package ]) - group.add_extended_messages(@unknown_extensions) + group.add_extended_messages(unknown_extensions) group.add_services(descriptor.service) group.add_header(:enum, 'Enum Classes') @@ -48,9 +47,9 @@ def compile end end - def extract_dangling_extensions - @unknown_extensions = @extension_fields.select do |k, v| - ! @known_messages.include?(k) + def unknown_extensions + @unknown_extensions ||= @extension_fields.reject do |k, _| + @known_messages.include?(k) end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index b1c2fa2c..a4d6e9a4 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -13,7 +13,7 @@ def self.register(event_name, &blk) ERROR end - ::ActiveSupport::Notifications.subscribe(event_name) do |name, start, finish, id, args| + ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| blk.call(*args) end end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index cddc7a53..10735e25 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -204,7 +204,7 @@ def remove_listing(uuid) logger.debug { sign_message("Removing listing: #{listing.inspect}") } - @listings_by_service.each do |service, listings| + @listings_by_service.each_value do |listings| listings.delete(listing) end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 6eab5654..14be45b2 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -120,7 +120,7 @@ def invoke_via_except?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_if?(rpc_method, filter) - if_check = filter.fetch(:if) { lambda { |service| return true } } + if_check = filter.fetch(:if) { lambda { |_service| return true } } do_invoke = case when if_check.nil? then true @@ -150,7 +150,7 @@ def invoke_via_only?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_unless?(rpc_method, filter) - unless_check = filter.fetch(:unless) { lambda { |service| return false } } + unless_check = filter.fetch(:unless) { lambda { |_service| return false } } skip_invoke = case when unless_check.nil? then false diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index 756fdc44..603a3efc 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -3,7 +3,7 @@ require 'fileutils' namespace :protobuf do desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.' - task :compile, [ :package, :source, :destination, :plugin, :file_extension ] do |tasks, args| + task :compile, [ :package, :source, :destination, :plugin, :file_extension ] do |_tasks, args| args.with_defaults(:destination => 'lib') args.with_defaults(:source => 'definitions') args.with_defaults(:plugin => 'ruby') @@ -27,7 +27,7 @@ namespace :protobuf do end desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.' - task :clean, [ :package, :destination, :file_extension ] do |task, args| + task :clean, [ :package, :destination, :file_extension ] do |_task, args| args.with_defaults(:destination => 'lib') args.with_defaults(:file_extension => '.pb.rb') diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 313a9da8..899e882a 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -34,7 +34,7 @@ def benchmark_wrapper(global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |server| + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |_server| client = ::Test::ResourceService.client(:port => 9399) benchmark_wrapper(global_bench) do |bench| @@ -60,13 +60,13 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) end desc "benchmark ZMQ client with ZMQ server" - task :zmq_client_zmq_server, [:number, :length] do |t, args| + task :zmq_client_zmq_server, [:number, :length] do |_task, args| args.with_defaults(:number => 1000, :length => 100) zmq_client_zmq_server(args[:number], args[:length]) end desc "benchmark ZMQ client with ZMQ server and profile" - task :zmq_profile, [:number, :length, :profile_output] do |t, args| + task :zmq_profile, [:number, :length, :profile_output] do |_task, args| args.with_defaults(:number => 1000, :length => 100, :profile_output => "/tmp/zmq_profiler_#{Time.now.to_i}") profile_code(args[:profile_output]) do @@ -77,7 +77,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) end desc "benchmark Protobuf Message #new" - task :profile_protobuf_new, [:number, :profile_output] do |t, args| + task :profile_protobuf_new, [:number, :profile_output] do |_task, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do @@ -88,7 +88,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) end desc "benchmark Protobuf Message #serialize" - task :profile_protobuf_serialize, [:number, :profile_output] do |t, args| + task :profile_protobuf_serialize, [:number, :profile_output] do |_task, args| args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do @@ -118,13 +118,13 @@ def profile_code(output, &block) end desc "benchmark Socket client with Socket server" - task :sock_client_sock_server, [:number, :length] do |t, args| + task :sock_client_sock_server, [:number, :length] do |_task, args| args.with_defaults(:number => 1000, :length => 100) sock_client_sock_server(args[:number], args[:length]) end desc "benchmark server performance" - task :servers, [:number, :length] do |t, args| + task :servers, [:number, :length] do |_task, args| args.with_defaults(:number => 1000, :length => 100) Benchmark.bm(10) do |bench| diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index c2fbcd79..a138024a 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -39,8 +39,8 @@ end it 'runs under heavy load' do - 10.times do |x| - 5.times.map do |y| + 10.times do + 5.times do Thread.new do client = ::Test::ResourceService.client diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 14ce7ac7..cc6e7b1b 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -149,7 +149,7 @@ def verify_before; @called << :verify_before; end context 'when "if" option is a callable that returns true' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :if => lambda { |service| true }) + FilterTest.before_filter(:verify_before, :if => lambda { |_service| true }) end it 'invokes the filter' do @@ -173,7 +173,7 @@ def verify_before; @called << :verify_before; end context 'when "if" option is a callable that returns false' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :if => lambda { |service| false }) + FilterTest.before_filter(:verify_before, :if => lambda { |_service| false }) end it 'skips the filter' do @@ -208,7 +208,7 @@ def verify_before; @called << :verify_before; end context 'when "unless" option is a callable that returns true' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :unless => lambda { |service| false }) + FilterTest.before_filter(:verify_before, :unless => lambda { |_service| false }) end it 'invokes the filter' do @@ -232,7 +232,7 @@ def verify_before; @called << :verify_before; end context 'when "unless" option is a callable that returns false' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :unless => lambda { |service| true }) + FilterTest.before_filter(:verify_before, :unless => lambda { |_service| true }) end it 'skips the filter' do From 29bb6c9f7033c91deb448bc465784add71bdccd2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:42:54 -0700 Subject: [PATCH 080/298] Lint/UnusedMethodArgument --- .rubocop_todo.yml | 5 ----- lib/protobuf/field/base_field.rb | 10 +++++----- lib/protobuf/rpc/service_dispatcher.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- 4 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 4799377e..aa53b447 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,11 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 6 -# Cop supports --auto-correct. -Lint/UnusedMethodArgument: - Enabled: false - # Offense count: 8 Lint/UselessAssignment: Enabled: false diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index b688f180..902dda63 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -51,7 +51,7 @@ def initialize(message_class, rule, type_class, name, tag, options) # Public Instance Methods # - def acceptable?(value) + def acceptable?(_value) true end @@ -59,8 +59,8 @@ def coerce!(value) value end - def decode(bytes) - raise NotImplementedError, "#{self.class.name}\#decode" + def decode(_bytes) + raise NotImplementedError, "#{self.class.name}##{__method__}" end def default @@ -79,8 +79,8 @@ def deprecated? options.key?(:deprecated) end - def encode(value) - raise NotImplementedError, "#{self.class.name}\#encode" + def encode(_value) + raise NotImplementedError, "#{self.class.name}##{__method__}" end def extension? diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 91dacb42..70aa476e 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -7,7 +7,7 @@ class ServiceDispatcher attr_reader :env - def initialize(app) + def initialize(_app) # End of the line... end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 14be45b2..12e45e97 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -119,7 +119,7 @@ def invoke_via_except?(rpc_method, filter) # Value can either be a symbol/string indicating an instance method to call # or an object that responds to `call`. # - def invoke_via_if?(rpc_method, filter) + def invoke_via_if?(_rpc_method, filter) if_check = filter.fetch(:if) { lambda { |_service| return true } } do_invoke = case when if_check.nil? then @@ -149,7 +149,7 @@ def invoke_via_only?(rpc_method, filter) # Value can either be a symbol/string indicating an instance method to call # or an object that responds to `call`. # - def invoke_via_unless?(rpc_method, filter) + def invoke_via_unless?(_rpc_method, filter) unless_check = filter.fetch(:unless) { lambda { |_service| return false } } skip_invoke = case when unless_check.nil? then From c5c55fccda2f59d834a60c52ed7938d6bb800abb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:43:44 -0700 Subject: [PATCH 081/298] Lint/UselessAssignment --- .rubocop_todo.yml | 4 ---- lib/protobuf/generators/field_generator.rb | 4 ++-- lib/protobuf/rpc/buffer.rb | 4 ++-- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/connectors/zmq.rb | 2 -- lib/protobuf/rpc/servers/socket/server.rb | 2 +- lib/protobuf/rpc/servers/zmq/broker.rb | 2 +- 7 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index aa53b447..892c87bc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -5,10 +5,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 8 -Lint/UselessAssignment: - Enabled: false - # Offense count: 3 Metrics/BlockNesting: Max: 5 diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 5ff0295b..b2a4117e 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -91,10 +91,10 @@ def type_name @type_name ||= begin case descriptor.type.name when :TYPE_MESSAGE, :TYPE_ENUM, :TYPE_GROUP then - type_name = modulize(descriptor.type_name) + modulize(descriptor.type_name) else type_name = descriptor.type.name.to_s.downcase.sub(/type_/, '') - type_name = ":#{type_name}" + ":#{type_name}" end end end diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 1281e697..e6509bed 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -26,9 +26,9 @@ def mode=(mode) def write(force_mode=true) if force_mode and reading? - mode = :write + self.mode = :write elsif not force_mode and reading? - raise = 'You chose to write the buffer when in read mode' + raise 'You chose to write the buffer when in read mode' end @size = @data.length diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 2ef5b9a1..747eef3b 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -9,7 +9,7 @@ module Common def any_callbacks? return [@complete_cb, @failure_cb, @success_cb].inject(false) do |reduction, cb| - reduction = (reduction || !cb.nil?) + reduction || !cb.nil? end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 5b2dbd24..ab65f7cd 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -75,8 +75,6 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket - socket = nil - begin server_uri = lookup_server_uri socket = zmq_context.socket(::ZMQ::REQ) diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index e184c9d8..01fa55d6 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -74,7 +74,7 @@ def run # no-op when client == @server then logger.debug { sign_message("Accepted new connection") } - client, sockaddr = @server.accept + client, _sockaddr = @server.accept @listen_fds << client else unless @working.include?(client) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 89333742..3be992db 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -121,7 +121,7 @@ def local_queue_max_size end def process_backend - worker, ignore, *frames = read_from_backend + worker, _ignore, *frames = read_from_backend @idle_workers << worker From e82087d2909d2d0c76e1902f94ba77b80cb551e7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:49:04 -0700 Subject: [PATCH 082/298] Style/AccessModifierIndentation --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/buffer.rb | 2 +- lib/protobuf/rpc/middleware/exception_handler.rb | 2 +- lib/protobuf/rpc/middleware/logger.rb | 4 ++-- lib/protobuf/rpc/middleware/request_decoder.rb | 2 +- lib/protobuf/rpc/middleware/response_encoder.rb | 2 +- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_dispatcher.rb | 2 +- 8 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 892c87bc..ba694e74 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 8 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AccessModifierIndentation: - Enabled: false - # Offense count: 2 Style/AccessorMethodName: Enabled: false diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index e6509bed..21b7e218 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -67,7 +67,7 @@ def get_data_size end end - private + private def check_for_flush if !@size.nil? && @data.length == @size diff --git a/lib/protobuf/rpc/middleware/exception_handler.rb b/lib/protobuf/rpc/middleware/exception_handler.rb index b29ea29b..4f3757a6 100644 --- a/lib/protobuf/rpc/middleware/exception_handler.rb +++ b/lib/protobuf/rpc/middleware/exception_handler.rb @@ -22,7 +22,7 @@ def call(env) env end - private + private # Wrap exceptions in a generic Protobuf errors unless they already are # diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb index 9f4bd308..08a2c801 100644 --- a/lib/protobuf/rpc/middleware/logger.rb +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -19,7 +19,7 @@ def call(env) env end - private + private def instrumenter @instrumenter ||= Instrumenter.new @@ -67,7 +67,7 @@ def to_s(env) ].compact.join(' - ') end - private + private def elapsed_time (@start_time && @end_time ? "#{(@end_time - @start_time).round(4)}s" : nil) diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index de42a77b..c142a586 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -30,7 +30,7 @@ def log_signature env.log_signature || super end - private + private def method_name @method_name ||= begin diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index 11c53613..ec30bafa 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -22,7 +22,7 @@ def log_signature env.log_signature || super end - private + private # Encode the response wrapper to return to the client # diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 1c5f1e8c..48148231 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -147,7 +147,7 @@ def rpcs self.class.rpcs end - private + private def request_type @_request_type ||= env.request_type diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 70aa476e..991fd657 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -22,7 +22,7 @@ def rpc_service @rpc_service ||= env.rpc_service.new(env) end - private + private # Call the given service method. def dispatch_rpc_request From b528b60a04c9a88a14d7f451048c5d309e170890 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:53:22 -0700 Subject: [PATCH 083/298] Style/AccessorMethodName --- .rubocop_todo.yml | 4 ---- lib/protobuf/rpc/buffer.rb | 4 ++-- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ba694e74..5b7a8fd9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,10 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 2 -Style/AccessorMethodName: - Enabled: false - # Offense count: 7 # Cop supports --auto-correct. Style/AlignArray: diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 21b7e218..4d628c34 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -43,7 +43,7 @@ def <<(data) end end - def set_data(data) + def set_data(data) # rubocop:disable Style/AccessorMethodName @data = data.to_s @size = @data.size end @@ -60,7 +60,7 @@ def flushed? @flush end - def get_data_size + def get_data_size # rubocop:disable Style/AccessorMethodName if @size == 0 || @data.match(SIZE_REGEX) sliced_size = @data.slice!(SIZE_REGEX) @size = sliced_size.gsub('-', '').to_i unless sliced_size.nil? From 1042d99b9e27fe277a01029904f1453579024f89 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 08:55:36 -0700 Subject: [PATCH 084/298] Style/AlignArray --- .rubocop_todo.yml | 5 ---- spec/lib/protobuf/message_spec.rb | 11 ++++++--- spec/lib/protobuf/rpc/service_filters_spec.rb | 24 ++++++++++++------- 3 files changed, 24 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5b7a8fd9..efc71076 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 7 -# Cop supports --auto-correct. -Style/AlignArray: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 7d64f1ea..e67f1b18 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -389,9 +389,14 @@ Test::Resource.new(:name => 'Resource 2') ]) - expect(proto.to_hash).to eq({ :multiple_resources => [ { :name => 'Resource 1' }, - { :name => 'Resource 2' } ] }) - + expect(proto.to_hash).to eq( + { + :multiple_resources => [ + { :name => 'Resource 1' }, + { :name => 'Resource 2' }, + ], + } + ) end end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index cc6e7b1b..c147ced5 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -331,11 +331,15 @@ def inner_around it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :outer_around_top, - :inner_around_top, - :endpoint, - :inner_around_bottom, - :outer_around_bottom ]) + expect(subject.called).to eq( + [ + :outer_around_top, + :inner_around_top, + :endpoint, + :inner_around_bottom, + :outer_around_bottom, + ] + ) end context 'when around_filter does not yield' do @@ -356,9 +360,13 @@ def inner_around it 'cancels calling the rest of the filters and the endpoint' do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :outer_around_top, - :inner_around, - :outer_around_bottom ]) + expect(subject.called).to eq( + [ + :outer_around_top, + :inner_around, + :outer_around_bottom, + ] + ) end end From 77b8d1bf7a5aba872bcc171bfccb742835d6a5c8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:13:23 -0700 Subject: [PATCH 085/298] Style/AndOr --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/buffer.rb | 4 ++-- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index efc71076..092b2510 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/AndOr: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 4d628c34..bec96248 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -25,9 +25,9 @@ def mode=(mode) end def write(force_mode=true) - if force_mode and reading? + if force_mode && reading? self.mode = :write - elsif not force_mode and reading? + elsif !force_mode && reading? raise 'You chose to write the buffer when in read mode' end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 747eef3b..4b33b3ed 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -90,7 +90,7 @@ def parse_response # Ensure client_response is an instance parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) - if parsed.nil? and not response_wrapper.has_field?(:error_reason) + if parsed.nil? && !response_wrapper.has_field?(:error_reason) fail(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') else verify_callbacks diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 2264f44b..2fe3066b 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -162,7 +162,7 @@ def reap_dead_workers @last_reaping = Time.now.to_i @workers.keep_if do |worker| - worker.alive? or worker.join && false + worker.alive? || worker.join && false end end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 10735e25..a2aef5e4 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -200,7 +200,7 @@ def remove_expired_listings end def remove_listing(uuid) - listing = @listings_by_uuid[uuid] or return + listing = @listings_by_uuid[uuid] || return logger.debug { sign_message("Removing listing: #{listing.inspect}") } From b4efb3a9bb4b7250fecd0703296994085f338d82 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:14:40 -0700 Subject: [PATCH 086/298] Style/BarePercentLiterals --- .rubocop_todo.yml | 6 ------ Rakefile | 4 ++-- lib/protobuf/deprecator.rb | 2 +- lib/protobuf/generators/field_generator.rb | 2 +- spec/lib/protobuf/generators/field_generator_spec.rb | 2 +- 5 files changed, 5 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 092b2510..6855f1fa 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BarePercentLiterals: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. Style/BlockEndNewline: diff --git a/Rakefile b/Rakefile index 30f57c70..77ab62e9 100644 --- a/Rakefile +++ b/Rakefile @@ -21,7 +21,7 @@ namespace :compile do desc 'Compile spec protos in spec/supprt/ directory' task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) - cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} puts cmd exec(cmd) @@ -33,7 +33,7 @@ namespace :compile do output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) - cmd = %Q{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} puts cmd system(cmd) diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index 9fbcbdc2..b19773c0 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -2,7 +2,7 @@ module Protobuf module Deprecator def warn_deprecated(old_method, new_method) - $stderr.puts %Q{[DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. + $stderr.puts %{[DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. Please use #{self.name}.#{new_method} instead.\n} end diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index b2a4117e..a252a445 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -119,7 +119,7 @@ def float_double_default_value end def string_default_value - %Q{"#{verbatim_default_value.gsub(/'/, '\\\\\'')}"} + %{"#{verbatim_default_value.gsub(/'/, '\\\\\'')}"} end def verbatim_default_value diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 714c864e..6daa5a23 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -53,7 +53,7 @@ let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } - specify { expect(subject).to eq %Q{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } + specify { expect(subject).to eq %{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } end context 'when float or double field type' do From 55d37ab500a00024f2cd7710cd2ea90733fadacc Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:15:34 -0700 Subject: [PATCH 087/298] Style/BlockEndNewline --- .rubocop_todo.yml | 5 ----- spec/lib/protobuf/generators/enum_generator_spec.rb | 3 ++- spec/lib/protobuf/generators/field_generator_spec.rb | 3 ++- spec/lib/protobuf/generators/service_generator_spec.rb | 3 ++- spec/lib/protobuf/rpc/connectors/common_spec.rb | 6 ++++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6855f1fa..e5b46008 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Cop supports --auto-correct. -Style/BlockEndNewline: - Enabled: false - # Offense count: 67 # Cop supports --auto-correct. Style/Blocks: diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 1521ced4..3c176409 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -14,7 +14,8 @@ let(:options) { nil } let(:enum_fields) { { :name => 'TestEnum', :value => values, - :options => options } } + :options => options } + } let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) } diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 6daa5a23..a6d9742e 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -20,7 +20,8 @@ :type_name => type_name, :default_value => default_value, :extendee => extendee, - :options => field_options } } + :options => field_options } + } let(:field) { ::Google::Protobuf::FieldDescriptorProto.new(field_fields) } diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index dae1fc02..166b8318 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -11,7 +11,8 @@ ] } let(:service_fields) { { :name => 'TestService', - :method => methods } } + :method => methods } + } let(:service) { ::Google::Protobuf::ServiceDescriptorProto.new(service_fields) } diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 1b945222..8ab486df 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -77,12 +77,14 @@ let(:subject_options) { { :service => service, :method => method, :request => request, - :client_host => client_host } } + :client_host => client_host } + } let(:expected) { ::Protobuf::Socketrpc::Request.new({ :service_name => service.name, :method_name => 'find', :request_proto => '', - :caller => client_host }) } + :caller => client_host }) + } before { allow(subject).to receive(:validate_request_type!).and_return(true) } before { expect(subject).not_to receive(:fail) } From b0eeabc250db74f4f618cf628ddfe9696a9de564 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:20:40 -0700 Subject: [PATCH 088/298] Style/Blocks --- .rubocop_todo.yml | 5 --- lib/protobuf.rb | 4 +-- lib/protobuf/cli.rb | 4 +-- lib/protobuf/enum.rb | 4 +-- lib/protobuf/generators/file_generator.rb | 4 +-- lib/protobuf/message.rb | 4 +-- lib/protobuf/rpc/connectors/zmq.rb | 4 +-- lib/protobuf/rpc/service_filters.rb | 8 ++--- spec/functional/socket_server_spec.rb | 4 +-- spec/functional/zmq_server_spec.rb | 4 +-- spec/lib/protobuf/cli_spec.rb | 8 ++--- spec/lib/protobuf/code_generator_spec.rb | 4 +-- spec/lib/protobuf/enum_spec.rb | 4 +-- spec/lib/protobuf/field/string_field_spec.rb | 8 ++--- spec/lib/protobuf/field_spec.rb | 4 +-- .../generators/enum_generator_spec.rb | 23 +++++++------ .../generators/extension_generator_spec.rb | 8 ++--- .../generators/field_generator_spec.rb | 21 ++++++------ .../generators/service_generator_spec.rb | 17 ++++++---- spec/lib/protobuf/lifecycle_spec.rb | 4 +-- spec/lib/protobuf/message_spec.rb | 32 +++++++++---------- spec/lib/protobuf/optionable_spec.rb | 4 +-- .../protobuf/rpc/connectors/common_spec.rb | 28 +++++++++------- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 16 ++++++---- .../protobuf/rpc/middleware/logger_spec.rb | 8 ++--- .../rpc/middleware/request_decoder_spec.rb | 16 +++++----- .../rpc/middleware/response_encoder_spec.rb | 4 +-- .../protobuf/rpc/servers/zmq/server_spec.rb | 14 ++++---- .../lib/protobuf/rpc/servers/zmq/util_spec.rb | 16 +++++----- .../protobuf/rpc/service_directory_spec.rb | 24 +++++++------- .../protobuf/rpc/service_dispatcher_spec.rb | 4 +-- spec/lib/protobuf/rpc/service_filters_spec.rb | 16 +++++----- spec/lib/protobuf/rpc/service_spec.rb | 8 ++--- spec/lib/protobuf_spec.rb | 8 ++--- 34 files changed, 179 insertions(+), 165 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e5b46008..f1a04247 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 67 -# Cop supports --auto-correct. -Style/Blocks: - Enabled: false - # Offense count: 15 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 4520ae06..38bae844 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -102,9 +102,9 @@ def self.ignore_unknown_fields=(value) require 'protobuf/rpc/client' require 'protobuf/rpc/service' - env_connector_type = ENV.fetch('PB_CLIENT_TYPE') { + env_connector_type = ENV.fetch('PB_CLIENT_TYPE') do ::Protobuf::DEFAULT_CONNECTOR - }.to_s.downcase.strip.to_sym + end.to_s.downcase.strip.to_sym if ::Protobuf::CONNECTORS.include?(env_connector_type) require "protobuf/#{env_connector_type}" diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index ad0716c6..6e543c7a 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -227,9 +227,9 @@ def start_server debug_say('Running server') @runner.run do - logger.info { + logger.info do "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" - } + end ::ActiveSupport::Notifications.instrument("after_server_bind") end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index bff48979..f179f634 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -101,9 +101,9 @@ def self.enums # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) - self.enums.select { |enum| + self.enums.select do |enum| enum.to_i == tag.to_i - } + end end # Public: Get the Enum associated with the given name. diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 63fb9412..92ac87ca 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -118,9 +118,9 @@ def print_import_requires def print_package(&block) final = lambda { block.call } namespaces = descriptor.package.split('.') - namespaces.reverse.inject(final) { |previous, namespace| + namespaces.reverse.inject(final) do |previous, namespace| lambda { print_module(namespace, &previous) } - }.call + end.call end private diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a608898a..3f95ab6e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -164,12 +164,12 @@ def []=(name, value) private def copy_to(object, method) - duplicate = proc { |obj| + duplicate = proc do |obj| case obj when Message, String then obj.__send__(method) else obj end - } + end object.__send__(:initialize) @values.each do |name, value| diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index ab65f7cd..598e068c 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -25,9 +25,9 @@ class Zmq < Base # Class Methods # def self.zmq_context - @zmq_contexts ||= Hash.new { |hash, key| + @zmq_contexts ||= Hash.new do |hash, key| hash[key] = ZMQ::Context.new - } + end @zmq_contexts[Process.pid] end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 12e45e97..acd05e22 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -210,13 +210,13 @@ def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = # def run_around_filters(rpc_method) final = lambda { __send__(rpc_method) } - filters[:around].reverse.inject(final) { |previous, filter| + filters[:around].reverse.inject(final) do |previous, filter| if invoke_filter?(rpc_method, filter) lambda { call_or_send(filter[:callable], &previous) } else previous end - }.call + end.call end @@ -240,10 +240,10 @@ def run_rescue_filters begin yield rescue *rescue_filters.keys => ex - callable = rescue_filters.fetch(ex.class) { + callable = rescue_filters.fetch(ex.class) do mapped_klass = rescue_filters.keys.detect { |child_klass| ex.class < child_klass } rescue_filters[mapped_klass] - } + end call_or_send(callable, ex) end diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 51784817..bf0c283a 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -16,7 +16,7 @@ end it 'runs fine when required fields are set' do - expect { + expect do client = ::Test::ResourceService.client client.find(:name => 'Test Name', :active => true) do |c| @@ -29,7 +29,7 @@ raise err.inspect end end - }.to_not raise_error + end.to_not raise_error end it 'calls the on_failure callback when a message is malformed' do diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index a138024a..fe69b3a8 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -22,7 +22,7 @@ end it 'runs fine when required fields are set' do - expect { + expect do client = ::Test::ResourceService.client client.find(:name => 'Test Name', :active => true) do |c| @@ -35,7 +35,7 @@ raise err.inspect end end - }.to_not raise_error + end.to_not raise_error end it 'runs under heavy load' do diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 24fde5e0..b1767bf7 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -7,17 +7,17 @@ File.expand_path('../../../support/test_app_file.rb', __FILE__) end - let(:sock_runner) { + let(:sock_runner) do runner = double("SocketRunner", :register_signals => nil) allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner - } + end - let(:zmq_runner) { + let(:zmq_runner) do runner = double "ZmqRunner", register_signals: nil allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner - } + end around(:each) do |example| logger = ::Protobuf::Logging.logger diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index ca31b278..5cc77e38 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -40,9 +40,9 @@ context 'class-level printing methods' do describe '.fatal' do it 'raises a CodeGeneratorFatalError error' do - expect { + expect do described_class.fatal("something is wrong") - }.to raise_error( + end.to raise_error( ::Protobuf::CodeGenerator::CodeGeneratorFatalError, "something is wrong" ) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 3de2ab40..fd121933 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -40,10 +40,10 @@ end it 'allows defining enums with the same tag number' do - expect { + expect do DefineEnumAlias.define(:FOO, 1) DefineEnumAlias.define(:BAR, 1) - }.not_to raise_error + end.not_to raise_error end end end diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index 887d8e57..b25ccc95 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -7,19 +7,19 @@ describe '#encode' do context 'when a repeated string field contains frozen strings' do it 'does not raise an encoding error' do - expect { + expect do frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] ::Test::ResourceFindRequest.encode(:name => 'resource', :widgets => frozen_strings) - }.not_to raise_error + end.not_to raise_error end end context 'when a repeated bytes field contains frozen strings' do it 'does not raise an encoding error' do - expect { + expect do frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] ::Test::ResourceFindRequest.encode(:name => 'resource', :widget_bytes => frozen_strings) - }.not_to raise_error + end.not_to raise_error end end diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index e9772588..7b7537a6 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -183,9 +183,9 @@ context 'when type is not mapped' do it 'raises an ArgumentError' do - expect { + expect do subject.field_class("boom") - }.to raise_error + end.to raise_error end end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 3c176409..6c3d8476 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -4,25 +4,28 @@ describe ::Protobuf::Generators::EnumGenerator do - let(:values) { + let(:values) do [ { :name => 'FOO', :number => 1 }, { :name => 'BAR', :number => 2 }, { :name => 'BAZ', :number => 3 } ] - } + end let(:options) { nil } - let(:enum_fields) { { :name => 'TestEnum', - :value => values, - :options => options } - } + let(:enum_fields) do + { + :name => 'TestEnum', + :value => values, + :options => options + } + end let(:enum) { ::Google::Protobuf::EnumDescriptorProto.new(enum_fields) } subject { described_class.new(enum) } describe '#compile' do - let(:compiled) { + let(:compiled) do <<-RUBY class TestEnum < ::Protobuf::Enum define :FOO, 1 @@ -31,7 +34,7 @@ class TestEnum < ::Protobuf::Enum end RUBY - } + end it 'compiles the enum and its field values' do subject.compile @@ -39,7 +42,7 @@ class TestEnum < ::Protobuf::Enum end context 'when allow_alias option is set' do - let(:compiled) { + let(:compiled) do <<-RUBY class TestEnum < ::Protobuf::Enum set_option :allow_alias @@ -50,7 +53,7 @@ class TestEnum < ::Protobuf::Enum end RUBY - } + end let(:options) { { :allow_alias => true } } diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 5d0e21f7..1afc8b98 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -5,13 +5,13 @@ describe ::Protobuf::Generators::ExtensionGenerator do - let(:field_descriptors) { + let(:field_descriptors) do [ double('field descriptor 1', :to_s => " field 1\n"), double('field descriptor 2', :to_s => " field 2\n"), double('field descriptor 3', :to_s => " field 3\n") ] - } + end let(:message_type) { 'FooBar' } before do @@ -23,7 +23,7 @@ subject { described_class.new(message_type, field_descriptors, 0) } describe '#compile' do - let(:compiled) { + let(:compiled) do %q{class FooBar < ::Protobuf::Message field 1 field 2 @@ -31,7 +31,7 @@ end } - } + end it 'compiles the a class with the extension fields' do subject.compile diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index a6d9742e..e03ee487 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -13,15 +13,18 @@ let(:extendee) { nil } let(:field_options) { {} } - let(:field_fields) { { :label => label_enum, - :name => name, - :number => number, - :type => type_enum, - :type_name => type_name, - :default_value => default_value, - :extendee => extendee, - :options => field_options } - } + let(:field_fields) do + { + :label => label_enum, + :name => name, + :number => number, + :type => type_enum, + :type_name => type_name, + :default_value => default_value, + :extendee => extendee, + :options => field_options + } + end let(:field) { ::Google::Protobuf::FieldDescriptorProto.new(field_fields) } diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 166b8318..0611e4be 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -4,29 +4,32 @@ describe ::Protobuf::Generators::ServiceGenerator do - let(:methods) { + let(:methods) do [ { :name => 'Search', :input_type => 'FooRequest', :output_type => 'FooResponse' }, { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' } ] - } - let(:service_fields) { { :name => 'TestService', - :method => methods } - } + end + let(:service_fields) do + { + :name => 'TestService', + :method => methods + } + end let(:service) { ::Google::Protobuf::ServiceDescriptorProto.new(service_fields) } subject { described_class.new(service) } describe '#compile' do - let(:compiled) { + let(:compiled) do %q{class TestService < ::Protobuf::Rpc::Service rpc :search, FooRequest, FooResponse rpc :foo_bar, ::Foo::Request, ::Bar::Response end } - } + end it 'compiles the service and it\'s rpc methods' do subject.compile diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index fce13162..f5e098f9 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -14,9 +14,9 @@ end it "only registers blocks for event callbacks" do - expect { + expect do subject.register("something") - }.to raise_error( /block/ ) + end.to raise_error( /block/ ) end it "calls the registered block when triggered" do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e67f1b18..47b81fe8 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -74,47 +74,47 @@ describe 'defining a new field' do context 'when defining a field with a tag that has already been used' do it 'raises a TagCollisionError' do - expect { + expect do Class.new(Protobuf::Message) do optional ::Protobuf::Field::Int32Field, :foo, 1 optional ::Protobuf::Field::Int32Field, :bar, 1 end - }.to raise_error(Protobuf::TagCollisionError, /Field number 1 has already been used/) + end.to raise_error(Protobuf::TagCollisionError, /Field number 1 has already been used/) end end context 'when defining an extension field with a tag that has already been used' do it 'raises a TagCollisionError' do - expect { + expect do Class.new(Protobuf::Message) do extensions 100...110 optional ::Protobuf::Field::Int32Field, :foo, 100 optional ::Protobuf::Field::Int32Field, :bar, 100, :extension => true end - }.to raise_error(Protobuf::TagCollisionError, /Field number 100 has already been used/) + end.to raise_error(Protobuf::TagCollisionError, /Field number 100 has already been used/) end end context 'when defining a field with a name that has already been used' do it 'raises a DuplicateFieldNameError' do - expect { + expect do Class.new(Protobuf::Message) do optional ::Protobuf::Field::Int32Field, :foo, 1 optional ::Protobuf::Field::Int32Field, :foo, 2 end - }.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) + end.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) end end context 'when defining an extension field with a name that has already been used' do it 'raises a DuplicateFieldNameError' do - expect { + expect do Class.new(Protobuf::Message) do extensions 100...110 optional ::Protobuf::Field::Int32Field, :foo, 1 optional ::Protobuf::Field::Int32Field, :foo, 100, :extension => true end - }.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) + end.to raise_error(Protobuf::DuplicateFieldNameError, /Field name foo has already been used/) end end end @@ -246,9 +246,9 @@ let(:message) { ::Test::ResourceWithRequiredField.new } it "raises a 'message not initialized' error" do - expect { + expect do message.encode - }.to raise_error(Protobuf::SerializationError, /required/i) + end.to raise_error(Protobuf::SerializationError, /required/i) end end @@ -256,10 +256,10 @@ let(:message) { ::Test::Resource.new(:name => "something") } it "does not raise an error when repeated fields are []" do - expect { + expect do message.repeated_enum = [] message.encode - }.to_not raise_error + end.to_not raise_error end it "sets the value to nil when empty array is passed" do @@ -280,9 +280,9 @@ end it "raises TypeError when a non-array replaces it" do - expect { + expect do message.repeated_enum = 2 - }.to raise_error(/value of type/) + end.to raise_error(/value of type/) end end end @@ -411,11 +411,11 @@ describe '.to_json' do it 'returns the class name of the message for use in json encoding' do - expect { + expect do ::Timeout.timeout(0.1) do expect(::Test::Resource.to_json).to eq("Test::Resource") end - }.not_to raise_error + end.not_to raise_error end end diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index d6237f14..056f9092 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -13,9 +13,9 @@ it 'stores the given option and value' do expect(OptionableSetOptionTest).to respond_to(:set_option) expect(OptionableSetOptionTest.method(:set_option).arity).to eq(-2) - expect { + expect do OptionableSetOptionTest.set_option(:foo, :bar) - }.to_not raise_error + end.to_not raise_error end it 'defaults the value to true' do diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 8ab486df..0710d6ab 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -74,17 +74,23 @@ let(:method) { :find } let(:request) { '' } let(:client_host) { 'myhost.myservice.com' } - let(:subject_options) { { :service => service, - :method => method, - :request => request, - :client_host => client_host } - } - - let(:expected) { ::Protobuf::Socketrpc::Request.new({ :service_name => service.name, - :method_name => 'find', - :request_proto => '', - :caller => client_host }) - } + let(:subject_options) do + { + :service => service, + :method => method, + :request => request, + :client_host => client_host + } + end + + let(:expected) do + ::Protobuf::Socketrpc::Request.new( + :service_name => service.name, + :method_name => 'find', + :request_proto => '', + :caller => client_host + ) + end before { allow(subject).to receive(:validate_request_type!).and_return(true) } before { expect(subject).not_to receive(:fail) } diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 7bec5332..03734958 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -4,13 +4,15 @@ describe ::Protobuf::Rpc::Connectors::Zmq do subject { described_class.new(options) } - let(:options) {{ - :service => "Test::Service", - :method => "find", - :timeout => 3, - :host => "127.0.0.1", - :port => "9400" - }} + let(:options) do + { + :service => "Test::Service", + :method => "find", + :timeout => 3, + :host => "127.0.0.1", + :port => "9400" + } + end let(:socket_double) { double(::ZMQ::Socket, :connect => 0) } let(:zmq_context_double) { double(::ZMQ::Context, :socket => socket_double) } diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index fa938aa1..e3621a76 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -2,7 +2,7 @@ describe Protobuf::Rpc::Middleware::Logger do let(:app) { Proc.new { |inner_env| inner_env } } - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'client_host' => 'client_host.test.co', 'encoded_request' => request_wrapper.encode, @@ -16,17 +16,17 @@ 'rpc_service' => service_class, 'service_name' => service_name, ) - } + end let(:method_name) { :find } let(:request) { request_type.new(:name => 'required') } let(:request_type) { rpc_method.request_type } - let(:request_wrapper) { + let(:request_wrapper) do Protobuf::Socketrpc::Request.new( :service_name => service_name, :method_name => method_name.to_s, :request_proto => request ) - } + end let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } let(:response) { rpc_method.response_type.new(:name => 'required') } let(:rpc_method) { service_class.rpcs[method_name] } diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index ae33afe8..f7f4a485 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -3,24 +3,24 @@ describe Protobuf::Rpc::Middleware::RequestDecoder do let(:app) { Proc.new { |env| env } } let(:client_host) { 'client_host.test.co' } - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'encoded_request' => encoded_request, 'log_signature' => 'log_signature' ) - } + end let(:encoded_request) { request_wrapper.encode } let(:method_name) { :find } let(:request) { request_type.new(:name => 'required') } let(:request_type) { rpc_method.request_type } - let(:request_wrapper) { + let(:request_wrapper) do Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => service_name, :method_name => method_name.to_s, :request_proto => request ) - } + end let(:response_type) { rpc_method.response_type } let(:rpc_method) { rpc_service.rpcs[method_name] } let(:rpc_service) { Test::ResourceService } @@ -83,14 +83,14 @@ end context "when the RPC service is not defined" do - let(:request_wrapper) { + let(:request_wrapper) do Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => 'Foo', :method_name => method_name.to_s, :request_proto => request ) - } + end it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::ServiceNotFound) @@ -98,14 +98,14 @@ end context "when RPC method is not defined" do - let(:request_wrapper) { + let(:request_wrapper) do Protobuf::Socketrpc::Request.new( :caller => client_host, :service_name => service_name, :method_name => 'foo', :request_proto => request ) - } + end it "raises a bad request data exception" do expect { subject.call(env) }.to raise_exception(Protobuf::Rpc::MethodNotFound) diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 9b9bb429..f9d47ebe 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -2,12 +2,12 @@ describe Protobuf::Rpc::Middleware::ResponseEncoder do let(:app) { Proc.new { |env| env.response = response; env } } - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'response_type' => Test::Resource, 'log_signature' => 'log_signature' ) - } + end let(:encoded_response) { response_wrapper.encode } let(:response) { Test::Resource.new(:name => 'required') } let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 0fbb0024..e8f0eacf 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -4,12 +4,14 @@ describe Protobuf::Rpc::Zmq::Server do subject { described_class.new(options) } - let(:options) {{ - :host => '127.0.0.1', - :port => 9399, - :worker_port => 9400, - :workers_only => true - }} + let(:options) do + { + :host => '127.0.0.1', + :port => 9399, + :worker_port => 9400, + :workers_only => true + } + end before do load 'protobuf/zmq.rb' diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index 523297f8..be2bdf62 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -12,28 +12,28 @@ class UtilTest subject { UtilTest.new } describe '#zmq_error_check' do it 'raises when the error code is less than 0' do - expect { + expect do subject.zmq_error_check(-1, :test) - }.to raise_error(/test/) + end.to raise_error(/test/) end it 'retrieves the error string from ZeroMQ' do allow(ZMQ::Util).to receive(:error_string).and_return('an error from zmq') - expect { + expect do subject.zmq_error_check(-1, :test) - }.to raise_error(RuntimeError, /an error from zmq/i) + end.to raise_error(RuntimeError, /an error from zmq/i) end it 'does nothing if the error code is > 0' do - expect { + expect do subject.zmq_error_check(1, :test) - }.to_not raise_error + end.to_not raise_error end it 'does nothing if the error code is == 0' do - expect { + expect do subject.zmq_error_check(0, :test) - }.to_not raise_error + end.to_not raise_error end end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 577fbe8e..4798e6e5 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -5,7 +5,7 @@ describe ::Protobuf::Rpc::ServiceDirectory do subject { described_class.instance } - let(:echo_server) { + let(:echo_server) do ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => 'echo', :address => '127.0.0.1', @@ -13,9 +13,9 @@ :ttl => 10, :services => %w[EchoService] ) - } + end - let(:hello_server) { + let(:hello_server) do ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "hello", :address => '127.0.0.1', @@ -23,9 +23,9 @@ :ttl => 10, :services => %w[HelloService] ) - } + end - let(:hello_server_with_short_ttl) { + let(:hello_server_with_short_ttl) do ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "hello_server_with_short_ttl", :address => '127.0.0.1', @@ -33,9 +33,9 @@ :ttl => 1, :services => %w[HelloService] ) - } + end - let(:combo_server) { + let(:combo_server) do ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "combo", :address => '127.0.0.1', @@ -43,7 +43,7 @@ :ttl => 10, :services => %w[HelloService EchoService] ) - } + end before(:all) do @address = "127.0.0.1" @@ -175,9 +175,9 @@ def send_beacon(type, server) send_beacon(:heartbeat, echo_server) send_beacon(:heartbeat, combo_server) - expect { |block| + expect do |block| subject.each_listing(&block) - }.to yield_control.exactly(3).times + end.to yield_control.exactly(3).times end end @@ -259,7 +259,7 @@ def send_beacon(type, server) if ENV.key?("BENCH") context "performance" do - let(:servers) { + let(:servers) do 100.times.collect do |x| ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "performance_server#{x + 1}", @@ -269,7 +269,7 @@ def send_beacon(type, server) :services => 10.times.collect { |y| "PerformanceService#{y}" } ) end - } + end before do require 'benchmark' diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 1582b44c..585b3b05 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -3,14 +3,14 @@ describe Protobuf::Rpc::ServiceDispatcher do let(:app) { proc { |env| env } } - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'method_name' => method_name, 'request' => request, 'rpc_service' => service_class, 'service_name' => service_name, ) - } + end let(:method_name) { :find } let(:request) { request_type.new(:name => 'required') } let(:request_type) { service_class.rpcs[method_name].request_type } diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index c147ced5..538dfcc1 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -419,12 +419,12 @@ def custom_error_occurred(ex) before { FilterTest.before_filter(:filter_with_error3) } it 'short-circuits the call stack' do - expect { + expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) expect(subject.called).to eq([ :filter_with_error3, :custom_error_occurred ]) expect(subject.ex_class).to eq CustomError3 - }.not_to raise_error + end.not_to raise_error end end @@ -440,12 +440,12 @@ def custom_error_occurred(ex) before { FilterTest.before_filter(:filter_with_error1) } it 'short-circuits the call stack' do - expect { + expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) expect(subject.called).to eq([ :filter_with_error1, :custom_error_occurred ]) expect(subject.ex_class).to eq CustomError1 - }.not_to raise_error + end.not_to raise_error end end end @@ -460,12 +460,12 @@ def custom_error_occurred(ex) before { FilterTest.before_filter(:filter_with_error1) } it 'short-circuits the call stack' do - expect { + expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) expect(subject.called).to eq([ :filter_with_error1, :block_rescue_handler ]) expect(subject.ex_class).to eq CustomError1 - }.not_to raise_error + end.not_to raise_error end end @@ -479,12 +479,12 @@ def custom_error_occurred(ex) before { FilterTest.before_filter(:filter_with_runtime_error) } it 'rescues with the given callable' do - expect { + expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) expect(subject.called).to eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) expect(subject.ex_class).to eq RuntimeError - }.not_to raise_error + end.not_to raise_error end end end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 545e90ee..2c44876e 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -125,12 +125,12 @@ def find_with_rpc_failed context 'when calling the rpc method' do context 'when response is implied' do - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'request' => request, 'response_type' => response_type ) - } + end let(:response_type) { service.rpcs[:find_with_implied_response].response_type } let(:service) { NewTestService } @@ -142,12 +142,12 @@ def find_with_rpc_failed end context 'when using respond_with paradigm' do - let(:env) { + let(:env) do Protobuf::Rpc::Env.new( 'method_name' => :find_with_respond_with, 'request' => request ) - } + end subject { NewTestService.new(env) } diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index b828f53c..f2a3a528 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -35,9 +35,9 @@ it 'does not accept other types' do [:hello, :world, :evented].each do |type| - expect { + expect do described_class.connector_type = type - }.to raise_error(ArgumentError) + end.to raise_error(ArgumentError) end end end @@ -87,9 +87,9 @@ end it 'is settable' do - expect { + expect do described_class.ignore_unknown_fields = false - }.to change { + end.to change { described_class.ignore_unknown_fields? }.from(true).to(false) end From 052a4fc9b0176bb4c9bf078691a56b134d380ca0 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 14 Oct 2014 09:23:53 -0700 Subject: [PATCH 089/298] Style/BracesAroundHashParameters --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/service_filters.rb | 2 +- spec/functional/zmq_server_spec.rb | 14 +++++++------ spec/lib/protobuf/enum_spec.rb | 8 ++++---- .../generators/file_generator_spec.rb | 8 ++++++-- spec/lib/protobuf/message_spec.rb | 20 +++++++++---------- spec/lib/protobuf/rpc/client_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/worker_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 9 +++++---- 9 files changed, 35 insertions(+), 36 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index f1a04247..90b35c33 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 15 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/BracesAroundHashParameters: - Enabled: false - # Offense count: 4 # Configuration parameters: EnforcedStyle, SupportedStyles. Style/ClassAndModuleChildren: diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index acd05e22..b67a7d45 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -45,7 +45,7 @@ def rescue_from(*ex_klasses, &block) def define_filter(type, filter, options = {}) return if filter_defined?(type, filter) - filters[type] << options.merge({ :callable => filter }) + filters[type] << options.merge(:callable => filter) remember_filter(type, filter) end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index fe69b3a8..1b52d68f 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -6,12 +6,14 @@ describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" - @runner = ::Protobuf::Rpc::ZmqRunner.new({ :host => "127.0.0.1", - :port => 9399, - :worker_port => 9408, - :backlog => 100, - :threshold => 100, - :threads => 5 }) + @runner = ::Protobuf::Rpc::ZmqRunner.new( + :host => "127.0.0.1", + :port => 9399, + :worker_port => 9408, + :backlog => 100, + :threshold => 100, + :threads => 5 + ) @server_thread = Thread.new(@runner) { |runner| runner.run } Thread.pass until @runner.running? end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index fd121933..17718801 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -175,20 +175,20 @@ describe '.values' do it 'provides a hash of defined Enums' do - expect(Test::EnumTestType.values).to eq({ + expect(Test::EnumTestType.values).to eq( :MINUS_ONE => Test::EnumTestType::MINUS_ONE, :ONE => Test::EnumTestType::ONE, :TWO => Test::EnumTestType::TWO, :THREE => Test::EnumTestType::THREE - }) + ) end it 'contains aliased Enums' do - expect(EnumAliasTest.values).to eq({ + expect(EnumAliasTest.values).to eq( :FOO => EnumAliasTest::FOO, :BAR => EnumAliasTest::BAR, :BAZ => EnumAliasTest::BAZ - }) + ) end end diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 9f666afa..56b05e37 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -13,8 +13,12 @@ describe '#print_import_requires' do let(:descriptor_fields) do - base_descriptor_fields.merge!({ :dependency => [ 'test/bar.proto', - 'test/baz.proto' ] }) + base_descriptor_fields.merge( + :dependency => [ + 'test/bar.proto', + 'test/baz.proto' + ] + ) end it 'prints a ruby require for each dependency' do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 47b81fe8..97acbb4d 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -363,7 +363,7 @@ context 'generating values for an ENUM field' do it 'converts the enum to its tag representation' do hash = Test::EnumTestMessage.new(:non_default_enum => :TWO).to_hash - expect(hash).to eq({ :non_default_enum => 2 }) + expect(hash).to eq(:non_default_enum => 2) end it 'does not populate default values' do @@ -373,14 +373,14 @@ it 'converts repeated enum fields to an array of the tags' do hash = Test::EnumTestMessage.new(:repeated_enums => [ :ONE, :TWO, :TWO, :ONE ]).to_hash - expect(hash).to eq({ :repeated_enums => [ 1, 2, 2, 1 ] }) + expect(hash).to eq(:repeated_enums => [ 1, 2, 2, 1 ]) end end context 'generating values for a Message field' do it 'recursively hashes field messages' do - hash = Test::Nested.new({ :resource => { :name => 'Nested' } }).to_hash - expect(hash).to eq({ :resource => { :name => 'Nested' } }) + hash = Test::Nested.new(:resource => { :name => 'Nested' }).to_hash + expect(hash).to eq(:resource => { :name => 'Nested' }) end it 'recursively hashes a repeated set of messages' do @@ -390,12 +390,10 @@ ]) expect(proto.to_hash).to eq( - { - :multiple_resources => [ - { :name => 'Resource 1' }, - { :name => 'Resource 2' }, - ], - } + :multiple_resources => [ + { :name => 'Resource 1' }, + { :name => 'Resource 2' }, + ] ) end end @@ -403,7 +401,7 @@ describe '#to_json' do subject do - ::Test::ResourceFindRequest.new({ :name => 'Test Name', :active => false }) + ::Test::ResourceFindRequest.new(:name => 'Test Name', :active => false) end specify { expect(subject.to_json).to eq '{"name":"Test Name","active":false}' } diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index 14b8ba34..cd2bfe13 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -55,7 +55,7 @@ it 'should be able to create the correct request object if passed a hash' do client = Test::ResourceService.client expect(client).to receive(:send_request) - client.find({:name => 'Test Name', :active => false}) + client.find(:name => 'Test Name', :active => false) expect(client.options[:request]).to be_a(Test::ResourceFindRequest) expect(client.options[:request].name).to eq('Test Name') expect(client.options[:request].active).to eq(false) diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index 1da51f5e..1f779917 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -14,7 +14,7 @@ end subject do - described_class.new({ :host => '127.0.0.1', :port => 9400 }) + described_class.new(:host => '127.0.0.1', :port => 9400) end describe '#run' do diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 2c44876e..9260e567 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -64,10 +64,11 @@ it 'initializes a client object for this service' do client = double('client') expect(::Protobuf::Rpc::Client).to receive(:new) - .with(hash_including({ :service => subject, - :host => subject.host, - :port => subject.port })) - .and_return(client) + .with(hash_including( + :service => subject, + :host => subject.host, + :port => subject.port + )).and_return(client) expect(subject.client).to eq client end end From f4601511d2cdff7a13b5f30218611235e134b136 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:57:56 -0700 Subject: [PATCH 090/298] Refresh RuboCop config --- .rubocop_todo.yml | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 90b35c33..b6353d88 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,5 +1,5 @@ # This configuration was generated by `rubocop --auto-gen-config` -# on 2014-10-14 08:30:47 -0700 using RuboCop version 0.26.1. +# on 2014-10-15 12:57:34 -0700 using RuboCop version 0.26.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -9,21 +9,21 @@ Metrics/BlockNesting: Max: 5 -# Offense count: 9 +# Offense count: 8 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 236 + Max: 233 # Offense count: 3 Metrics/CyclomaticComplexity: Max: 11 -# Offense count: 515 +# Offense count: 505 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 196 -# Offense count: 45 +# Offense count: 47 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 41 @@ -122,7 +122,7 @@ Style/IfUnlessModifier: Style/IndentationConsistency: Enabled: false -# Offense count: 2 +# Offense count: 1 # Cop supports --auto-correct. Style/IndentationWidth: Enabled: false @@ -142,11 +142,6 @@ Style/LeadingCommentSpace: Style/MethodDefParentheses: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -Style/MultilineBlockLayout: - Enabled: false - # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: @@ -158,11 +153,6 @@ Style/Next: Style/NonNilCheck: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -Style/Not: - Enabled: false - # Offense count: 46 # Cop supports --auto-correct. Style/NumericLiterals: @@ -172,7 +162,7 @@ Style/NumericLiterals: Style/OpMethod: Enabled: false -# Offense count: 15 +# Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: @@ -222,7 +212,7 @@ Style/SelfAssignment: Style/Semicolon: Enabled: false -# Offense count: 66 +# Offense count: 67 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/SignalException: @@ -272,12 +262,12 @@ Style/SpaceBeforeBlockBraces: Style/SpaceInsideBlockBraces: Enabled: false -# Offense count: 134 +# Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: Enabled: false -# Offense count: 4 +# Offense count: 2 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. Style/SpaceInsideHashLiteralBraces: @@ -304,13 +294,13 @@ Style/StringLiterals: Style/Tab: Enabled: false -# Offense count: 57 +# Offense count: 56 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/TrailingBlankLines: Enabled: false -# Offense count: 35 +# Offense count: 47 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. Style/TrailingComma: @@ -326,7 +316,7 @@ Style/TrivialAccessors: Style/UnlessElse: Enabled: false -# Offense count: 6 +# Offense count: 2 # Cop supports --auto-correct. Style/UnneededPercentQ: Enabled: false From 592717ad5795a1ceee916131499751efe427cb23 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 14:50:28 -0700 Subject: [PATCH 091/298] Actually run the tests again. Damnit, `#exec`! Also generate encoding comments for all the files, needed for 1.9.3. --- Rakefile | 10 ++++++---- .../descriptors/google/protobuf/compiler/plugin.pb.rb | 2 ++ .../descriptors/google/protobuf/descriptor.pb.rb | 2 ++ lib/protobuf/generators/file_generator.rb | 2 ++ lib/protobuf/rpc/dynamic_discovery.pb.rb | 2 ++ lib/protobuf/rpc/rpc.pb.rb | 2 ++ spec/functional/zmq_server_spec.rb | 2 +- spec/spec_helper.rb | 8 -------- spec/support/test/defaults.pb.rb | 2 ++ spec/support/test/enum.pb.rb | 2 ++ spec/support/test/extended.pb.rb | 2 ++ spec/support/test/google_unittest_import.pb.rb | 2 ++ spec/support/test/google_unittest_import_public.pb.rb | 2 ++ spec/support/test/multi_field_extensions.pb.rb | 2 ++ spec/support/test/resource.pb.rb | 2 ++ 15 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Rakefile b/Rakefile index 77ab62e9..6423d7ad 100644 --- a/Rakefile +++ b/Rakefile @@ -13,7 +13,7 @@ require 'rubocop/rake_task' RSpec::Core::RakeTask.new(:spec) RuboCop::RakeTask.new -task :default => [:spec, :rubocop] +task :default => ['compile:spec', 'compile:rpc', :spec, :rubocop] desc 'Run specs' namespace :compile do @@ -21,19 +21,21 @@ namespace :compile do desc 'Compile spec protos in spec/supprt/ directory' task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) - cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + proto_files = Dir[File.join(proto_path, '**', '*.proto')] + cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')}} puts cmd - exec(cmd) + system(cmd) end desc 'Compile rpc protos in protos/ directory' task :rpc do proto_path = ::File.expand_path('../proto', __FILE__) + proto_files = Dir[File.join(proto_path, '**', '*.proto')] output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) - cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{File.join(proto_path, '**', '*.proto')}} + cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')}} puts cmd system(cmd) diff --git a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb index 5dd8eddf..4d3f72bb 100644 --- a/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/compiler/plugin.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb index c4835c12..54de4e2e 100644 --- a/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb +++ b/lib/protobuf/descriptors/google/protobuf/descriptor.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 92ac87ca..097cd818 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -92,6 +92,8 @@ def map_extensions(descriptor, namespaces) end def print_file_comment + puts "# encoding: utf-8" + puts puts "##" puts "# This file is auto-generated. DO NOT EDIT!" puts "#" diff --git a/lib/protobuf/rpc/dynamic_discovery.pb.rb b/lib/protobuf/rpc/dynamic_discovery.pb.rb index 1ee963ca..2070b475 100644 --- a/lib/protobuf/rpc/dynamic_discovery.pb.rb +++ b/lib/protobuf/rpc/dynamic_discovery.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/lib/protobuf/rpc/rpc.pb.rb b/lib/protobuf/rpc/rpc.pb.rb index 1a5e7e21..d302de54 100644 --- a/lib/protobuf/rpc/rpc.pb.rb +++ b/lib/protobuf/rpc/rpc.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 1b52d68f..72b4d72b 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -42,7 +42,7 @@ it 'runs under heavy load' do 10.times do - 5.times do + 5.times.map do Thread.new do client = ::Test::ResourceService.client diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 20cd2fe4..07b108ea 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -26,14 +26,6 @@ # Get rid of the deprecation env var if present (messes with specs). ENV.delete("PB_IGNORE_DEPRECATIONS") -::RSpec.configure do |c| - c.before(:suite) do - require 'rake' - load ::File.expand_path('../../Rakefile', __FILE__) - ::Rake::Task['compile:spec'].invoke - end -end - support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) Dir[support_proto_glob].each { |proto_file| require proto_file } diff --git a/spec/support/test/defaults.pb.rb b/spec/support/test/defaults.pb.rb index 9849e8a5..24c6c4bf 100644 --- a/spec/support/test/defaults.pb.rb +++ b/spec/support/test/defaults.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/enum.pb.rb b/spec/support/test/enum.pb.rb index ae1bdb61..8f68cb80 100644 --- a/spec/support/test/enum.pb.rb +++ b/spec/support/test/enum.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/extended.pb.rb b/spec/support/test/extended.pb.rb index 2f3a8602..a9edae82 100644 --- a/spec/support/test/extended.pb.rb +++ b/spec/support/test/extended.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/google_unittest_import.pb.rb b/spec/support/test/google_unittest_import.pb.rb index 1c37587c..1e49a5c3 100644 --- a/spec/support/test/google_unittest_import.pb.rb +++ b/spec/support/test/google_unittest_import.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/google_unittest_import_public.pb.rb b/spec/support/test/google_unittest_import_public.pb.rb index 68a35d5c..18434960 100644 --- a/spec/support/test/google_unittest_import_public.pb.rb +++ b/spec/support/test/google_unittest_import_public.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/multi_field_extensions.pb.rb b/spec/support/test/multi_field_extensions.pb.rb index 15ae94ed..276041ad 100644 --- a/spec/support/test/multi_field_extensions.pb.rb +++ b/spec/support/test/multi_field_extensions.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # diff --git a/spec/support/test/resource.pb.rb b/spec/support/test/resource.pb.rb index 0605bacc..622f33e4 100644 --- a/spec/support/test/resource.pb.rb +++ b/spec/support/test/resource.pb.rb @@ -1,3 +1,5 @@ +# encoding: utf-8 + ## # This file is auto-generated. DO NOT EDIT! # From fe75516b59c241c93273618afa9365b93740b2ec Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:45:24 -0700 Subject: [PATCH 092/298] Style/WhileUntilDo --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/servers/zmq/broker.rb | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b6353d88..05781c3b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -321,11 +321,6 @@ Style/UnlessElse: Style/UnneededPercentQ: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -Style/WhileUntilDo: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 3be992db..4f70fbb5 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -55,7 +55,7 @@ def check_and_process_backend readables_include_backend = @poller.readables.include?(@backend_socket) message_count_read_from_backend = 0 - while readables_include_backend && message_count_read_from_backend < backend_poll_weight do + while readables_include_backend && message_count_read_from_backend < backend_poll_weight message_count_read_from_backend += 1 process_backend @poller.poll_nonblock @@ -67,7 +67,7 @@ def check_and_process_frontend readables_include_frontend = @poller.readables.include?(@frontend_socket) message_count_read_from_frontend = 0 - while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight do + while readables_include_frontend && message_count_read_from_frontend < frontend_poll_weight message_count_read_from_frontend += 1 process_frontend break unless local_queue_available? # no need to read frontend just to throw away messages, will prioritize backend when full From 725e09f3339bedc09416340756e408525536f862 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:46:02 -0700 Subject: [PATCH 093/298] Style/UnneededPercentQ --- .rubocop_todo.yml | 5 ----- spec/lib/protobuf/generators/extension_generator_spec.rb | 4 ++-- spec/lib/protobuf/generators/service_generator_spec.rb | 4 ++-- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 05781c3b..c643c17b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -316,11 +316,6 @@ Style/TrivialAccessors: Style/UnlessElse: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -Style/UnneededPercentQ: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 1afc8b98..5c742480 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -24,13 +24,13 @@ describe '#compile' do let(:compiled) do - %q{class FooBar < ::Protobuf::Message + 'class FooBar < ::Protobuf::Message field 1 field 2 field 3 end -} +' end it 'compiles the a class with the extension fields' do diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 0611e4be..33894dc9 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -23,12 +23,12 @@ describe '#compile' do let(:compiled) do - %q{class TestService < ::Protobuf::Rpc::Service + 'class TestService < ::Protobuf::Rpc::Service rpc :search, FooRequest, FooResponse rpc :foo_bar, ::Foo::Request, ::Bar::Response end -} +' end it 'compiles the service and it\'s rpc methods' do From 92e7c09d7a5bad46d2c82a073fa26bb5ba677ed5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:49:14 -0700 Subject: [PATCH 094/298] Style/UnlessElse --- .rubocop_todo.yml | 4 ---- lib/protobuf/rpc/client.rb | 8 ++++---- 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c643c17b..c871d0d8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -312,10 +312,6 @@ Style/TrailingComma: Style/TrivialAccessors: Enabled: false -# Offense count: 1 -Style/UnlessElse: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index 57fc6b57..d8ebe349 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -105,10 +105,7 @@ def on_success=(callable) # def method_missing(method_name, *params) service = options[:service] - unless service.rpc_method?(method_name) - logger.error { sign_message("#{service.name}##{method_name} not rpc method, passing to super") } - super(method_name, *params) - else + if service.rpc_method?(method_name) logger.debug { sign_message("#{service.name}##{method_name}") } rpc = service.rpcs[method_name.to_sym] @@ -131,6 +128,9 @@ def method_missing(method_name, *params) end send_request + else + logger.error { sign_message("#{service.name}##{method_name} not rpc method, passing to super") } + super(method_name, *params) end end From b02146cf1416a6db611650b4d825acbc5f40c27e Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Mon, 27 Oct 2014 09:17:39 -0700 Subject: [PATCH 095/298] Inspect looks like an object, not a hash --- lib/protobuf/message.rb | 6 +++++- spec/lib/protobuf/message_spec.rb | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 3f95ab6e..2d72cfcd 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -86,7 +86,11 @@ def has_field?(name) end def inspect - to_hash.inspect + attrs = self.class.fields.map do |field| + [ field.name, send(field.name).inspect ].join('=') + end.join(' ') + + "#<#{self.class} #{attrs}>" end def respond_to_has?(key) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 97acbb4d..6a8efc0c 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -359,6 +359,24 @@ end + describe '#inspect' do + before do + MyMessage = Class.new(Protobuf::Message) do + optional :string, :name, 1 + repeated :int, :counts, 2 + optional :int, :timestamp, 2 + end + end + + after { remove_const(:MyMessage) } + + it 'lists the fields' do + proto = message.new(:name => 'wooo', :counts => [ 1, 2, 3 ]) + expect(proto.inspect).to eq \ + '#' + end + end + describe '#to_hash' do context 'generating values for an ENUM field' do it 'converts the enum to its tag representation' do From 3e3f10702d656330b57bb23c14a0e14278d2cc32 Mon Sep 17 00:00:00 2001 From: Zach Margolis Date: Mon, 27 Oct 2014 09:48:50 -0700 Subject: [PATCH 096/298] Use stub_const --- spec/lib/protobuf/message_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 6a8efc0c..a45337bb 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -360,18 +360,18 @@ end describe '#inspect' do - before do - MyMessage = Class.new(Protobuf::Message) do + let(:klass) do + Class.new(Protobuf::Message) do optional :string, :name, 1 repeated :int, :counts, 2 optional :int, :timestamp, 2 end end - after { remove_const(:MyMessage) } + before { stub_const('MyMessage', klass) } it 'lists the fields' do - proto = message.new(:name => 'wooo', :counts => [ 1, 2, 3 ]) + proto = klass.new(:name => 'wooo', :counts => [ 1, 2, 3 ]) expect(proto.inspect).to eq \ '#' end From 6728ee3e5dff354f2f83616a93e149c5a2b89a9f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:50:34 -0700 Subject: [PATCH 097/298] Style/TrivialAccessors --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 6 ----- lib/protobuf.rb | 34 +++++++++++++-------------- lib/protobuf/enum.rb | 4 ++-- lib/protobuf/generators/printable.rb | 16 ++++++------- lib/protobuf/logging.rb | 4 ++-- lib/protobuf/rpc/service.rb | 22 ++++++++--------- lib/protobuf/rpc/service_directory.rb | 8 ++----- lib/protobuf/rpc/stat.rb | 4 +--- spec/lib/protobuf_spec.rb | 8 +++---- spec/support/server.rb | 8 ++----- 11 files changed, 52 insertions(+), 66 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 20b78655..24b47ee2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -11,3 +11,7 @@ Style/IndentHash: Style/TrailingComma: EnforcedStyleForMultiline: comma + +Style/TrivialAccessors: + AllowDSLWriters: true + AllowPredicates: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c871d0d8..84841a89 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -306,12 +306,6 @@ Style/TrailingBlankLines: Style/TrailingComma: Enabled: false -# Offense count: 12 -# Cop supports --auto-correct. -# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, Whitelist. -Style/TrivialAccessors: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 38bae844..fb3129ec 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -19,18 +19,16 @@ module Protobuf module_function - # Client Host - # - # Default: `hostname` of the system - # - # The name or address of the host to use during client RPC calls. - def self.client_host - @_client_host ||= `hostname`.chomp + class << self + # Client Host + # + # Default: `hostname` of the system + # + # The name or address of the host to use during client RPC calls. + attr_accessor :client_host end - def self.client_host=(host) - @_client_host = host - end + self.client_host = Socket.gethostname # Connector Type # @@ -39,12 +37,12 @@ def self.client_host=(host) # Symbol value which denotes the type of connector to use # during client requests to an RPC server. def self.connector_type - @_connector_type ||= DEFAULT_CONNECTOR + @connector_type ||= DEFAULT_CONNECTOR end def self.connector_type=(type) raise ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type) - @_connector_type = type + @connector_type = type end # GC Pause during server requests @@ -56,12 +54,12 @@ def self.connector_type=(type) # Once the request is completed, the GC is enabled again. # This optomization provides a huge boost in speed to rpc requests. def self.gc_pause_server_request? - return @_gc_pause_server_request unless @_gc_pause_server_request.nil? + return @gc_pause_server_request unless @gc_pause_server_request.nil? self.gc_pause_server_request = false end def self.gc_pause_server_request=(value) - @_gc_pause_server_request = !!value + @gc_pause_server_request = !!value end # Print Deprecation Warnings @@ -75,12 +73,12 @@ def self.gc_pause_server_request=(value) # # The rpc_server option will override the ENV setting. def self.print_deprecation_warnings? - return @_print_deprecation_warnings unless @_print_deprecation_warnings.nil? + return @print_deprecation_warnings unless @print_deprecation_warnings.nil? self.print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true end def self.print_deprecation_warnings=(value) - @_print_deprecation_warnings = !!value + @print_deprecation_warnings = !!value end # Permit unknown field on Message initialization @@ -90,11 +88,11 @@ def self.print_deprecation_warnings=(value) # Simple boolean to define whether we want to permit unknown fields # on Message intialization; otherwise a ::Protobuf::FieldNotDefinedError is thrown. def self.ignore_unknown_fields? - !defined?(@_ignore_unknown_fields) || @_ignore_unknown_fields + !defined?(@ignore_unknown_fields) || @ignore_unknown_fields end def self.ignore_unknown_fields=(value) - @_ignore_unknown_fields = !!value + @ignore_unknown_fields = !!value end end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index f179f634..62e9b423 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -78,8 +78,8 @@ def self.define(name, tag) # Public: All defined enums. # - def self.enums - @enums + class << self + attr_reader :enums end # Public: Get an array of Enum objects with the given tag. diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 34440ad0..31874b7f 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -11,9 +11,13 @@ module Printable # def init_printer(indent_level) @io = ::StringIO.new - @_indent_level = indent_level.to_i || 0 + self.current_indent = indent_level.to_i end + protected + + attr_accessor :current_indent + private # Print a one-line comment. @@ -22,10 +26,6 @@ def comment(message) puts "# #{message}" end - def current_indent - @_indent_level - end - # Print a "header" comment. # # header("Lorem ipsum dolor") @@ -43,7 +43,7 @@ def header(message) # (after the block is finished). # def indent - @_indent_level += 1 + self.current_indent += 1 yield outdent end @@ -68,7 +68,7 @@ def modulize(name) # Decrease the indent level. Cannot be negative. # def outdent - @_indent_level -= 1 unless @_indent_level == 0 + self.current_indent -= 1 unless current_indent.zero? end # Return the parent class for a given type. @@ -136,7 +136,7 @@ def print_require(file) # def puts(message = nil) if message - @io.puts((" " * @_indent_level) + message) + @io.puts((" " * current_indent) + message) else @io.puts end diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 273d159d..bdaea254 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -14,8 +14,8 @@ def self.logger defined?(@logger) ? @logger : initialize_logger end - def self.logger=(new_logger) - @logger = new_logger + class << self + attr_writer :logger end def logger diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 48148231..54d6f8a6 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -54,13 +54,13 @@ def self.configure(config = {}) # The host location of the service. # def self.host - @_host ||= DEFAULT_HOST + @host ||= DEFAULT_HOST end # The host location setter. # - def self.host=(new_host) - @_host = new_host + class << self + attr_writer :host end # An array of defined service classes that contain implementation @@ -88,13 +88,13 @@ def self.located_at(location) # The port of the service on the destination server. # def self.port - @_port ||= DEFAULT_PORT + @port ||= DEFAULT_PORT end # The port location setter. # - def self.port=(new_port) - @_port = new_port + class << self + attr_writer :port end # Define an rpc method with the given request and response types. @@ -108,7 +108,7 @@ def self.rpc(method, request_type, response_type) # Hash containing the set of methods defined via `rpc`. # def self.rpcs - @_rpcs ||= {} + @rpcs ||= {} end # Check if the given method name is a known rpc endpoint. @@ -132,7 +132,7 @@ def callable_rpc_method(method_name) # Response object for this rpc cycle. Not assignable. # def response - @_response ||= response_type.new + @response ||= response_type.new end # Convenience method to get back to class method. @@ -150,7 +150,7 @@ def rpcs private def request_type - @_request_type ||= env.request_type + @request_type ||= env.request_type end # Sugar to make an rpc method feel like a controller method. @@ -158,12 +158,12 @@ def request_type # object returned by the response reader. # def respond_with(candidate) - @_response = candidate + @response = candidate end alias_method :return_from_whence_you_came, :respond_with def response_type - @_response_type ||= env.response_type + @response_type ||= env.response_type end # Automatically fail a service method. diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index a2aef5e4..d293f4a3 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -17,7 +17,7 @@ class ServiceDirectory DEFAULT_PORT = 53000 DEFAULT_TIMEOUT = 1 - class Listing < Delegator + class Listing < SimpleDelegator attr_reader :expires_at def initialize(server) @@ -45,13 +45,9 @@ def ttl end def update(server) - @server = server + __setobj__(server) @expires_at = Time.now.to_i + ttl end - - def __getobj__ - @server - end end # Class Methods diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 5ab9407e..eea4c273 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -17,9 +17,7 @@ def initialize(mode = :SERVER) start end - def client=(client_host) - @client = client_host - end + attr_writer :client def client @client || nil diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index f2a3a528..0f238013 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -4,7 +4,7 @@ describe ::Protobuf do describe '.client_host' do - after { ::Protobuf.instance_variable_set(:@_client_host, nil) } + after { ::Protobuf.client_host = nil } subject { ::Protobuf.client_host } @@ -20,7 +20,7 @@ end describe '.connector_type' do - before { described_class.instance_variable_set(:@_connector_type, nil) } + before { described_class.instance_variable_set(:@connector_type, nil) } it 'defaults to socket' do expect(described_class.connector_type).to eq :socket @@ -43,7 +43,7 @@ end describe '.gc_pause_server_request?' do - before { described_class.instance_variable_set(:@_gc_pause_server_request, nil) } + before { described_class.instance_variable_set(:@gc_pause_server_request, nil) } it 'defaults to a false value' do expect(described_class.gc_pause_server_request?).to be false @@ -56,7 +56,7 @@ end describe '.print_deprecation_warnings?' do - before { described_class.instance_variable_set(:@_print_deprecation_warnings, nil) } + before { described_class.instance_variable_set(:@print_deprecation_warnings, nil) } it 'defaults to a true value' do expect(described_class.print_deprecation_warnings?).to be true diff --git a/spec/support/server.rb b/spec/support/server.rb index 55e4dbea..d572b1db 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -13,12 +13,8 @@ module StubProtobufServerFactory def self.build(delay) new_server = Class.new(Protobuf::Rpc::Socket::Server) do - def self.sleep_interval - @sleep_interval - end - - def self.sleep_interval=(si) - @sleep_interval = si + class << self + attr_accessor :sleep_interval end def post_init From e351f581c3e9602d548ed0b099113bac7a95688b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:50:58 -0700 Subject: [PATCH 098/298] Style/Tab --- .rubocop_todo.yml | 5 ----- spec/lib/protobuf/enum_spec.rb | 14 +++++++------- 2 files changed, 7 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 84841a89..fd395013 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -289,11 +289,6 @@ Style/SpecialGlobalVars: Style/StringLiterals: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -Style/Tab: - Enabled: false - # Offense count: 56 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 17718801..f532627a 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -200,15 +200,15 @@ end end - subject { Test::EnumTestType::ONE } + subject { Test::EnumTestType::ONE } specify { expect(subject.class).to eq(Fixnum) } specify { expect(subject.parent_class).to eq(Test::EnumTestType) } - specify { expect(subject.name).to eq(:ONE) } - specify { expect(subject.tag).to eq(1) } - specify { expect(subject.value).to eq(1) } - specify { expect(subject.to_hash_value).to eq(1) } - specify { expect(subject.to_s).to eq("1") } - specify { expect(subject.inspect).to eq('#') } + specify { expect(subject.name).to eq(:ONE) } + specify { expect(subject.tag).to eq(1) } + specify { expect(subject.value).to eq(1) } + specify { expect(subject.to_hash_value).to eq(1) } + specify { expect(subject.to_s).to eq("1") } + specify { expect(subject.inspect).to eq('#') } specify { expect(subject.to_s(:tag)).to eq("1") } specify { expect(subject.to_s(:name)).to eq("ONE") } From 079a78bf47d3476e506a1694eacfff64bc7e947f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 10:52:23 -0700 Subject: [PATCH 099/298] Style/TrailingBlankLines --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 6 ------ bin/protoc-gen-ruby | 1 - lib/protobuf/code_generator.rb | 1 - lib/protobuf/decoder.rb | 1 - lib/protobuf/encoder.rb | 1 - lib/protobuf/enum.rb | 1 - lib/protobuf/field/base_field.rb | 1 - lib/protobuf/field/bool_field.rb | 1 - lib/protobuf/field/bytes_field.rb | 1 - lib/protobuf/field/double_field.rb | 1 - lib/protobuf/field/enum_field.rb | 1 - lib/protobuf/field/field_array.rb | 1 - lib/protobuf/field/fixed64_field.rb | 1 - lib/protobuf/field/float_field.rb | 1 - lib/protobuf/field/int32_field.rb | 1 - lib/protobuf/field/int64_field.rb | 1 - lib/protobuf/field/integer_field.rb | 1 - lib/protobuf/field/message_field.rb | 1 - lib/protobuf/field/sfixed32_field.rb | 1 - lib/protobuf/field/sfixed64_field.rb | 1 - lib/protobuf/field/signed_integer_field.rb | 1 - lib/protobuf/field/sint32_field.rb | 1 - lib/protobuf/field/sint64_field.rb | 1 - lib/protobuf/field/string_field.rb | 1 - lib/protobuf/field/uint32_field.rb | 1 - lib/protobuf/field/uint64_field.rb | 1 - lib/protobuf/field/varint_field.rb | 1 - lib/protobuf/generators/base.rb | 1 - lib/protobuf/generators/enum_generator.rb | 1 - lib/protobuf/generators/extension_generator.rb | 1 - lib/protobuf/generators/field_generator.rb | 1 - lib/protobuf/generators/file_generator.rb | 1 - lib/protobuf/generators/group_generator.rb | 1 - lib/protobuf/generators/message_generator.rb | 1 - lib/protobuf/generators/printable.rb | 1 - lib/protobuf/generators/service_generator.rb | 1 - lib/protobuf/message/fields.rb | 1 - lib/protobuf/rpc/stat.rb | 1 - lib/protobuf/socket.rb | 1 - spec/functional/socket_server_spec.rb | 1 - spec/lib/protobuf/generators/base_spec.rb | 1 - spec/lib/protobuf/generators/extension_generator_spec.rb | 1 - spec/lib/protobuf/generators/field_generator_spec.rb | 1 - spec/lib/protobuf/generators/file_generator_spec.rb | 1 - spec/lib/protobuf/generators/service_generator_spec.rb | 1 - 46 files changed, 4 insertions(+), 50 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 24b47ee2..ad64da6e 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,6 +9,10 @@ Style/CaseIndentation: Style/IndentHash: EnforcedStyle: consistent +Style/TrailingBlankLines: + Exclude: + - '**/*.pb.rb' + Style/TrailingComma: EnforcedStyleForMultiline: comma diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fd395013..b327328b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -289,12 +289,6 @@ Style/SpecialGlobalVars: Style/StringLiterals: Enabled: false -# Offense count: 56 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/TrailingBlankLines: - Enabled: false - # Offense count: 47 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. diff --git a/bin/protoc-gen-ruby b/bin/protoc-gen-ruby index 71e0be47..c0f7d37b 100755 --- a/bin/protoc-gen-ruby +++ b/bin/protoc-gen-ruby @@ -14,4 +14,3 @@ request_bytes = STDIN.read code_generator = ::Protobuf::CodeGenerator.new(request_bytes) response_bytes = code_generator.response_bytes STDOUT.print(response_bytes) - diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index df4b5ccf..e44fe2ac 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -38,4 +38,3 @@ def response_bytes end end - diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index b3b9eb0e..67e5f8ec 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -71,4 +71,3 @@ def self.read_varint(stream) end end - diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 202c672f..1eec5cf7 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -59,4 +59,3 @@ def write_pair(field, value) end end - diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 62e9b423..d2d8646a 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -316,4 +316,3 @@ def value alias_method :to_hash_value, :to_i end end - diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 902dda63..9d6efe75 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -264,4 +264,3 @@ def validate_packed_field end end end - diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index a002bbf7..6e789ed3 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -50,4 +50,3 @@ def define_getter end end end - diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 6b7e6c17..c095629f 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -78,4 +78,3 @@ def define_setter end end end - diff --git a/lib/protobuf/field/double_field.rb b/lib/protobuf/field/double_field.rb index b520fad1..31eb1b34 100644 --- a/lib/protobuf/field/double_field.rb +++ b/lib/protobuf/field/double_field.rb @@ -23,4 +23,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 15bfd94c..4b362248 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -68,4 +68,3 @@ def typed_default_value end end end - diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index afc2fef5..cf46323f 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -83,4 +83,3 @@ def raise_type_error(val) end end end - diff --git a/lib/protobuf/field/fixed64_field.rb b/lib/protobuf/field/fixed64_field.rb index d47ad327..ef825433 100644 --- a/lib/protobuf/field/fixed64_field.rb +++ b/lib/protobuf/field/fixed64_field.rb @@ -26,4 +26,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/float_field.rb b/lib/protobuf/field/float_field.rb index 4d138972..3c6ac8a4 100644 --- a/lib/protobuf/field/float_field.rb +++ b/lib/protobuf/field/float_field.rb @@ -39,4 +39,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/int32_field.rb b/lib/protobuf/field/int32_field.rb index a95b75a8..4a7865f9 100644 --- a/lib/protobuf/field/int32_field.rb +++ b/lib/protobuf/field/int32_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/int64_field.rb b/lib/protobuf/field/int64_field.rb index b0080819..18538f4b 100644 --- a/lib/protobuf/field/int64_field.rb +++ b/lib/protobuf/field/int64_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/integer_field.rb b/lib/protobuf/field/integer_field.rb index 49435f32..5eb3b064 100644 --- a/lib/protobuf/field/integer_field.rb +++ b/lib/protobuf/field/integer_field.rb @@ -21,4 +21,3 @@ def encode(value) end end end - diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 447455e4..5161edbe 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -63,4 +63,3 @@ def define_setter end end end - diff --git a/lib/protobuf/field/sfixed32_field.rb b/lib/protobuf/field/sfixed32_field.rb index 242a1850..9f9b64e9 100644 --- a/lib/protobuf/field/sfixed32_field.rb +++ b/lib/protobuf/field/sfixed32_field.rb @@ -25,4 +25,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/sfixed64_field.rb b/lib/protobuf/field/sfixed64_field.rb index f639cedd..fc296483 100644 --- a/lib/protobuf/field/sfixed64_field.rb +++ b/lib/protobuf/field/sfixed64_field.rb @@ -26,4 +26,3 @@ def wire_type end end end - diff --git a/lib/protobuf/field/signed_integer_field.rb b/lib/protobuf/field/signed_integer_field.rb index 821db3bf..8945f771 100644 --- a/lib/protobuf/field/signed_integer_field.rb +++ b/lib/protobuf/field/signed_integer_field.rb @@ -27,4 +27,3 @@ def encode(value) end end end - diff --git a/lib/protobuf/field/sint32_field.rb b/lib/protobuf/field/sint32_field.rb index 95784c85..3af0ce98 100644 --- a/lib/protobuf/field/sint32_field.rb +++ b/lib/protobuf/field/sint32_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/sint64_field.rb b/lib/protobuf/field/sint64_field.rb index a6d0056d..2aba7dfa 100644 --- a/lib/protobuf/field/sint64_field.rb +++ b/lib/protobuf/field/sint64_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index 83fbd4ae..d1045a03 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -32,4 +32,3 @@ def encode(value) end end end - diff --git a/lib/protobuf/field/uint32_field.rb b/lib/protobuf/field/uint32_field.rb index 6b60b898..50fa8fef 100644 --- a/lib/protobuf/field/uint32_field.rb +++ b/lib/protobuf/field/uint32_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/uint64_field.rb b/lib/protobuf/field/uint64_field.rb index eafbda32..8a060f14 100644 --- a/lib/protobuf/field/uint64_field.rb +++ b/lib/protobuf/field/uint64_field.rb @@ -19,4 +19,3 @@ def self.min end end end - diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 35c68bab..448610dd 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -65,4 +65,3 @@ def wire_type end end end - diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index 4981488f..800e63fe 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -68,4 +68,3 @@ def type_namespace end end end - diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index 90b70221..57b7416b 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -39,4 +39,3 @@ def build_value(enum_value_descriptor) end end end - diff --git a/lib/protobuf/generators/extension_generator.rb b/lib/protobuf/generators/extension_generator.rb index 57e34117..36c5c581 100644 --- a/lib/protobuf/generators/extension_generator.rb +++ b/lib/protobuf/generators/extension_generator.rb @@ -25,4 +25,3 @@ def compile end end end - diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index a252a445..7797afbf 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -129,4 +129,3 @@ def verbatim_default_value end end end - diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 097cd818..5f62f7d1 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -138,4 +138,3 @@ def fully_qualified_token?(token) end end end - diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index 84d95176..8c6a90c3 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -110,4 +110,3 @@ def to_s end end end - diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index c9ea7af1..81505f71 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -96,4 +96,3 @@ def message_extension_fields end end end - diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 31874b7f..268ce42f 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -158,4 +158,3 @@ def print_contents end end end - diff --git a/lib/protobuf/generators/service_generator.rb b/lib/protobuf/generators/service_generator.rb index 2c5a4891..bc2f5d8d 100644 --- a/lib/protobuf/generators/service_generator.rb +++ b/lib/protobuf/generators/service_generator.rb @@ -24,4 +24,3 @@ def build_method(method_descriptor) end end end - diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 30023e6a..a89596cc 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -119,4 +119,3 @@ def raise_if_name_collision(field_name) end end end - diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index eea4c273..36a9c2e6 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -95,4 +95,3 @@ def trace_id end end end - diff --git a/lib/protobuf/socket.rb b/lib/protobuf/socket.rb index 7731cfa0..a8feb2fe 100644 --- a/lib/protobuf/socket.rb +++ b/lib/protobuf/socket.rb @@ -19,4 +19,3 @@ require 'protobuf/rpc/servers/socket/server' require 'protobuf/rpc/connectors/socket' - diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index bf0c283a..7d1b7277 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -57,4 +57,3 @@ expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end end - diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index a7a303e4..6feab2b1 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -81,4 +81,3 @@ def compile end end - diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 5c742480..559f21b8 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -40,4 +40,3 @@ end end - diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index e03ee487..c329ea04 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -100,4 +100,3 @@ end end - diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 56b05e37..bfb699d6 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -30,4 +30,3 @@ end end - diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 33894dc9..0748ced2 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -44,4 +44,3 @@ end end - From b8505e0498ccefa585afb99ca4075bc7ccc7f22b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:15:29 -0700 Subject: [PATCH 100/298] Style/SpecialGlobalVars --- .rubocop_todo.yml | 5 ----- Rakefile | 4 ++-- lib/protobuf/rpc/connectors/zmq.rb | 8 ++++---- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- protobuf.gemspec | 2 +- spec/spec_helper.rb | 6 +++--- 7 files changed, 12 insertions(+), 17 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b327328b..a621c9b6 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -278,11 +278,6 @@ Style/SpaceInsideHashLiteralBraces: Style/SpaceInsideParens: Enabled: false -# Offense count: 12 -# Cop supports --auto-correct. -Style/SpecialGlobalVars: - Enabled: false - # Offense count: 464 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/Rakefile b/Rakefile index 6423d7ad..7c8ce81a 100644 --- a/Rakefile +++ b/Rakefile @@ -1,5 +1,5 @@ -$: << ::File.expand_path('../', __FILE__) -$: << ::File.expand_path('../spec', __FILE__) +$LOAD_PATH << ::File.expand_path('../', __FILE__) +$LOAD_PATH << ::File.expand_path('../spec', __FILE__) require 'fileutils' require 'rubygems' diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 598e068c..4e331c7b 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -259,13 +259,13 @@ def zmq_eagain_error_check(return_code, source) raise ZmqEagainError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR else raise <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR end end @@ -276,7 +276,7 @@ def zmq_error_check(return_code, source) raise <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR end end @@ -286,7 +286,7 @@ def zmq_recoverable_error_check(return_code, source) raise ZmqRecoverableError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 2fe3066b..c548722c 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -296,7 +296,7 @@ def start_worker begin ::Protobuf::Rpc::Zmq::Worker.new(server).run rescue => e - message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($/)}" + message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($INPUT_RECORD_SEPARATOR)}" $stderr.puts(message) logger.error { message } end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index f16bbcfd..4a991ab0 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -23,7 +23,7 @@ def zmq_error_check(return_code, source = nil) raise <<-ERROR Last ZMQ API call #{source ? "to #{source}" : ""} failed with "#{::ZMQ::Util.error_string}". - #{caller(1).join($/)} + #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR end end diff --git a/protobuf.gemspec b/protobuf.gemspec index 495a8aa7..3549a82f 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -1,5 +1,5 @@ # encoding: UTF-8 -$:.push ::File.expand_path("../lib", __FILE__) +$LOAD_PATH.push ::File.expand_path("../lib", __FILE__) require "protobuf/version" ::Gem::Specification.new do |s| diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 07b108ea..d588e54e 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -5,14 +5,14 @@ require 'pry' # require 'rspec/its' -$: << ::File.expand_path('../..', __FILE__) -$: << ::File.expand_path('../support', __FILE__) +$LOAD_PATH << ::File.expand_path('../..', __FILE__) +$LOAD_PATH << ::File.expand_path('../support', __FILE__) require 'protobuf' require 'protobuf/rpc/server' require ::File.expand_path('../support/all', __FILE__) -$: << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) +$LOAD_PATH << ::File.expand_path("../../lib/protobuf/descriptors", __FILE__) require 'google/protobuf/compiler/plugin.pb' # Including a way to turn on debug logger for spec runs From e6152abf68e85bd40cad12cee0c64fe2012eeaae Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:16:13 -0700 Subject: [PATCH 101/298] Style/SpaceInsideParens --- .rubocop_todo.yml | 5 ----- lib/protobuf/lifecycle.rb | 4 ++-- spec/lib/protobuf/lifecycle_spec.rb | 2 +- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 2 +- spec/spec_helper.rb | 2 +- 5 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index a621c9b6..37279b2a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -273,11 +273,6 @@ Style/SpaceInsideBrackets: Style/SpaceInsideHashLiteralBraces: Enabled: false -# Offense count: 8 -# Cop supports --auto-correct. -Style/SpaceInsideParens: - Enabled: false - # Offense count: 464 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index a4d6e9a4..bc035145 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -18,7 +18,7 @@ def self.register(event_name, &blk) end end - def self.trigger( event_name, *args ) + def self.trigger(event_name, *args) if ::Protobuf.print_deprecation_warnings? $stderr.puts <<-ERROR [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. @@ -26,7 +26,7 @@ def self.trigger( event_name, *args ) ERROR end - event_name = normalized_event_name( event_name ) + event_name = normalized_event_name(event_name) ::ActiveSupport::Notifications.instrument(event_name, args) end diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index f5e098f9..de42520f 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -16,7 +16,7 @@ it "only registers blocks for event callbacks" do expect do subject.register("something") - end.to raise_error( /block/ ) + end.to raise_error(/block/) end it "calls the registered block when triggered" do diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 03734958..45142662 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -31,7 +31,7 @@ end describe "#lookup_server_uri" do - let(:service_directory) { double('ServiceDirectory', :running? => running? ) } + let(:service_directory) { double('ServiceDirectory', :running? => running?) } let(:listing) { double('Listing', :address => '127.0.0.2', :port => 9399) } let(:listings) { [listing] } let(:running?) { true } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index d588e54e..831fd671 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,7 +17,7 @@ # Including a way to turn on debug logger for spec runs if ENV.key?('DEBUG') - debug_log = ::File.expand_path('../../debug_specs.log', __FILE__ ) + debug_log = ::File.expand_path('../../debug_specs.log', __FILE__) ::Protobuf::Logging.initialize_logger(debug_log, ::Logger::DEBUG) else ::Protobuf::Logging.initialize_logger('/dev/null') From 4506cc53a4ab8effe705ae519e8614ec87627f73 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:16:41 -0700 Subject: [PATCH 102/298] Style/SpaceInsideHashLiteralBraces --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/stat.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 37279b2a..1b962b21 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -267,12 +267,6 @@ Style/SpaceInsideBlockBraces: Style/SpaceInsideBrackets: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles. -Style/SpaceInsideHashLiteralBraces: - Enabled: false - # Offense count: 464 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 36a9c2e6..7f6d063b 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -32,7 +32,7 @@ def method_name end def server=(peer) - @server = {:port => peer[0], :ip => peer[1]} + @server = { :port => peer[0], :ip => peer[1] } end def server From 1d9ff260f8baa400e78544666c593cdf498b93a3 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:17:21 -0700 Subject: [PATCH 103/298] Style/SpaceInsideBlockBraces --- .rubocop_todo.yml | 6 ------ lib/protobuf/message.rb | 2 +- spec/functional/socket_server_spec.rb | 8 ++++---- spec/functional/zmq_server_spec.rb | 4 ++-- spec/lib/protobuf/message_spec.rb | 2 +- spec/lib/protobuf/rpc/connectors/base_spec.rb | 4 ++-- 6 files changed, 10 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1b962b21..5293138b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -256,12 +256,6 @@ Style/SpaceAroundOperators: Style/SpaceBeforeBlockBraces: Enabled: false -# Offense count: 14 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. -Style/SpaceInsideBlockBraces: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 3f95ab6e..da3dfbea 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -174,7 +174,7 @@ def copy_to(object, method) object.__send__(:initialize) @values.each do |name, value| if value.is_a?(::Protobuf::Field::FieldArray) - object.__send__(name).replace(value.map {|v| duplicate.call(v)}) + object.__send__(name).replace(value.map { |v| duplicate.call(v) }) else object.__send__("#{name}=", duplicate.call(value)) end diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 7d1b7277..c6098b6c 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -38,8 +38,8 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} + c.on_success { raise "shouldn't pass" } + c.on_failure { |e| error = e } end expect(error.message).to match(/Required field.*does not have a value/) @@ -51,8 +51,8 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass"} - c.on_failure {|e| error = e} + c.on_success { raise "shouldn't pass" } + c.on_failure { |e| error = e } end expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 72b4d72b..31b627d2 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -69,7 +69,7 @@ client.find(request) do |c| c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e } + c.on_failure { |e| error = e } end expect(error.message).to match(/Required field.*does not have a value/) end @@ -83,7 +83,7 @@ client.find(request) do |c| c.on_success { raise "shouldn't pass" } - c.on_failure {|e| error = e} + c.on_failure { |e| error = e } end expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 97acbb4d..d2e06024 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -425,7 +425,7 @@ end it "does not allow string fields to be set to Numeric" do - expect { subject.name = 1}.to raise_error(/name/) + expect { subject.name = 1 }.to raise_error(/name/) end end diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index fad03f4f..fb1f0df1 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -30,7 +30,7 @@ describe '#success_cb' do it 'allows setting the success callback and calling it' do expect(subject.success_cb).to be_nil - cb = proc {|res| raise res } + cb = proc { |res| raise res } subject.success_cb = cb expect(subject.success_cb).to eq(cb) expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb' @@ -40,7 +40,7 @@ describe '#failure_cb' do it 'allows setting the failure callback and calling it' do expect(subject.failure_cb).to be_nil - cb = proc {|res| raise res } + cb = proc { |res| raise res } subject.failure_cb = cb expect(subject.failure_cb).to eq(cb) expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb' From 8dbf693ebc32650971917b2a335f2fde9859ac5d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:17:53 -0700 Subject: [PATCH 104/298] Style/SpaceBeforeBlockBraces --- .rubocop_todo.yml | 6 ------ spec/lib/protobuf/rpc/connectors/base_spec.rb | 6 +++--- spec/lib/protobuf/rpc/connectors/common_spec.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/socket_spec.rb | 4 ++-- 4 files changed, 7 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5293138b..59e2846e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -250,12 +250,6 @@ Style/SpaceAroundEqualsInParameterDefault: Style/SpaceAroundOperators: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceBeforeBlockBraces: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index fb1f0df1..5d911d2c 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -10,12 +10,12 @@ describe "#send_request" do it "raising an error when 'send_request' is not overridden" do - expect{ subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/) + expect { subject.send_request }.to raise_error(RuntimeError, /inherit a Connector/) end it "does not raise error when 'send_request' is overridden" do - new_sub = Class.new(subject.class){ def send_request; end }.new(options) - expect{ new_sub.send_request }.to_not raise_error + new_sub = Class.new(subject.class) { def send_request; end }.new(options) + expect { new_sub.send_request }.to_not raise_error end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 0710d6ab..029c9b46 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -111,7 +111,7 @@ end it "doesn't set @failure_cb when already defined" do - set_cb = lambda{ true } + set_cb = lambda { true } subject.instance_variable_set(:@failure_cb, set_cb) subject.verify_callbacks expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb) @@ -119,7 +119,7 @@ end it "doesn't set @success_cb when already defined" do - set_cb = lambda{ true } + set_cb = lambda { true } subject.instance_variable_set(:@success_cb, set_cb) subject.verify_callbacks expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb) diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index 38aeea2a..635c6590 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/socket' shared_examples "a Protobuf Connector" do - subject{ described_class.new({}) } + subject { described_class.new({}) } context "API" do # Check the API @@ -14,7 +14,7 @@ end describe Protobuf::Rpc::Connectors::Socket do - subject{ described_class.new({}) } + subject { described_class.new({}) } it_behaves_like "a Protobuf Connector" From fbaa7f158947a2e86a51e46d6c4f4750eec047e2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:18:15 -0700 Subject: [PATCH 105/298] Style/SpaceAroundOperators --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/connectors/zmq.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 59e2846e..5593d1b3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -245,11 +245,6 @@ Style/SpaceAfterNot: Style/SpaceAroundEqualsInParameterDefault: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/SpaceAroundOperators: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 4e331c7b..520fc034 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -129,7 +129,7 @@ def lookup_server_uri port = options[:port] return "tcp://#{host}:#{port}" if host_alive?(host) - sleep(1.0/100.0) + sleep(1.0 / 100.0) end raise "Host not found for service #{service}" From 9e632efce7222e5d8349a80a0b26cffe8bc52711 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:18:57 -0700 Subject: [PATCH 106/298] Style/SpaceAroundEqualsInParameterDefault --- .rubocop_todo.yml | 6 ------ lib/protobuf/logging.rb | 2 +- lib/protobuf/rpc/buffer.rb | 4 ++-- lib/protobuf/rpc/env.rb | 2 +- lib/protobuf/rpc/error.rb | 2 +- lib/protobuf/rpc/error/client_error.rb | 8 ++++---- lib/protobuf/rpc/error/server_error.rb | 12 ++++++------ 7 files changed, 15 insertions(+), 21 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 5593d1b3..ae4c812b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -239,12 +239,6 @@ Style/SpaceAfterComma: Style/SpaceAfterNot: Enabled: false -# Offense count: 17 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SpaceAroundEqualsInParameterDefault: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index bdaea254..904d77d5 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -2,7 +2,7 @@ module Protobuf module Logging - def self.initialize_logger(log_target=$stdout, log_level=::Logger::INFO) + def self.initialize_logger(log_target = $stdout, log_level = ::Logger::INFO) @counter ||= 0 @counter = @counter + 1 @logger = Logger.new(log_target) diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index bec96248..97587a00 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -9,7 +9,7 @@ class Buffer # constantize this so we don't re-initialize the regex every time we need it SIZE_REGEX = /^\d+-/ - def initialize(mode=:read) + def initialize(mode = :read) @flush = false @data = "" @size = 0 @@ -24,7 +24,7 @@ def mode=(mode) end end - def write(force_mode=true) + def write(force_mode = true) if force_mode && reading? self.mode = :write elsif !force_mode && reading? diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index 2f648e74..c719cadf 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -48,7 +48,7 @@ def #{name}? :service_name, :worker_id - def initialize(options={}) + def initialize(options = {}) merge!(options) self['worker_id'] = ::Thread.current.object_id.to_s(16) diff --git a/lib/protobuf/rpc/error.rb b/lib/protobuf/rpc/error.rb index a834a9bc..9a3f8569 100644 --- a/lib/protobuf/rpc/error.rb +++ b/lib/protobuf/rpc/error.rb @@ -8,7 +8,7 @@ module Rpc class PbError < StandardError attr_reader :error_type - def initialize(message='An unknown RpcError occurred', error_type='RPC_ERROR') + def initialize(message = 'An unknown RpcError occurred', error_type = 'RPC_ERROR') @error_type = error_type.is_a?(String) ? Socketrpc::ErrorReason.const_get(error_type) : error_type super message end diff --git a/lib/protobuf/rpc/error/client_error.rb b/lib/protobuf/rpc/error/client_error.rb index 19d161af..7efe27f5 100644 --- a/lib/protobuf/rpc/error/client_error.rb +++ b/lib/protobuf/rpc/error/client_error.rb @@ -4,25 +4,25 @@ module Protobuf module Rpc class InvalidRequestProto < PbError - def initialize(message='Invalid request type given') + def initialize(message = 'Invalid request type given') super message, 'INVALID_REQUEST_PROTO' end end class BadResponseProto < PbError - def initialize(message='Bad response type from server') + def initialize(message = 'Bad response type from server') super message, 'BAD_RESPONSE_PROTO' end end class UnkownHost < PbError - def initialize(message='Unknown host or port') + def initialize(message = 'Unknown host or port') super message, 'UNKNOWN_HOST' end end class IOError < PbError - def initialize(message='IO Error occurred') + def initialize(message = 'IO Error occurred') super message, 'IO_ERROR' end end diff --git a/lib/protobuf/rpc/error/server_error.rb b/lib/protobuf/rpc/error/server_error.rb index a37f0a37..7c516221 100644 --- a/lib/protobuf/rpc/error/server_error.rb +++ b/lib/protobuf/rpc/error/server_error.rb @@ -4,37 +4,37 @@ module Protobuf module Rpc class BadRequestData < PbError - def initialize message='Unable to parse request' + def initialize message = 'Unable to parse request' super message, 'BAD_REQUEST_DATA' end end class BadRequestProto < PbError - def initialize message='Request is of wrong type' + def initialize message = 'Request is of wrong type' super message, 'BAD_REQUEST_PROTO' end end class ServiceNotFound < PbError - def initialize message='Service class not found' + def initialize message = 'Service class not found' super message, 'SERVICE_NOT_FOUND' end end class MethodNotFound < PbError - def initialize message='Service method not found' + def initialize message = 'Service method not found' super message, 'METHOD_NOT_FOUND' end end class RpcError < PbError - def initialize message='RPC exception occurred' + def initialize message = 'RPC exception occurred' super message, 'RPC_ERROR' end end class RpcFailed < PbError - def initialize message='RPC failed' + def initialize message = 'RPC failed' super message, 'RPC_FAILED' end end From bcbe2df116c0849be452812c5b1260998ef6fbc3 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:19:45 -0700 Subject: [PATCH 107/298] Style/RedundantException --- .rubocop_todo.yml | 4 ---- spec/lib/protobuf/rpc/service_filters_spec.rb | 2 +- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ae4c812b..295ffad9 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -183,10 +183,6 @@ Style/Proc: Style/RaiseArgs: Enabled: false -# Offense count: 1 -Style/RedundantException: - Enabled: false - # Offense count: 20 # Cop supports --auto-correct. # Configuration parameters: AllowMultipleReturnValues. diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 538dfcc1..93781f2f 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -400,7 +400,7 @@ def filter_with_error3 def filter_with_runtime_error @called << :filter_with_runtime_error - raise RuntimeError, 'Filter with runtime error failed' + raise 'Filter with runtime error failed' end def custom_error_occurred(ex) From 2bb5f1f7450cd33d108799284635b37a023c8f94 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:21:53 -0700 Subject: [PATCH 108/298] Style/EmptyLineBetweenDefs --- .rubocop.yml | 3 +++ .rubocop_todo.yml | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ad64da6e..796150c8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,9 @@ Lint/Loop: Style/CaseIndentation: IndentWhenRelativeTo: end +Style/EmptyLineBetweenDefs: + AllowAdjacentOneLineDefs: true + Style/IndentHash: EnforcedStyle: consistent diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 295ffad9..ccff0678 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -70,12 +70,6 @@ Style/DoubleNegation: Style/EachWithObject: Enabled: false -# Offense count: 4 -# Cop supports --auto-correct. -# Configuration parameters: AllowAdjacentOneLineDefs. -Style/EmptyLineBetweenDefs: - Enabled: false - # Offense count: 35 # Cop supports --auto-correct. Style/EmptyLines: From 4b1ec197c603dc4235eb88c5189a29b1f73e2570 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 11:25:31 -0700 Subject: [PATCH 109/298] Style/ClassAndModuleChildren --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 5 ----- spec/lib/protobuf/rpc/service_spec.rb | 6 +++--- spec/spec_helper.rb | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 796150c8..689fbd6b 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,10 @@ Lint/Loop: Style/CaseIndentation: IndentWhenRelativeTo: end +Style/ClassAndModuleChildren: + Exclude: + - '**/*.pb.rb' + Style/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ccff0678..36dae6ab 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 4 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/ClassAndModuleChildren: - Enabled: false - # Offense count: 9 # Cop supports --auto-correct. # Configuration parameters: PreferredMethods. diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 9260e567..2d01202e 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -100,8 +100,8 @@ context 'instance methods' do context 'when invoking a service call' do - before(:all) do - class ::NewTestService < Protobuf::Rpc::Service + before do + stub_const('NewTestService', Class.new(Protobuf::Rpc::Service) do rpc :find_with_implied_response, Test::ResourceFindRequest, Test::Resource def find_with_implied_response response.name = 'Implicit response' @@ -118,7 +118,7 @@ def find_with_rpc_failed rpc_failed('This is a failed endpoint') response.name = 'Name will still be set' end - end + end) end let(:request) { Test::ResourceFindRequest.new(:name => 'resource') } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 831fd671..216c9415 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,7 +29,7 @@ support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) Dir[support_proto_glob].each { |proto_file| require proto_file } -class ::Protobuf::Rpc::Client +::Protobuf::Rpc::Client.class_eval do def ==(other) connector.options == other.options && \ success_cb == other.success_cb && \ From 6a85590ecb49284f1e24cc9ec4919b07353981d8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:37:13 -0700 Subject: [PATCH 110/298] Style/CollectionMethods --- .rubocop_todo.yml | 6 ------ lib/protobuf/cli.rb | 2 +- lib/protobuf/enum.rb | 2 +- lib/protobuf/generators/file_generator.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- spec/lib/protobuf/rpc/service_directory_spec.rb | 4 ++-- 8 files changed, 9 insertions(+), 15 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 36dae6ab..b56926e7 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,12 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 9 -# Cop supports --auto-correct. -# Configuration parameters: PreferredMethods. -Style/CollectionMethods: - Enabled: false - # Offense count: 5 # Configuration parameters: Keywords. Style/CommentAnnotation: diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 6e543c7a..3bacac65 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -180,7 +180,7 @@ def require_application(app_file) def runner_options # Symbolize keys - opt = options.inject({}) { |h, (k, v)| h[k.to_sym] = v; h } + opt = options.reduce({}) { |h, (k, v)| h[k.to_sym] = v; h } opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index d2d8646a..4e234ce9 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -226,7 +226,7 @@ def self.values self.warn_deprecated(:values, :enums) @values ||= begin - self.enums.inject({}) do |hash, enum| + self.enums.reduce({}) do |hash, enum| hash[enum.name] = enum hash end diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 5f62f7d1..77580bfd 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -120,7 +120,7 @@ def print_import_requires def print_package(&block) final = lambda { block.call } namespaces = descriptor.package.split('.') - namespaces.reverse.inject(final) do |previous, namespace| + namespaces.reverse.reduce(final) do |previous, namespace| lambda { print_module(namespace, &previous) } end.call end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 4b33b3ed..552610d2 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -8,7 +8,7 @@ module Common attr_reader :error def any_callbacks? - return [@complete_cb, @failure_cb, @success_cb].inject(false) do |reduction, cb| + return [@complete_cb, @failure_cb, @success_cb].reduce(false) do |reduction, cb| reduction || !cb.nil? end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 4a991ab0..bdaaee96 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -38,7 +38,7 @@ def log_signature end def resolve_ip(hostname) - ::Resolv.getaddresses(hostname).detect do |address| + ::Resolv.getaddresses(hostname).find do |address| address =~ ADDRESS_MATCH end end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index b67a7d45..27484fda 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -210,7 +210,7 @@ def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = # def run_around_filters(rpc_method) final = lambda { __send__(rpc_method) } - filters[:around].reverse.inject(final) do |previous, filter| + filters[:around].reverse.reduce(final) do |previous, filter| if invoke_filter?(rpc_method, filter) lambda { call_or_send(filter[:callable], &previous) } else @@ -241,7 +241,7 @@ def run_rescue_filters yield rescue *rescue_filters.keys => ex callable = rescue_filters.fetch(ex.class) do - mapped_klass = rescue_filters.keys.detect { |child_klass| ex.class < child_klass } + mapped_klass = rescue_filters.keys.find { |child_klass| ex.class < child_klass } rescue_filters[mapped_klass] end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 4798e6e5..3fcfbcc2 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -260,13 +260,13 @@ def send_beacon(type, server) if ENV.key?("BENCH") context "performance" do let(:servers) do - 100.times.collect do |x| + 100.times.map do |x| ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => "performance_server#{x + 1}", :address => '127.0.0.1', :port => (5555 + x).to_s, :ttl => rand(1..5), - :services => 10.times.collect { |y| "PerformanceService#{y}" } + :services => 10.times.map { |y| "PerformanceService#{y}" } ) end end From 51eac3a11486e04958f7e8fc2ca0eeefdeb20258 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:38:21 -0700 Subject: [PATCH 111/298] Style/CommentAnnotation --- .rubocop_todo.yml | 5 ----- lib/protobuf/cli.rb | 2 +- lib/protobuf/field/base_field.rb | 4 ++-- lib/protobuf/rpc/service_filters.rb | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index b56926e7..d9e44b94 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Configuration parameters: Keywords. -Style/CommentAnnotation: - Enabled: false - # Offense count: 5 # Cop supports --auto-correct. Style/DeprecatedHashMethods: diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3bacac65..a4f55a01 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -126,7 +126,7 @@ def configure_runner_mode end # Configure signal traps. - # TODO add signal handling for hot-reloading the application. + # TODO: add signal handling for hot-reloading the application. def configure_traps debug_say('Configuring traps') diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 9d6efe75..4c69025e 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -119,7 +119,7 @@ def required? rule == :required end - # FIXME need to cleanup (rename) this warthog of a method. + # FIXME: need to cleanup (rename) this warthog of a method. def set(message_instance, bytes) if packed? array = message_instance.__send__(getter) @@ -148,7 +148,7 @@ def setter @setter ||= "#{name}=" end - # FIXME add packed, deprecated, extension options to to_s output + # FIXME: add packed, deprecated, extension options to to_s output def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 27484fda..ed9bcfa2 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -66,8 +66,8 @@ def remember_filter(type, filter) end # Takes a list of actually (or potentially) callable objects. - # TODO add support for if/unless - # TODO add support for only/except sub-filters + # TODO: add support for if/unless + # TODO: add support for only/except sub-filters # def set_filters(type, *args) options = args.last.is_a?(Hash) ? args.pop : {} From d6b33d7e6888c36c9932fb6507bcc99cb340523c Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:39:00 -0700 Subject: [PATCH 112/298] Style/DeprecatedHashMethods --- .rubocop_todo.yml | 5 ----- lib/protobuf/message.rb | 2 +- lib/protobuf/rpc/connectors/base.rb | 4 ++-- lib/protobuf/rpc/connectors/zmq.rb | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d9e44b94..36760a53 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -37,11 +37,6 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 5 -# Cop supports --auto-correct. -Style/DeprecatedHashMethods: - Enabled: false - # Offense count: 191 Style/Documentation: Enabled: false diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index da3dfbea..18d314f9 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -82,7 +82,7 @@ def each_field_for_serialization end def has_field?(name) - @values.has_key?(name) + @values.key?(name) end def inspect diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index c2a6b9d6..81326cd1 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -33,7 +33,7 @@ def initialize(options) end def first_alive_load_balance? - ENV.has_key?("PB_FIRST_ALIVE_LOAD_BALANCE") || + ENV.key?("PB_FIRST_ALIVE_LOAD_BALANCE") || options[:first_alive_load_balance] end @@ -46,7 +46,7 @@ def ping_port end def ping_port_enabled? - ENV.has_key?("PB_RPC_PING_PORT") + ENV.key?("PB_RPC_PING_PORT") end end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 520fc034..a6310a02 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -190,7 +190,7 @@ def rcv_timeout case when options[:timeout] then options[:timeout] - when ENV.has_key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then + when ENV.key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i else 300_000 # 300 seconds @@ -203,7 +203,7 @@ def snd_timeout case when options[:timeout] then options[:timeout] - when ENV.has_key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then + when ENV.key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i else 300_000 # 300 seconds From 855467bf75d7c9b59b8656bda957ef33c33da37f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:46:15 -0700 Subject: [PATCH 113/298] Style/EachWithObject --- .rubocop_todo.yml | 4 ---- lib/protobuf/cli.rb | 5 +++-- lib/protobuf/enum.rb | 3 +-- 3 files changed, 4 insertions(+), 8 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 36760a53..9c099391 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -45,10 +45,6 @@ Style/Documentation: Style/DoubleNegation: Enabled: false -# Offense count: 2 -Style/EachWithObject: - Enabled: false - # Offense count: 35 # Cop supports --auto-correct. Style/EmptyLines: diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index a4f55a01..90990e2c 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/hash/keys' + require 'thor' require 'protobuf/version' require 'protobuf/logging' @@ -179,8 +181,7 @@ def require_application(app_file) end def runner_options - # Symbolize keys - opt = options.reduce({}) { |h, (k, v)| h[k.to_sym] = v; h } + opt = options.symbolize_keys opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 4e234ce9..cb6bc31f 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -226,9 +226,8 @@ def self.values self.warn_deprecated(:values, :enums) @values ||= begin - self.enums.reduce({}) do |hash, enum| + self.enums.each_with_object({}) do |enum, hash| hash[enum.name] = enum - hash end end end From d83fb0471ec9b7ff387bc7ff90ec91a5bcd32ee1 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:49:55 -0700 Subject: [PATCH 114/298] Style/EmptyLines --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 5 ----- lib/protobuf/enum.rb | 1 - lib/protobuf/field/bool_field.rb | 1 - lib/protobuf/rpc/service_filters.rb | 1 - spec/lib/protobuf/enum_spec.rb | 1 - spec/lib/protobuf/field/string_field_spec.rb | 1 - spec/lib/protobuf/field_spec.rb | 3 --- 8 files changed, 4 insertions(+), 13 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 689fbd6b..54aee5d2 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -13,6 +13,10 @@ Style/ClassAndModuleChildren: Style/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true +Style/EmptyLines: + Exclude: + - '**/*.pb.rb' + Style/IndentHash: EnforcedStyle: consistent diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9c099391..d4a6b8b8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -45,11 +45,6 @@ Style/Documentation: Style/DoubleNegation: Enabled: false -# Offense count: 35 -# Cop supports --auto-correct. -Style/EmptyLines: - Enabled: false - # Offense count: 10 # Cop supports --auto-correct. Style/EmptyLinesAroundAccessModifier: diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index cb6bc31f..e6bfd422 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -241,7 +241,6 @@ def self.values deprecate_class_method :get_name_by_tag, :name_for_tag deprecate_class_method :value_by_name, :enum_for_name - ## # Attributes # diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 6e789ed3..182d6295 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -12,7 +12,6 @@ def self.default false end - ## # Public Instance Methods # # diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index ed9bcfa2..f7de8ad9 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -219,7 +219,6 @@ def run_around_filters(rpc_method) end.call end - # Entry method to call each filter type in the appropriate order. This should # be used instead of the other run methods directly. # diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index f532627a..645bf424 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -69,7 +69,6 @@ end end - describe '.enums_for_tag' do it 'returns an array of Enums for the given tag, if any' do expect(EnumAliasTest.enums_for_tag(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index b25ccc95..f1ad1a7e 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -42,5 +42,4 @@ end end - end diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index 7b7537a6..4dafd9f5 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -148,7 +148,6 @@ end end - context 'when type is a string field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::StringField @@ -159,7 +158,6 @@ end end - context 'when type is a bytes field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::BytesField @@ -170,7 +168,6 @@ end end - context 'when type is a bool field class or symbol' do it 'returns that class' do expected_field = ::Protobuf::Field::BoolField From 90b393cd1f923095b84685437d18809650e700ab Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:51:07 -0700 Subject: [PATCH 115/298] Style/EmptyLinesAroundAccessModifier --- .rubocop_todo.yml | 5 ----- lib/protobuf/message.rb | 1 + spec/lib/protobuf/rpc/service_filters_spec.rb | 9 +++++++++ 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index d4a6b8b8..c5affee2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -45,11 +45,6 @@ Style/Documentation: Style/DoubleNegation: Enabled: false -# Offense count: 10 -# Cop supports --auto-correct. -Style/EmptyLinesAroundAccessModifier: - Enabled: false - # Offense count: 146 # Cop supports --auto-correct. Style/EmptyLinesAroundBody: diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 18d314f9..8320861d 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -161,6 +161,7 @@ def []=(name, value) ## # Private Instance Methods # + private def copy_to(object, method) diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 93781f2f..0040e356 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -38,6 +38,7 @@ def self.clear_filters! before(:all) do class FilterTest private + def verify_before @called << :verify_before @before_filter_calls += 1 @@ -68,6 +69,7 @@ def foo before(:all) do class FilterTest private + def endpoint_with_verify @called << :endpoint_with_verify end @@ -98,6 +100,7 @@ def endpoint_with_verify before(:all) do class FilterTest private + def endpoint_without_verify @called << :endpoint_without_verify end @@ -128,6 +131,7 @@ def endpoint_without_verify before(:all) do class FilterTest private + def check_true; return true; end def check_false; return false; end def verify_before; @called << :verify_before; end @@ -187,6 +191,7 @@ def verify_before; @called << :verify_before; end before(:all) do class FilterTest private + def check_true; return true; end def check_false; return false; end def verify_before; @called << :verify_before; end @@ -246,6 +251,7 @@ def verify_before; @called << :verify_before; end before(:all) do class FilterTest private + def short_circuit_filter @called << :short_circuit_filter return false @@ -272,6 +278,7 @@ def short_circuit_filter before(:all) do class FilterTest private + def verify_after @called << :verify_after @after_filter_calls += 1 @@ -305,6 +312,7 @@ def foo before(:all) do class FilterTest private + def outer_around @called << :outer_around_top yield @@ -346,6 +354,7 @@ def inner_around before do class FilterTest private + def inner_around @called << :inner_around end From ff67c4eff1272545c2abda2d26923de941d9aae2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:53:14 -0700 Subject: [PATCH 116/298] Style/EmptyLiteral --- .rubocop_todo.yml | 5 ----- lib/protobuf/message.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c5affee2..31e62fdc 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,11 +50,6 @@ Style/DoubleNegation: Style/EmptyLinesAroundBody: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/EmptyLiteral: - Enabled: false - # Offense count: 2 # Configuration parameters: Exclude. Style/FileName: diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 8320861d..83345493 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -100,7 +100,7 @@ def respond_to_has_and_present?(key) # Return a hash-representation of the given fields for this message type. def to_hash - result = Hash.new + result = {} @values.keys.each do |field_name| value = __send__(field_name) From c990afce1a7467d9ae8884da19d2808fea229e05 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:53:58 -0700 Subject: [PATCH 117/298] Style/IndentationConsistency --- .rubocop_todo.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 31e62fdc..afac0e85 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -71,11 +71,6 @@ Style/HashSyntax: Style/IfUnlessModifier: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -Style/IndentationConsistency: - Enabled: false - # Offense count: 1 # Cop supports --auto-correct. Style/IndentationWidth: From d5aa15fa2d86df13501f66e0740590e714a8ddf7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:54:40 -0700 Subject: [PATCH 118/298] Style/IndentationWidth --- .rubocop_todo.yml | 5 ----- lib/protobuf/field/fixed32_field.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index afac0e85..0c685eb8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -71,11 +71,6 @@ Style/HashSyntax: Style/IfUnlessModifier: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/IndentationWidth: - Enabled: false - # Offense count: 14 Style/Lambda: Enabled: false diff --git a/lib/protobuf/field/fixed32_field.rb b/lib/protobuf/field/fixed32_field.rb index 4b07f3e4..74d0f384 100644 --- a/lib/protobuf/field/fixed32_field.rb +++ b/lib/protobuf/field/fixed32_field.rb @@ -17,7 +17,7 @@ def encode(value) end def wire_type - ::Protobuf::WireType::FIXED32 + ::Protobuf::WireType::FIXED32 end end From 2dacbe128984e81262b60c426e97acb43503003a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:55:24 -0700 Subject: [PATCH 119/298] Style/LeadingCommentSpace --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/servers/socket/server.rb | 2 +- 2 files changed, 1 insertion(+), 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 0c685eb8..cd602d92 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -75,11 +75,6 @@ Style/IfUnlessModifier: Style/Lambda: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/LeadingCommentSpace: - Enabled: false - # Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 01fa55d6..4353c0a5 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -96,7 +96,7 @@ def run raise rescue # Closing the server causes the loop to raise an exception here - raise #if running? + raise # if running? end def running? From 712b93bc4e2d1eed19571cdc7acce18321f02e37 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:55:53 -0700 Subject: [PATCH 120/298] Style/MethodDefParentheses --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/error/server_error.rb | 12 ++++++------ 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cd602d92..49935059 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -75,12 +75,6 @@ Style/IfUnlessModifier: Style/Lambda: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MethodDefParentheses: - Enabled: false - # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: diff --git a/lib/protobuf/rpc/error/server_error.rb b/lib/protobuf/rpc/error/server_error.rb index 7c516221..990c858b 100644 --- a/lib/protobuf/rpc/error/server_error.rb +++ b/lib/protobuf/rpc/error/server_error.rb @@ -4,37 +4,37 @@ module Protobuf module Rpc class BadRequestData < PbError - def initialize message = 'Unable to parse request' + def initialize(message = 'Unable to parse request') super message, 'BAD_REQUEST_DATA' end end class BadRequestProto < PbError - def initialize message = 'Request is of wrong type' + def initialize(message = 'Request is of wrong type') super message, 'BAD_REQUEST_PROTO' end end class ServiceNotFound < PbError - def initialize message = 'Service class not found' + def initialize(message = 'Service class not found') super message, 'SERVICE_NOT_FOUND' end end class MethodNotFound < PbError - def initialize message = 'Service method not found' + def initialize(message = 'Service method not found') super message, 'METHOD_NOT_FOUND' end end class RpcError < PbError - def initialize message = 'RPC exception occurred' + def initialize(message = 'RPC exception occurred') super message, 'RPC_ERROR' end end class RpcFailed < PbError - def initialize message = 'RPC failed' + def initialize(message = 'RPC failed') super message, 'RPC_FAILED' end end From 4416cd094d792c2f0cf5212bdb8b55315f71d4dd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 12:56:43 -0700 Subject: [PATCH 121/298] Style/NonNilCheck --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/client.rb | 6 +++--- 2 files changed, 3 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 49935059..81320ec4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -80,12 +80,6 @@ Style/Lambda: Style/Next: Enabled: false -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: IncludeSemanticChanges. -Style/NonNilCheck: - Enabled: false - # Offense count: 46 # Cop supports --auto-correct. Style/NumericLiterals: diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index d8ebe349..e810530a 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -46,7 +46,7 @@ def on_complete(&complete_cb) end def on_complete=(callable) - if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 + if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 raise "callable must take a single argument and respond to :call" end @@ -65,7 +65,7 @@ def on_failure(&failure_cb) end def on_failure=(callable) - if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 + if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 raise "Callable must take a single argument and respond to :call" end @@ -84,7 +84,7 @@ def on_success(&success_cb) end def on_success=(callable) - if callable != nil && !callable.respond_to?(:call) && callable.arity != 1 + if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 raise "Callable must take a single argument and respond to :call" end From 8ba592177161f9968a6cfd815cf86733e23a120d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:04:01 -0700 Subject: [PATCH 122/298] Style/OpMethod --- .rubocop_todo.yml | 4 ---- lib/protobuf/message.rb | 6 +++--- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 81320ec4..1b8c0ce0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -85,10 +85,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 1 -Style/OpMethod: - Enabled: false - # Offense count: 13 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 83345493..62741a39 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -119,10 +119,10 @@ def to_proto self end - def ==(obj) - return false unless obj.is_a?(self.class) + def ==(other) + return false unless other.is_a?(self.class) each_field do |field, value| - return false unless value == obj.__send__(field.name) + return false unless value == other.__send__(field.name) end true end From b5f40594a595726a93ff087f950563d2652054df Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:06:21 -0700 Subject: [PATCH 123/298] Style/PercentLiteralDelimiters --- .rubocop_todo.yml | 6 ------ Rakefile | 4 ++-- lib/protobuf/deprecator.rb | 4 ++-- lib/protobuf/generators/field_generator.rb | 2 +- lib/protobuf/message/fields.rb | 4 ++-- spec/lib/protobuf/generators/field_generator_spec.rb | 2 +- spec/lib/protobuf/rpc/service_directory_spec.rb | 8 ++++---- 7 files changed, 12 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1b8c0ce0..7c8b5c8d 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -85,12 +85,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 13 -# Cop supports --auto-correct. -# Configuration parameters: PreferredDelimiters. -Style/PercentLiteralDelimiters: - Enabled: false - # Offense count: 7 # Configuration parameters: NamePrefix, NamePrefixBlacklist. Style/PredicateName: diff --git a/Rakefile b/Rakefile index 7c8ce81a..57f3e75c 100644 --- a/Rakefile +++ b/Rakefile @@ -22,7 +22,7 @@ namespace :compile do task :spec do proto_path = ::File.expand_path('../spec/support/', __FILE__) proto_files = Dir[File.join(proto_path, '**', '*.proto')] - cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')}} + cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{proto_path} -I #{proto_path} #{proto_files.join(' ')}) puts cmd system(cmd) @@ -35,7 +35,7 @@ namespace :compile do output_dir = ::File.expand_path('../tmp/rpc', __FILE__) ::FileUtils.mkdir_p(output_dir) - cmd = %{protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')}} + cmd = %(protoc --plugin=./bin/protoc-gen-ruby --ruby_out=#{output_dir} -I #{proto_path} #{proto_files.join(' ')}) puts cmd system(cmd) diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index b19773c0..f7d5df84 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -2,8 +2,8 @@ module Protobuf module Deprecator def warn_deprecated(old_method, new_method) - $stderr.puts %{[DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. - Please use #{self.name}.#{new_method} instead.\n} + $stderr.puts %([DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. + Please use #{self.name}.#{new_method} instead.\n) end # Given deprecations should be a hash whose keys are the new methods diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 7797afbf..91684914 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -119,7 +119,7 @@ def float_double_default_value end def string_default_value - %{"#{verbatim_default_value.gsub(/'/, '\\\\\'')}"} + %("#{verbatim_default_value.gsub(/'/, '\\\\\'')}") end def verbatim_default_value diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index a89596cc..7e92f606 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -106,13 +106,13 @@ def define_field(rule, type_class, field_name, tag, options) def raise_if_tag_collision(tag, field_name) if get_field(tag, true) - raise TagCollisionError, %!Field number #{tag} has already been used in "#{name}" by field "#{field_name}".! + raise TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) end end def raise_if_name_collision(field_name) if get_field(field_name, true) - raise DuplicateFieldNameError, %!Field name #{field_name} has already been used in "#{name}".! + raise DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) end end diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index c329ea04..0e72dde5 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -57,7 +57,7 @@ let(:type_enum) { :TYPE_STRING } let(:default_value) { "a default \"string\"" } - specify { expect(subject).to eq %{optional :string, :foo_bar, 3, :default => "a default \"string\""\n} } + specify { expect(subject).to eq "optional :string, :foo_bar, 3, :default => \"a default \"string\"\"\n" } end context 'when float or double field type' do diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 3fcfbcc2..32cb3b4f 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -11,7 +11,7 @@ :address => '127.0.0.1', :port => '1111', :ttl => 10, - :services => %w[EchoService] + :services => %w(EchoService) ) end @@ -21,7 +21,7 @@ :address => '127.0.0.1', :port => "1112", :ttl => 10, - :services => %w[HelloService] + :services => %w(HelloService) ) end @@ -31,7 +31,7 @@ :address => '127.0.0.1', :port => '1113', :ttl => 1, - :services => %w[HelloService] + :services => %w(HelloService) ) end @@ -41,7 +41,7 @@ :address => '127.0.0.1', :port => '1114', :ttl => 10, - :services => %w[HelloService EchoService] + :services => %w(HelloService EchoService) ) end From 3bd24d5b6436ab8969d78fc25fb5900a558745f5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:07:06 -0700 Subject: [PATCH 124/298] Style/Proc --- .rubocop_todo.yml | 5 ----- spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb | 2 +- spec/lib/protobuf/rpc/middleware/logger_spec.rb | 2 +- spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb | 2 +- spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb | 2 +- 5 files changed, 4 insertions(+), 9 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 7c8b5c8d..48fdf8cf 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -90,11 +90,6 @@ Style/NumericLiterals: Style/PredicateName: Enabled: false -# Offense count: 4 -# Cop supports --auto-correct. -Style/Proc: - Enabled: false - # Offense count: 8 # Configuration parameters: EnforcedStyle, SupportedStyles. Style/RaiseArgs: diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index e7d3a79f..8ebe422b 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::ExceptionHandler do - let(:app) { Proc.new { |env| env } } + let(:app) { proc { |env| env } } let(:env) { Protobuf::Rpc::Env.new } subject { described_class.new(app) } diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index e3621a76..db42a8f0 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::Logger do - let(:app) { Proc.new { |inner_env| inner_env } } + let(:app) { proc { |inner_env| inner_env } } let(:env) do Protobuf::Rpc::Env.new( 'client_host' => 'client_host.test.co', diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index f7f4a485..1fd5fb4e 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::RequestDecoder do - let(:app) { Proc.new { |env| env } } + let(:app) { proc { |env| env } } let(:client_host) { 'client_host.test.co' } let(:env) do Protobuf::Rpc::Env.new( diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index f9d47ebe..83694083 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' describe Protobuf::Rpc::Middleware::ResponseEncoder do - let(:app) { Proc.new { |env| env.response = response; env } } + let(:app) { proc { |env| env.response = response; env } } let(:env) do Protobuf::Rpc::Env.new( 'response_type' => Test::Resource, From c7a06bc8e59ce64dc7087690e0584520b73b7c33 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:07:46 -0700 Subject: [PATCH 125/298] Style/RedundantReturn --- .rubocop_todo.yml | 6 ------ lib/protobuf/code_generator.rb | 2 +- lib/protobuf/decoder.rb | 2 +- lib/protobuf/generators/enum_generator.rb | 2 +- lib/protobuf/generators/service_generator.rb | 2 +- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/message.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 14 +++++++------- spec/lib/protobuf/rpc/service_filters_spec.rb | 10 +++++----- spec/support/server.rb | 2 +- 11 files changed, 20 insertions(+), 26 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 48fdf8cf..6b2367a1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -95,12 +95,6 @@ Style/PredicateName: Style/RaiseArgs: Enabled: false -# Offense count: 20 -# Cop supports --auto-correct. -# Configuration parameters: AllowMultipleReturnValues. -Style/RedundantReturn: - Enabled: false - # Offense count: 26 # Cop supports --auto-correct. Style/RedundantSelf: diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index e44fe2ac..7aa96272 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -33,7 +33,7 @@ def response_bytes generate_file(file_descriptor) end - return ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => @generated_files) + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => @generated_files) end end diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 67e5f8ec..ddcc4ac3 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -31,7 +31,7 @@ def self.read_field(stream) raise InvalidWireType, wire_type end - return tag, bytes + [tag, bytes] end # Read 32-bit string value from +stream+. diff --git a/lib/protobuf/generators/enum_generator.rb b/lib/protobuf/generators/enum_generator.rb index 57b7416b..c45c6985 100644 --- a/lib/protobuf/generators/enum_generator.rb +++ b/lib/protobuf/generators/enum_generator.rb @@ -33,7 +33,7 @@ def compile def build_value(enum_value_descriptor) name = enum_value_descriptor.name number = enum_value_descriptor.number - return "define :#{name}, #{number}" + "define :#{name}, #{number}" end end diff --git a/lib/protobuf/generators/service_generator.rb b/lib/protobuf/generators/service_generator.rb index bc2f5d8d..801dd0bb 100644 --- a/lib/protobuf/generators/service_generator.rb +++ b/lib/protobuf/generators/service_generator.rb @@ -18,7 +18,7 @@ def build_method(method_descriptor) name = method_descriptor.name request_klass = modulize(method_descriptor.input_type) response_klass = modulize(method_descriptor.output_type) - return "rpc :#{name.underscore}, #{request_klass}, #{response_klass}" + "rpc :#{name.underscore}, #{request_klass}, #{response_klass}" end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index bc035145..60c2bd95 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -32,7 +32,7 @@ def self.trigger(event_name, *args) end def self.normalized_event_name(event_name) - return "#{event_name}".downcase + "#{event_name}".downcase end class << self diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 62741a39..622e2942 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -108,7 +108,7 @@ def to_hash result.merge!(field_name => hashed_value) end - return result + result end def to_json(options = {}) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 552610d2..5e69336a 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -8,7 +8,7 @@ module Common attr_reader :error def any_callbacks? - return [@complete_cb, @failure_cb, @success_cb].reduce(false) do |reduction, cb| + [@complete_cb, @failure_cb, @success_cb].reduce(false) do |reduction, cb| reduction || !cb.nil? end end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index f7de8ad9..45dc6923 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -94,7 +94,7 @@ def filters # if the filter should not be invoked, true if invocation should occur. # def invoke_filter?(rpc_method, filter) - return invoke_via_only?(rpc_method, filter) \ + invoke_via_only?(rpc_method, filter) \ && invoke_via_except?(rpc_method, filter) \ && invoke_via_if?(rpc_method, filter) \ && invoke_via_unless?(rpc_method, filter) @@ -109,7 +109,7 @@ def invoke_filter?(rpc_method, filter) # def invoke_via_except?(rpc_method, filter) except = [ filter.fetch(:except) { [] } ].flatten - return except.empty? || ! except.include?(rpc_method) + except.empty? || ! except.include?(rpc_method) end # Invoke the given :if callable (if any) and return its return value. @@ -128,7 +128,7 @@ def invoke_via_if?(_rpc_method, filter) call_or_send(if_check) end - return do_invoke + do_invoke end # If the target rpc endpoint method is listed in the :only option, @@ -139,7 +139,7 @@ def invoke_via_if?(_rpc_method, filter) # def invoke_via_only?(rpc_method, filter) only = [ filter.fetch(:only) { [] } ].flatten - return only.empty? || only.include?(rpc_method) + only.empty? || only.include?(rpc_method) end # Invoke the given :unless callable (if any) and return the opposite @@ -158,7 +158,7 @@ def invoke_via_unless?(_rpc_method, filter) call_or_send(unless_check) end - return ! skip_invoke + ! skip_invoke end def rescue_filters @@ -176,7 +176,7 @@ def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = end end - return true + true end # Reverse build a chain of around filters. To implement an around chain, @@ -262,7 +262,7 @@ def call_or_send(callable, *args, &block) raise "Object #{callable} is not callable" end - return return_value + return_value end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 0040e356..0542ef8c 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -132,8 +132,8 @@ def endpoint_without_verify class FilterTest private - def check_true; return true; end - def check_false; return false; end + def check_true; true; end + def check_false; false; end def verify_before; @called << :verify_before; end end end @@ -192,8 +192,8 @@ def verify_before; @called << :verify_before; end class FilterTest private - def check_true; return true; end - def check_false; return false; end + def check_true; true; end + def check_false; false; end def verify_before; @called << :verify_before; end end end @@ -254,7 +254,7 @@ class FilterTest def short_circuit_filter @called << :short_circuit_filter - return false + false end end end diff --git a/spec/support/server.rb b/spec/support/server.rb index d572b1db..dd0817a9 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -24,7 +24,7 @@ def post_init end new_server.sleep_interval = delay - return new_server + new_server end end From 8275f87f509126d4a82e62ca3ceebc824d2e6414 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:08:19 -0700 Subject: [PATCH 126/298] Style/RedundantSelf --- .rubocop_todo.yml | 5 ----- lib/protobuf/deprecator.rb | 4 ++-- lib/protobuf/enum.rb | 24 ++++++++++++------------ lib/protobuf/field/field_array.rb | 2 +- lib/protobuf/logging.rb | 2 +- lib/protobuf/message/serialization.rb | 4 ++-- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 6 +++--- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 6 +++--- 10 files changed, 26 insertions(+), 31 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6b2367a1..1ef443da 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -95,11 +95,6 @@ Style/PredicateName: Style/RaiseArgs: Enabled: false -# Offense count: 26 -# Cop supports --auto-correct. -Style/RedundantSelf: - Enabled: false - # Offense count: 2 Style/RescueModifier: Enabled: false diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index f7d5df84..856f8480 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -2,8 +2,8 @@ module Protobuf module Deprecator def warn_deprecated(old_method, new_method) - $stderr.puts %([DEPRECATED] #{self.name}.#{old_method} is deprecated and will disappear in a future version. - Please use #{self.name}.#{new_method} instead.\n) + $stderr.puts %([DEPRECATED] #{name}.#{old_method} is deprecated and will disappear in a future version. + Please use #{name}.#{new_method} instead.\n) end # Given deprecations should be a hash whose keys are the new methods diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index e6bfd422..f85665f8 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -32,7 +32,7 @@ class Enum < SimpleDelegator include ::Protobuf::Optionable def self.aliases_allowed? - self.get_option(:allow_alias) + get_option(:allow_alias) end # Public: Get all integer tags defined by this enum. @@ -51,7 +51,7 @@ def self.aliases_allowed? # Returns an array of unique integers. # def self.all_tags - @all_tags ||= self.enums.map(&:to_i).uniq + @all_tags ||= enums.map(&:to_i).uniq end # Internal: DSL method to create a new Enum. The given name will @@ -70,7 +70,7 @@ def self.all_tags # Returns nothing. # def self.define(name, tag) - enum = self.new(self, name, tag) + enum = new(self, name, tag) @enums ||= [] @enums << enum const_set(name, enum) @@ -101,7 +101,7 @@ class << self # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) - self.enums.select do |enum| + enums.select do |enum| enum.to_i == tag.to_i end end @@ -125,7 +125,7 @@ def self.enums_for_tag(tag) # Returns the Enum object with the given name or nil. # def self.enum_for_name(name) - self.const_get(name) + const_get(name) rescue ::NameError nil end @@ -138,7 +138,7 @@ def self.enum_for_name(name) # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) - self.enums_for_tag(tag).first + enums_for_tag(tag).first end # Public: Get an Enum by a variety of type-checking mechanisms. @@ -206,7 +206,7 @@ def self.fetch(candidate) # the first defined name will be returned. # def self.name_for_tag(tag) - self.enum_for_tag(tag).try(:name) + enum_for_tag(tag).try(:name) end # Public: Check if the given tag is defined by this Enum. @@ -216,17 +216,17 @@ def self.name_for_tag(tag) # Returns a boolean. # def self.valid_tag?(tag) - tag.respond_to?(:to_i) && self.all_tags.include?(tag.to_i) + tag.respond_to?(:to_i) && all_tags.include?(tag.to_i) end # Public: [DEPRECATED] Return a hash of Enum objects keyed # by their :name. # def self.values - self.warn_deprecated(:values, :enums) + warn_deprecated(:values, :enums) @values ||= begin - self.enums.each_with_object({}) do |enum, hash| + enums.each_with_object({}) do |enum, hash| hash[enum.name] = enum end end @@ -279,11 +279,11 @@ def to_int def to_s(format = :tag) case format when :tag then - self.to_i.to_s + to_i.to_s when :name then name.to_s else - self.to_i.to_s + to_i.to_s end end diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index cf46323f..14eacd34 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -41,7 +41,7 @@ def replace(val) # Return a hash-representation of the given values for this field type. # The value in this case would be an array. def to_hash_value - self.map do |value| + map do |value| value.respond_to?(:to_hash_value) ? value.to_hash_value : value end end diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index 904d77d5..f75e79e5 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -29,7 +29,7 @@ def log_exception(ex) end def log_signature - @_log_signature ||= "[#{self.class == Class ? self.name : self.class.name}]" + @_log_signature ||= "[#{self.class == Class ? name : self.class.name}]" end def sign_message(message) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 05e3c1b8..22457b96 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -8,12 +8,12 @@ module Serialization module ClassMethods def decode(bytes) - self.new.decode(bytes) + new.decode(bytes) end # Create a new object with the given values and return the encoded bytes. def encode(fields = {}) - self.new(fields).encode + new(fields).encode end end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 5e69336a..0bcb310d 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -162,7 +162,7 @@ def validate_request_type! def verify_callbacks unless any_callbacks? logger.debug { sign_message("No callbacks set, using data_callback") } - @success_cb = @failure_cb = self.method(:data_callback) + @success_cb = @failure_cb = method(:data_callback) end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c548722c..57945758 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -79,7 +79,7 @@ def broadcast_beacons? def broadcast_flatline flatline = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE, - :server => self.to_proto + :server => to_proto ) @beacon_socket.send(flatline.encode, 0) @@ -90,7 +90,7 @@ def broadcast_heartbeat heartbeat = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT, - :server => self.to_proto + :server => to_proto ) @beacon_socket.send(heartbeat.encode, 0) @@ -124,7 +124,7 @@ def frontend_uri end def inproc? - !!self.options[:zmq_inproc] + !!options[:zmq_inproc] end def maintenance_timeout diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 54d6f8a6..dea0eda2 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -66,7 +66,7 @@ class << self # An array of defined service classes that contain implementation # code def self.implemented_services - classes = (self.subclasses || []).select do |subclass| + classes = (subclasses || []).select do |subclass| subclass.rpcs.any? do |(name, _)| subclass.method_defined? name end diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index d293f4a3..6aec7b4d 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -66,11 +66,11 @@ def self.port def self.start yield(self) if block_given? - self.instance.start + instance.start end def self.stop - self.instance.stop + instance.stop end # @@ -113,7 +113,7 @@ def start unless running? init_socket logger.info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } - @thread = Thread.new { self.send(:run) } + @thread = Thread.new { send(:run) } end self From 797e86328bc8d4c69126d5a8145d421f7cc405bb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:09:51 -0700 Subject: [PATCH 127/298] Style/SelfAssignment --- .rubocop_todo.yml | 4 ---- lib/protobuf/logging.rb | 2 -- 2 files changed, 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 1ef443da..ac728d5a 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,10 +99,6 @@ Style/RaiseArgs: Style/RescueModifier: Enabled: false -# Offense count: 1 -Style/SelfAssignment: - Enabled: false - # Offense count: 7 # Cop supports --auto-correct. # Configuration parameters: AllowAsExpressionSeparator. diff --git a/lib/protobuf/logging.rb b/lib/protobuf/logging.rb index f75e79e5..59fc9997 100644 --- a/lib/protobuf/logging.rb +++ b/lib/protobuf/logging.rb @@ -3,8 +3,6 @@ module Protobuf module Logging def self.initialize_logger(log_target = $stdout, log_level = ::Logger::INFO) - @counter ||= 0 - @counter = @counter + 1 @logger = Logger.new(log_target) @logger.level = log_level @logger From 2d7fa3b94f9d9eb329f1bb7f8ef7a4ad26f2c9f6 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:10:39 -0700 Subject: [PATCH 128/298] Style/SpaceAfterColon --- .rubocop_todo.yml | 5 ----- spec/encoding/all_types_spec.rb | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ac728d5a..71c909f1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -117,11 +117,6 @@ Style/SignalException: Style/SingleLineMethods: Enabled: false -# Offense count: 2 -# Cop supports --auto-correct. -Style/SpaceAfterColon: - Enabled: false - # Offense count: 9 # Cop supports --auto-correct. Style/SpaceAfterComma: diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index c202215a..411a7a55 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -57,8 +57,8 @@ ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ], repeated_string_piece: ["224", "324"], repeated_cord: ["225", "325"], - repeated_lazy_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb:227), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb:327)], + repeated_lazy_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 227), + ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 327)], default_int32: 401, default_int64: 402, default_uint32: 403, From 0cdef2fd4c9a0992da067e8babac5c8873323722 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:13:19 -0700 Subject: [PATCH 129/298] Style/Semicolon --- .rubocop.yml | 3 +++ .rubocop_todo.yml | 6 ------ 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 54aee5d2..77a6182c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -20,6 +20,9 @@ Style/EmptyLines: Style/IndentHash: EnforcedStyle: consistent +Style/Semicolon: + AllowAsExpressionSeparator: true + Style/TrailingBlankLines: Exclude: - '**/*.pb.rb' diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 71c909f1..428750a0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,12 +99,6 @@ Style/RaiseArgs: Style/RescueModifier: Enabled: false -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: AllowAsExpressionSeparator. -Style/Semicolon: - Enabled: false - # Offense count: 67 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. From 96e0298c9205e7a6b7458864e0e788276631b2be Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:14:06 -0700 Subject: [PATCH 130/298] Style/SingleLineMethods --- .rubocop_todo.yml | 6 ---- spec/lib/protobuf/rpc/service_filters_spec.rb | 28 +++++++++++++++---- 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 428750a0..ac9d7ada 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -105,12 +105,6 @@ Style/RescueModifier: Style/SignalException: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -# Configuration parameters: AllowIfMethodIsEmpty. -Style/SingleLineMethods: - Enabled: false - # Offense count: 9 # Cop supports --auto-correct. Style/SpaceAfterComma: diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 0542ef8c..27f5d356 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -132,9 +132,17 @@ def endpoint_without_verify class FilterTest private - def check_true; true; end - def check_false; false; end - def verify_before; @called << :verify_before; end + def check_true + true + end + + def check_false + false + end + + def verify_before + @called << :verify_before + end end end @@ -192,9 +200,17 @@ def verify_before; @called << :verify_before; end class FilterTest private - def check_true; true; end - def check_false; false; end - def verify_before; @called << :verify_before; end + def check_true + true + end + + def check_false + false + end + + def verify_before + @called << :verify_before + end end end From f85b7fb4b35b8828f23988449cd810ed92133877 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:15:17 -0700 Subject: [PATCH 131/298] Style/SpaceAfterComma --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/connectors/zmq.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- spec/lib/protobuf/generators/base_spec.rb | 4 ++-- 4 files changed, 5 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ac9d7ada..9a4095b2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -105,11 +105,6 @@ Style/RescueModifier: Style/SignalException: Enabled: false -# Offense count: 9 -# Cop supports --auto-correct. -Style/SpaceAfterComma: - Enabled: false - # Offense count: 6 # Cop supports --auto-correct. Style/SpaceAfterNot: diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index a6310a02..1eaf9037 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -159,7 +159,7 @@ def host_alive_check_interval def ping_port_open?(host) socket = TCPSocket.new(host, ping_port.to_i) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) - socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1,0].pack('ii')) + socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1, 0].pack('ii')) true rescue diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 45dc6923..c042b58f 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -24,7 +24,7 @@ module ClassMethods # whose values are Sets. # def filters - @filters ||= Hash.new { |h,k| h[k] = [] } + @filters ||= Hash.new { |h, k| h[k] = [] } end # Filters hash keyed based on filter type (e.g. :before, :after, :around), @@ -50,7 +50,7 @@ def define_filter(type, filter, options = {}) end def defined_filters - @defined_filters ||= Hash.new { |h,k| h[k] = Set.new } + @defined_filters ||= Hash.new { |h, k| h[k] = Set.new } end # Check to see if the filter has been defined. diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 6feab2b1..0162b1b2 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -68,14 +68,14 @@ def compile context 'when tags are duplicated' do it 'fails with a GeneratorFatalError' do expect(::Protobuf::CodeGenerator).to receive(:fatal).with(/FooBar object has duplicate tags\. Expected 3 tags, but got 4/) - described_class.validate_tags("FooBar", [1,2,2,3]) + described_class.validate_tags("FooBar", [1, 2, 2, 3]) end end context 'when tags are missing in the range' do it 'prints a warning' do expect(::Protobuf::CodeGenerator).to receive(:warn).with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) - described_class.validate_tags("FooBar", [1,2,4,5]) + described_class.validate_tags("FooBar", [1, 2, 4, 5]) end end end From b8fc83bede97a3b7b78d59551ea46ff9677b8181 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:15:43 -0700 Subject: [PATCH 132/298] Style/SpaceAfterNot --- .rubocop_todo.yml | 5 ----- lib/protobuf/field/enum_field.rb | 2 +- lib/protobuf/generators/message_generator.rb | 2 +- lib/protobuf/message/fields.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- lib/protobuf/rpc/stat.rb | 2 +- 6 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9a4095b2..e15afba1 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -105,11 +105,6 @@ Style/RescueModifier: Style/SignalException: Enabled: false -# Offense count: 6 -# Cop supports --auto-correct. -Style/SpaceAfterNot: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 4b362248..23b593e0 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -17,7 +17,7 @@ def self.default # def acceptable?(val) - ! type_class.fetch(val).nil? + !type_class.fetch(val).nil? end def encode(value) diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index 81505f71..cdfecf7d 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -62,7 +62,7 @@ def compile_message private def has_extensions? - ! message_extension_fields.empty? + !message_extension_fields.empty? end def has_fields? diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 7e92f606..9d28d4fe 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -82,7 +82,7 @@ def get_field(name_or_tag, allow_extension = false) name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) field = field_store[name_or_tag] - if field && (allow_extension || ! field.extension?) + if field && (allow_extension || !field.extension?) field else nil diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index c042b58f..add710e9 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -109,7 +109,7 @@ def invoke_filter?(rpc_method, filter) # def invoke_via_except?(rpc_method, filter) except = [ filter.fetch(:except) { [] } ].flatten - except.empty? || ! except.include?(rpc_method) + except.empty? || !except.include?(rpc_method) end # Invoke the given :if callable (if any) and return its return value. @@ -158,7 +158,7 @@ def invoke_via_unless?(_rpc_method, filter) call_or_send(unless_check) end - ! skip_invoke + !skip_invoke end def rescue_filters diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 7f6d063b..2fe80205 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -61,7 +61,7 @@ def stop end def stopped? - ! end_time.nil? + !end_time.nil? end def rpc From 344d54c3bdd26975ce6269cb673595f24d0a25a0 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:16:54 -0700 Subject: [PATCH 133/298] Style/TrailingComma --- .rubocop_todo.yml | 6 ------ Rakefile | 2 +- lib/protobuf/field.rb | 2 +- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/rpc/connectors/zmq.rb | 2 +- lib/protobuf/rpc/middleware/logger.rb | 2 +- lib/protobuf/rpc/servers/zmq/server.rb | 6 +++--- lib/protobuf/rpc/stat.rb | 2 +- spec/encoding/extreme_values_spec.rb | Bin 1357 -> 1358 bytes spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/code_generator_spec.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 8 ++++---- .../generators/enum_generator_spec.rb | 4 ++-- .../generators/extension_generator_spec.rb | 2 +- .../generators/field_generator_spec.rb | 2 +- .../generators/file_generator_spec.rb | 4 ++-- .../generators/service_generator_spec.rb | 4 ++-- spec/lib/protobuf/message_spec.rb | 4 ++-- .../protobuf/rpc/connectors/common_spec.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 2 +- .../protobuf/rpc/middleware/logger_spec.rb | 2 +- .../rpc/middleware/request_decoder_spec.rb | 8 ++++---- .../rpc/middleware/response_encoder_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/server_spec.rb | 2 +- .../protobuf/rpc/service_directory_spec.rb | 12 ++++++------ spec/lib/protobuf/rpc/service_filters_spec.rb | 4 ++-- spec/lib/protobuf/rpc/service_spec.rb | 6 +++--- 27 files changed, 46 insertions(+), 52 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index e15afba1..988e786b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -116,12 +116,6 @@ Style/SpaceInsideBrackets: Style/StringLiterals: Enabled: false -# Offense count: 47 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. -Style/TrailingComma: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. Style/WordArray: diff --git a/Rakefile b/Rakefile index 57f3e75c..8df9895f 100644 --- a/Rakefile +++ b/Rakefile @@ -44,7 +44,7 @@ namespace :compile do 'tmp/rpc/dynamic_discovery.pb.rb' => 'lib/protobuf/rpc', 'tmp/rpc/rpc.pb.rb' => 'lib/protobuf/rpc', 'tmp/rpc/google/protobuf/descriptor.pb.rb' => 'lib/protobuf/descriptors/google/protobuf', - 'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler' + 'tmp/rpc/google/protobuf/compiler/plugin.pb.rb' => 'lib/protobuf/descriptors/google/protobuf/compiler', } files.each_pair do |source_file, destination_dir| diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index bbcd8c73..abe30a54 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -38,7 +38,7 @@ module Field :sfixed64 => ::Protobuf::Field::Sfixed64Field, :string => ::Protobuf::Field::StringField, :bytes => ::Protobuf::Field::BytesField, - :bool => ::Protobuf::Field::BoolField + :bool => ::Protobuf::Field::BoolField, }.freeze def self.build(message_class, rule, type, name, tag, options = {}) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 4c69025e..f6a0fc8e 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -14,7 +14,7 @@ class BaseField PACKED_TYPES = [ ::Protobuf::WireType::VARINT, ::Protobuf::WireType::FIXED32, - ::Protobuf::WireType::FIXED64 + ::Protobuf::WireType::FIXED64, ].freeze ## diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 1eaf9037..15fe47b0 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -147,7 +147,7 @@ def host_alive?(host) ping_port_open = ping_port_open?(host) self.class.ping_port_responses[host] = { :at => Time.now.to_i, - :ping_port_open => ping_port_open + :ping_port_open => ping_port_open, } ping_port_open end diff --git a/lib/protobuf/rpc/middleware/logger.rb b/lib/protobuf/rpc/middleware/logger.rb index 08a2c801..a5d30e36 100644 --- a/lib/protobuf/rpc/middleware/logger.rb +++ b/lib/protobuf/rpc/middleware/logger.rb @@ -63,7 +63,7 @@ def to_s(env) rpc, sizes, elapsed_time, - @end_time.try(:iso8601) + @end_time.try(:iso8601), ].compact.join(' - ') end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 57945758..87f663cb 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -79,7 +79,7 @@ def broadcast_beacons? def broadcast_flatline flatline = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE, - :server => to_proto + :server => to_proto, ) @beacon_socket.send(flatline.encode, 0) @@ -90,7 +90,7 @@ def broadcast_heartbeat heartbeat = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::HEARTBEAT, - :server => to_proto + :server => to_proto, ) @beacon_socket.send(heartbeat.encode, 0) @@ -234,7 +234,7 @@ def to_proto :address => frontend_ip, :port => frontend_port.to_s, :ttl => (beacon_interval * 1.5).ceil, - :services => ::Protobuf::Rpc::Service.implemented_services + :services => ::Protobuf::Rpc::Service.implemented_services, ) end diff --git a/lib/protobuf/rpc/stat.rb b/lib/protobuf/rpc/stat.rb index 2fe80205..a4c7e8d1 100644 --- a/lib/protobuf/rpc/stat.rb +++ b/lib/protobuf/rpc/stat.rb @@ -84,7 +84,7 @@ def to_s rpc, sizes, elapsed_time, - @end_time.try(:iso8601) + @end_time.try(:iso8601), ].compact.join(' - ') end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 65f1c910a25e433add419fb72f73bcd988187706..39aa70d11d5507e16d460101de0cd74c967d8655 100644 GIT binary patch delta 13 UcmX@hb&hL8Gz+87 9408, :backlog => 100, :threshold => 100, - :threads => 5 + :threads => 5, ) @server_thread = Thread.new(@runner) { |runner| runner.run } Thread.pass until @runner.running? diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 5cc77e38..956d05ae 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -44,7 +44,7 @@ described_class.fatal("something is wrong") end.to raise_error( ::Protobuf::CodeGenerator::CodeGeneratorFatalError, - "something is wrong" + "something is wrong", ) end end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 645bf424..55a73602 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -54,7 +54,7 @@ Test::EnumTestType::ONE, Test::EnumTestType::TWO, Test::EnumTestType::MINUS_ONE, - Test::EnumTestType::THREE + Test::EnumTestType::THREE, ]) end @@ -63,7 +63,7 @@ expect(EnumAliasTest.enums).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR, - EnumAliasTest::BAZ + EnumAliasTest::BAZ, ]) end end @@ -178,7 +178,7 @@ :MINUS_ONE => Test::EnumTestType::MINUS_ONE, :ONE => Test::EnumTestType::ONE, :TWO => Test::EnumTestType::TWO, - :THREE => Test::EnumTestType::THREE + :THREE => Test::EnumTestType::THREE, ) end @@ -186,7 +186,7 @@ expect(EnumAliasTest.values).to eq( :FOO => EnumAliasTest::FOO, :BAR => EnumAliasTest::BAR, - :BAZ => EnumAliasTest::BAZ + :BAZ => EnumAliasTest::BAZ, ) end end diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 6c3d8476..086cb4a2 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -8,7 +8,7 @@ [ { :name => 'FOO', :number => 1 }, { :name => 'BAR', :number => 2 }, - { :name => 'BAZ', :number => 3 } + { :name => 'BAZ', :number => 3 }, ] end let(:options) { nil } @@ -16,7 +16,7 @@ { :name => 'TestEnum', :value => values, - :options => options + :options => options, } end diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index 559f21b8..b3f68c8d 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -9,7 +9,7 @@ [ double('field descriptor 1', :to_s => " field 1\n"), double('field descriptor 2', :to_s => " field 2\n"), - double('field descriptor 3', :to_s => " field 3\n") + double('field descriptor 3', :to_s => " field 3\n"), ] end let(:message_type) { 'FooBar' } diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 0e72dde5..7ba88536 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -22,7 +22,7 @@ :type_name => type_name, :default_value => default_value, :extendee => extendee, - :options => field_options + :options => field_options, } end diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index bfb699d6..6560cf8d 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -16,8 +16,8 @@ base_descriptor_fields.merge( :dependency => [ 'test/bar.proto', - 'test/baz.proto' - ] + 'test/baz.proto', + ], ) end diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 0748ced2..03622318 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -7,13 +7,13 @@ let(:methods) do [ { :name => 'Search', :input_type => 'FooRequest', :output_type => 'FooResponse' }, - { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' } + { :name => 'FooBar', :input_type => '.foo.Request', :output_type => '.bar.Response' }, ] end let(:service_fields) do { :name => 'TestService', - :method => methods + :method => methods, } end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index d2e06024..56012dd6 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -386,14 +386,14 @@ it 'recursively hashes a repeated set of messages' do proto = Test::Nested.new(:multiple_resources => [ Test::Resource.new(:name => 'Resource 1'), - Test::Resource.new(:name => 'Resource 2') + Test::Resource.new(:name => 'Resource 2'), ]) expect(proto.to_hash).to eq( :multiple_resources => [ { :name => 'Resource 1' }, { :name => 'Resource 2' }, - ] + ], ) end end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 029c9b46..69205eb1 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -79,7 +79,7 @@ :service => service, :method => method, :request => request, - :client_host => client_host + :client_host => client_host, } end @@ -88,7 +88,7 @@ :service_name => service.name, :method_name => 'find', :request_proto => '', - :caller => client_host + :caller => client_host, ) end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 45142662..53a918b0 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -10,7 +10,7 @@ :method => "find", :timeout => 3, :host => "127.0.0.1", - :port => "9400" + :port => "9400", } end diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index db42a8f0..8ae5959d 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -24,7 +24,7 @@ Protobuf::Socketrpc::Request.new( :service_name => service_name, :method_name => method_name.to_s, - :request_proto => request + :request_proto => request, ) end let(:response_wrapper) { Protobuf::Socketrpc::Response.new(:response_proto => response) } diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index 1fd5fb4e..f95a05ab 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -6,7 +6,7 @@ let(:env) do Protobuf::Rpc::Env.new( 'encoded_request' => encoded_request, - 'log_signature' => 'log_signature' + 'log_signature' => 'log_signature', ) end let(:encoded_request) { request_wrapper.encode } @@ -18,7 +18,7 @@ :caller => client_host, :service_name => service_name, :method_name => method_name.to_s, - :request_proto => request + :request_proto => request, ) end let(:response_type) { rpc_method.response_type } @@ -88,7 +88,7 @@ :caller => client_host, :service_name => 'Foo', :method_name => method_name.to_s, - :request_proto => request + :request_proto => request, ) end @@ -103,7 +103,7 @@ :caller => client_host, :service_name => service_name, :method_name => 'foo', - :request_proto => request + :request_proto => request, ) end diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 83694083..00ab46cd 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -5,7 +5,7 @@ let(:env) do Protobuf::Rpc::Env.new( 'response_type' => Test::Resource, - 'log_signature' => 'log_signature' + 'log_signature' => 'log_signature', ) end let(:encoded_response) { response_wrapper.encode } diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index e8f0eacf..215230ba 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -9,7 +9,7 @@ :host => '127.0.0.1', :port => 9399, :worker_port => 9400, - :workers_only => true + :workers_only => true, } end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 32cb3b4f..6f39ae20 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -11,7 +11,7 @@ :address => '127.0.0.1', :port => '1111', :ttl => 10, - :services => %w(EchoService) + :services => %w(EchoService), ) end @@ -21,7 +21,7 @@ :address => '127.0.0.1', :port => "1112", :ttl => 10, - :services => %w(HelloService) + :services => %w(HelloService), ) end @@ -31,7 +31,7 @@ :address => '127.0.0.1', :port => '1113', :ttl => 1, - :services => %w(HelloService) + :services => %w(HelloService), ) end @@ -41,7 +41,7 @@ :address => '127.0.0.1', :port => '1114', :ttl => 10, - :services => %w(HelloService EchoService) + :services => %w(HelloService EchoService), ) end @@ -65,7 +65,7 @@ def send_beacon(type, server) type = type.to_s.upcase beacon = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :server => server, - :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType.fetch(type) + :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType.fetch(type), ) @socket.send(beacon.encode, 0, @address, @port) @@ -266,7 +266,7 @@ def send_beacon(type, server) :address => '127.0.0.1', :port => (5555 + x).to_s, :ttl => rand(1..5), - :services => 10.times.map { |y| "PerformanceService#{y}" } + :services => 10.times.map { |y| "PerformanceService#{y}" }, ) end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 27f5d356..0694533d 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -362,7 +362,7 @@ def inner_around :endpoint, :inner_around_bottom, :outer_around_bottom, - ] + ], ) end @@ -390,7 +390,7 @@ def inner_around :outer_around_top, :inner_around, :outer_around_bottom, - ] + ], ) end diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 2d01202e..27518464 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -67,7 +67,7 @@ .with(hash_including( :service => subject, :host => subject.host, - :port => subject.port + :port => subject.port, )).and_return(client) expect(subject.client).to eq client end @@ -129,7 +129,7 @@ def find_with_rpc_failed let(:env) do Protobuf::Rpc::Env.new( 'request' => request, - 'response_type' => response_type + 'response_type' => response_type, ) end let(:response_type) { service.rpcs[:find_with_implied_response].response_type } @@ -146,7 +146,7 @@ def find_with_rpc_failed let(:env) do Protobuf::Rpc::Env.new( 'method_name' => :find_with_respond_with, - 'request' => request + 'request' => request, ) end From 58ca57e2aac6d5f9860e64534d5ef2d23c934ed2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:17:35 -0700 Subject: [PATCH 134/298] Style/SignalException --- .rubocop_todo.yml | 6 ------ lib/protobuf.rb | 2 +- lib/protobuf/code_generator.rb | 2 +- lib/protobuf/decoder.rb | 6 +++--- lib/protobuf/encoder.rb | 2 +- lib/protobuf/field.rb | 2 +- lib/protobuf/field/base_field.rb | 10 +++++----- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/field/enum_field.rb | 4 ++-- lib/protobuf/field/field_array.rb | 4 ++-- lib/protobuf/field/message_field.rb | 4 ++-- lib/protobuf/generators/printable.rb | 2 +- lib/protobuf/lifecycle.rb | 2 +- lib/protobuf/message.rb | 4 ++-- lib/protobuf/message/fields.rb | 4 ++-- lib/protobuf/rpc/buffer.rb | 2 +- lib/protobuf/rpc/client.rb | 8 ++++---- lib/protobuf/rpc/connectors/base.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 20 +++++++++---------- lib/protobuf/rpc/connectors/zmq.rb | 12 +++++------ .../rpc/middleware/request_decoder.rb | 2 +- .../rpc/middleware/response_encoder.rb | 2 +- lib/protobuf/rpc/servers/socket/server.rb | 2 +- lib/protobuf/rpc/servers/socket/worker.rb | 2 +- lib/protobuf/rpc/servers/socket_runner.rb | 2 +- lib/protobuf/rpc/servers/zmq/util.rb | 2 +- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_dispatcher.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 4 ++-- spec/functional/socket_server_spec.rb | 6 +++--- spec/functional/zmq_server_spec.rb | 10 +++++----- spec/lib/protobuf/rpc/connectors/base_spec.rb | 4 ++-- .../protobuf/rpc/connectors/common_spec.rb | 8 ++++---- spec/lib/protobuf/rpc/service_filters_spec.rb | 8 ++++---- 35 files changed, 76 insertions(+), 82 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 988e786b..cd9d0cb8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,12 +99,6 @@ Style/RaiseArgs: Style/RescueModifier: Enabled: false -# Offense count: 67 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/SignalException: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf.rb b/lib/protobuf.rb index fb3129ec..ca3c311c 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -41,7 +41,7 @@ def self.connector_type end def self.connector_type=(type) - raise ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type) + fail ArgumentError, 'Invalid connector type given' unless CONNECTORS.include?(type) @connector_type = type end diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index 7aa96272..cf39b0df 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -6,7 +6,7 @@ class CodeGenerator CodeGeneratorFatalError = Class.new(RuntimeError) def self.fatal(message) - raise CodeGeneratorFatalError, message + fail CodeGeneratorFatalError, message end def self.print_tag_warning_suppress diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index ddcc4ac3..601e06f5 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -24,11 +24,11 @@ def self.read_field(stream) when ::Protobuf::WireType::FIXED32 then read_fixed32(stream) when ::Protobuf::WireType::START_GROUP then - raise NotImplementedError, 'Group is deprecated.' + fail NotImplementedError, 'Group is deprecated.' when ::Protobuf::WireType::END_GROUP then - raise NotImplementedError, 'Group is deprecated.' + fail NotImplementedError, 'Group is deprecated.' else - raise InvalidWireType, wire_type + fail InvalidWireType, wire_type end [tag, bytes] diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 1eec5cf7..4c19ab08 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -9,7 +9,7 @@ def self.encode(stream, message) def initialize(message, stream) unless message.respond_to?(:each_field_for_serialization) - raise ArgumentError, "Message instance must respond to :each_field_for_serialization" + fail ArgumentError, "Message instance must respond to :each_field_for_serialization" end @message = message diff --git a/lib/protobuf/field.rb b/lib/protobuf/field.rb index abe30a54..02cc14f4 100644 --- a/lib/protobuf/field.rb +++ b/lib/protobuf/field.rb @@ -59,7 +59,7 @@ def self.field_class(type) elsif type < ::Protobuf::Field::BaseField type else - raise ArgumentError, "Invalid field type #{type}" + fail ArgumentError, "Invalid field type #{type}" end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index f6a0fc8e..8b722e8a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -60,7 +60,7 @@ def coerce!(value) end def decode(_bytes) - raise NotImplementedError, "#{self.class.name}##{__method__}" + fail NotImplementedError, "#{self.class.name}##{__method__}" end def default @@ -80,7 +80,7 @@ def deprecated? end def encode(_value) - raise NotImplementedError, "#{self.class.name}##{__method__}" + fail NotImplementedError, "#{self.class.name}##{__method__}" end def extension? @@ -204,7 +204,7 @@ def define_array_setter val = val.dup val.compact! else - raise TypeError, <<-TYPE_ERROR + fail TypeError, <<-TYPE_ERROR Expected repeated value of type '#{field.type_class}' Got '#{val.class}' for repeated protobuf field #{field.name} TYPE_ERROR @@ -241,7 +241,7 @@ def define_setter elsif field.acceptable?(val) @values[field.name] = field.coerce!(val) else - raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" + fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end end @@ -257,7 +257,7 @@ def typed_default_value def validate_packed_field if packed? && ! ::Protobuf::Field::BaseField::PACKED_TYPES.include?(wire_type) - raise "Can't use packed encoding for '#{type_class}' type" + fail "Can't use packed encoding for '#{type_class}' type" end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index c095629f..733e391e 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -64,7 +64,7 @@ def define_setter elsif field.acceptable?(val) @values[field.name] = val.dup else - raise TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" + fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end rescue NoMethodError => ex logger.error { ex.message } diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 23b593e0..4f31316f 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -9,7 +9,7 @@ class EnumField < VarintField # def self.default - raise NoMethodError, "#{self}.#{__method__} must be called on an instance" + fail NoMethodError, "#{self}.#{__method__} must be called on an instance" end ## @@ -49,7 +49,7 @@ def define_setter @values.delete(field.name) else value = field.type_class.fetch(value) - raise TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value + fail TypeError, "Invalid Enum value: #{orig_value.inspect} for #{field.name}" unless value @values[field.name] = value end diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 14eacd34..65447a31 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -62,7 +62,7 @@ def unshift(val) def normalize(value) value = value.to_proto if value.respond_to?(:to_proto) - raise TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value) + fail TypeError, "Unacceptable value #{value} for field #{field.name} of type #{field.type_class}" unless field.acceptable?(value) if field.is_a?(::Protobuf::Field::EnumField) field.type_class.fetch(value) @@ -74,7 +74,7 @@ def normalize(value) end def raise_type_error(val) - raise TypeError, <<-TYPE_ERROR + fail TypeError, <<-TYPE_ERROR Expected repeated value of type '#{field.type_class}' Got '#{val.class}' for repeated protobuf field #{field.name} TYPE_ERROR diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 5161edbe..45dec389 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -10,7 +10,7 @@ class MessageField < BaseField def acceptable?(val) unless val.instance_of?(type_class) || val.respond_to?(:to_hash) - raise TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" + fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end true @@ -54,7 +54,7 @@ def define_setter when val.respond_to?(:to_hash) then @values[field.name] = field.type_class.new(val.to_hash) else - raise TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'" + fail TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'" end end end diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 268ce42f..6347afe2 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -84,7 +84,7 @@ def parent_class(type) when :service then PARENT_CLASS_SERVICE else - raise "Unknown parent class type #{type}: #{caller[0..5].join("\n")}" + fail "Unknown parent class type #{type}: #{caller[0..5].join("\n")}" end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 60c2bd95..fd688820 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -3,7 +3,7 @@ class Lifecycle include ::Protobuf::Logging def self.register(event_name, &blk) - raise "Lifecycle register must have a block" unless block_given? + fail "Lifecycle register must have a block" unless block_given? event_name = normalized_event_name(event_name) if ::Protobuf.print_deprecation_warnings? diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 622e2942..c5b901ed 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -74,7 +74,7 @@ def each_field_for_serialization value = @values[field.getter] if value.nil? - raise ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." + fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." else yield(field, value) end @@ -138,7 +138,7 @@ def []=(name, value) __send__(field.setter, value) unless value.nil? else unless ::Protobuf.ignore_unknown_fields? - raise ::Protobuf::FieldNotDefinedError, name + fail ::Protobuf::FieldNotDefinedError, name end end end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 9d28d4fe..234c0dfa 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -106,13 +106,13 @@ def define_field(rule, type_class, field_name, tag, options) def raise_if_tag_collision(tag, field_name) if get_field(tag, true) - raise TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) + fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) end end def raise_if_name_collision(field_name) if get_field(field_name, true) - raise DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) + fail DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) end end diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index 97587a00..dc63dbd6 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -28,7 +28,7 @@ def write(force_mode = true) if force_mode && reading? self.mode = :write elsif !force_mode && reading? - raise 'You chose to write the buffer when in read mode' + fail 'You chose to write the buffer when in read mode' end @size = @data.length diff --git a/lib/protobuf/rpc/client.rb b/lib/protobuf/rpc/client.rb index e810530a..618aa503 100644 --- a/lib/protobuf/rpc/client.rb +++ b/lib/protobuf/rpc/client.rb @@ -27,7 +27,7 @@ class Client # }) # def initialize(options = {}) - raise "Invalid client configuration. Service must be defined." if options[:service].nil? + fail "Invalid client configuration. Service must be defined." if options[:service].nil? @connector = Connector.connector_for_client.new(options) logger.debug { sign_message("Initialized with options: #{options.inspect}") } end @@ -47,7 +47,7 @@ def on_complete(&complete_cb) def on_complete=(callable) if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 - raise "callable must take a single argument and respond to :call" + fail "callable must take a single argument and respond to :call" end @connector.complete_cb = callable @@ -66,7 +66,7 @@ def on_failure(&failure_cb) def on_failure=(callable) if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 - raise "Callable must take a single argument and respond to :call" + fail "Callable must take a single argument and respond to :call" end @connector.failure_cb = callable @@ -85,7 +85,7 @@ def on_success(&success_cb) def on_success=(callable) if !callable.nil? && !callable.respond_to?(:call) && callable.arity != 1 - raise "Callable must take a single argument and respond to :call" + fail "Callable must take a single argument and respond to :call" end @connector.success_cb = callable diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 81326cd1..8f6d43c5 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -38,7 +38,7 @@ def first_alive_load_balance? end def send_request - raise 'If you inherit a Connector from Base you must implement send_request' + fail 'If you inherit a Connector from Base you must implement send_request' end def ping_port diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index 0bcb310d..dd02b34f 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -38,7 +38,7 @@ def data_callback(data) # # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason) # @param [String] message The error message - def fail(code, message) + def failure(code, message) @error = ClientError.new @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message @@ -60,7 +60,7 @@ def initialize_stats @stats.method_name = @options[:method].to_s rescue => ex log_exception(ex) - fail(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") + failure(:RPC_ERROR, "Invalid stats configuration. #{ex.message}") end def log_signature @@ -83,7 +83,7 @@ def parse_response # fail the call if we already know the client is failed # (don't try to parse out the response payload) - fail(response_wrapper.error_reason, response_wrapper.error) + failure(response_wrapper.error_reason, response_wrapper.error) else logger.debug { sign_message("Successful response parsed") } @@ -91,7 +91,7 @@ def parse_response parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) if parsed.nil? && !response_wrapper.has_field?(:error_reason) - fail(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') + failure(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') else verify_callbacks succeed(parsed) @@ -103,7 +103,7 @@ def parse_response def post_init send_data unless error? rescue => e - fail(:RPC_ERROR, "Connection error: #{e.message}") + failure(:RPC_ERROR, "Connection error: #{e.message}") end def request_bytes @@ -115,7 +115,7 @@ def request_bytes return ::Protobuf::Socketrpc::Request.encode(fields) rescue => e - fail(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") + failure(:INVALID_REQUEST_PROTO, "Could not set request proto: #{e.message}") end def setup_connection @@ -130,7 +130,7 @@ def succeed(response) rescue => e logger.error { sign_message("Success callback error encountered") } log_exception(e) - fail(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") + failure(:RPC_ERROR, "An exception occurred while calling on_success: #{e.message}") ensure complete end @@ -148,14 +148,14 @@ def timeout def timeout_wrap(&block) ::Timeout.timeout(timeout, &block) rescue ::Timeout::Error - fail(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond") + failure(:RPC_FAILED, "The server took longer than #{timeout} seconds to respond") end def validate_request_type! unless @options[:request].class == @options[:request_type] expected = @options[:request_type].name actual = @options[:request].class.name - fail(:INVALID_REQUEST_PROTO, "Expected request type to be type of #{expected}, got #{actual} instead") + failure(:INVALID_REQUEST_PROTO, "Expected request type to be type of #{expected}, got #{actual} instead") end end @@ -169,7 +169,7 @@ def verify_callbacks def verify_options! # Verify the options that are necessary and merge them in [:service, :method, :host, :port].each do |opt| - fail(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil? + failure(:RPC_ERROR, "Invalid client connection configuration. #{opt} must be a defined option.") if @options[opt].nil? end end end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 15fe47b0..2af45f7d 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -132,7 +132,7 @@ def lookup_server_uri sleep(1.0 / 100.0) end - raise "Host not found for service #{service}" + fail "Host not found for service #{service}" end def host_alive?(host) @@ -181,7 +181,7 @@ def send_request_with_lazy_pirate parse_response rescue RequestTimeout retry if attempt < CLIENT_RETRIES - fail(:RPC_FAILED, "The server repeatedly failed to respond within #{timeout} seconds") + failure(:RPC_FAILED, "The server repeatedly failed to respond within #{timeout} seconds") end end @@ -256,13 +256,13 @@ def zmq_context def zmq_eagain_error_check(return_code, source) unless ::ZMQ::Util.resultcode_ok?(return_code || -1) if ::ZMQ::Util.errno == ::ZMQ::EAGAIN - raise ZmqEagainError, <<-ERROR + fail ZmqEagainError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR else - raise <<-ERROR + fail <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} @@ -273,7 +273,7 @@ def zmq_eagain_error_check(return_code, source) def zmq_error_check(return_code, source) unless ::ZMQ::Util.resultcode_ok?(return_code || -1) - raise <<-ERROR + fail <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} @@ -283,7 +283,7 @@ def zmq_error_check(return_code, source) def zmq_recoverable_error_check(return_code, source) unless ::ZMQ::Util.resultcode_ok?(return_code || -1) - raise ZmqRecoverableError, <<-ERROR + fail ZmqRecoverableError, <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index c142a586..61bc6d3b 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -37,7 +37,7 @@ def method_name method_name = request_wrapper.method_name.underscore.to_sym unless service.rpc_method?(method_name) - raise MethodNotFound.new("#{service.name}##{method_name} is not a defined RPC method.") + fail MethodNotFound.new("#{service.name}##{method_name} is not a defined RPC method.") end method_name diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index ec30bafa..a4e652ea 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -66,7 +66,7 @@ def validate!(candidate) expected = env.response_type if expected != actual - raise BadResponseProto.new("Expected response to be of type #{expected.name} but was #{actual.name}") + fail BadResponseProto.new("Expected response to be of type #{expected.name} but was #{actual.name}") end candidate diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 4353c0a5..e096b7c7 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -55,7 +55,7 @@ def run @threads = [] @server = ::TCPServer.new(host, port) - raise "The server was unable to start properly." if @server.closed? + fail "The server was unable to start properly." if @server.closed? @server.listen(backlog) @working = [] diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index 984ae01e..b64ee8db 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -33,7 +33,7 @@ def read_data end def send_data(data) - raise 'Socket closed unexpectedly' unless socket_writable? + fail 'Socket closed unexpectedly' unless socket_writable? response_buffer = Protobuf::Rpc::Buffer.new(:write) response_buffer.set_data(data) diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index bd70aad2..e81159aa 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -11,7 +11,7 @@ def initialize(options) when options.respond_to?(:to_hash) then options.to_hash else - raise "Cannot parser Socket Server - server options" + fail "Cannot parser Socket Server - server options" end @server = ::Protobuf::Rpc::Socket::Server.new(@options) diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index bdaaee96..ee5e0f83 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -20,7 +20,7 @@ def self.included(base) def zmq_error_check(return_code, source = nil) unless ::ZMQ::Util.resultcode_ok?(return_code) - raise <<-ERROR + fail <<-ERROR Last ZMQ API call #{source ? "to #{source}" : ""} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 70b53548..5d213640 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -12,7 +12,7 @@ def initialize(options) when options.respond_to?(:to_hash) then options.to_hash else - raise "Cannot parser Zmq Server - server options" + fail "Cannot parser Zmq Server - server options" end end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index dea0eda2..dea54723 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -170,7 +170,7 @@ def response_type # def rpc_failed(message) message = message.message if message.respond_to?(:message) - raise RpcFailed.new(message) + fail RpcFailed.new(message) end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 991fd657..5c1f151c 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -27,7 +27,7 @@ def rpc_service # Call the given service method. def dispatch_rpc_request unless rpc_service.respond_to?(method_name) - raise MethodNotFound.new("#{service_name}##{method_name} is not a publicly defined method.") + fail MethodNotFound.new("#{service_name}##{method_name} is not a publicly defined method.") end rpc_service.callable_rpc_method(method_name).call diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index add710e9..2c6b9b09 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -37,7 +37,7 @@ def rescue_filters def rescue_from(*ex_klasses, &block) options = ex_klasses.last.is_a?(Hash) ? ex_klasses.pop : {} callable = options.delete(:with) { block } - raise ArgumentError, 'Option :with missing from rescue_from options' if callable.nil? + fail ArgumentError, 'Option :with missing from rescue_from options' if callable.nil? ex_klasses.each { |ex_klass| rescue_filters[ex_klass] = callable } end @@ -259,7 +259,7 @@ def call_or_send(callable, *args, &block) when respond_to?(callable, true) then __send__(callable, *args, &block) else - raise "Object #{callable} is not callable" + fail "Object #{callable} is not callable" end return_value diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index c6098b6c..6b034845 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -26,7 +26,7 @@ end c.on_failure do |err| - raise err.inspect + fail err.inspect end end end.to_not raise_error @@ -38,7 +38,7 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end @@ -51,7 +51,7 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 0c37a573..18d1941b 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -34,7 +34,7 @@ end c.on_failure do |err| - raise err.inspect + fail err.inspect end end end.to_not raise_error @@ -53,7 +53,7 @@ end c.on_failure do |err| - raise err.inspect + fail err.inspect end end end @@ -68,7 +68,7 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end expect(error.message).to match(/Required field.*does not have a value/) @@ -82,7 +82,7 @@ client = ::Test::ResourceService.client client.find(request) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end expect(error.message).to match(/expected request.*ResourceFindRequest.*Resource instead/i) @@ -95,7 +95,7 @@ client = ::Test::ResourceService.client(:timeout => 1) client.find_with_sleep(:sleep => 2) do |c| - c.on_success { raise "shouldn't pass" } + c.on_success { fail "shouldn't pass" } c.on_failure { |e| error = e } end expect(error.message).to match(/The server repeatedly failed to respond/) diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 5d911d2c..5a9945ae 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -30,7 +30,7 @@ describe '#success_cb' do it 'allows setting the success callback and calling it' do expect(subject.success_cb).to be_nil - cb = proc { |res| raise res } + cb = proc { |res| fail res } subject.success_cb = cb expect(subject.success_cb).to eq(cb) expect { subject.success_cb.call('an error from cb') }.to raise_error 'an error from cb' @@ -40,7 +40,7 @@ describe '#failure_cb' do it 'allows setting the failure callback and calling it' do expect(subject.failure_cb).to be_nil - cb = proc { |res| raise res } + cb = proc { |res| fail res } subject.failure_cb = cb expect(subject.failure_cb).to eq(cb) expect { subject.failure_cb.call('an error from cb') }.to raise_error 'an error from cb' diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 69205eb1..47ff900b 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -19,7 +19,7 @@ specify { expect(subject.respond_to?(:request_caller)).to be true } specify { expect(subject.respond_to?(:data_callback)).to be true } specify { expect(subject.respond_to?(:error)).to be true } - specify { expect(subject.respond_to?(:fail)).to be true } + specify { expect(subject.respond_to?(:failure)).to be true } specify { expect(subject.respond_to?(:complete)).to be true } specify { expect(subject.respond_to?(:parse_response)).to be true } specify { expect(subject.respond_to?(:verify_options!)).to be true } @@ -93,7 +93,7 @@ end before { allow(subject).to receive(:validate_request_type!).and_return(true) } - before { expect(subject).not_to receive(:fail) } + before { expect(subject).not_to receive(:failure) } specify { expect(subject.request_bytes).to eq expected.encode } end @@ -161,8 +161,8 @@ end - it_behaves_like("a ConnectorDisposition", :fail, "failure_cb", "code", "message") - it_behaves_like("a ConnectorDisposition", :fail, "complete_cb", "code", "message") + it_behaves_like("a ConnectorDisposition", :failure, "failure_cb", "code", "message") + it_behaves_like("a ConnectorDisposition", :failure, "complete_cb", "code", "message") it_behaves_like("a ConnectorDisposition", :succeed, "complete_cb", "response") it_behaves_like("a ConnectorDisposition", :succeed, "success_cb", "response") it_behaves_like("a ConnectorDisposition", :complete, "complete_cb") diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index 0694533d..caae7b43 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -410,22 +410,22 @@ class FilterTest def filter_with_error1 @called << :filter_with_error1 - raise CustomError1, 'Filter 1 failed' + fail CustomError1, 'Filter 1 failed' end def filter_with_error2 @called << :filter_with_error2 - raise CustomError1, 'Filter 2 failed' + fail CustomError1, 'Filter 2 failed' end def filter_with_error3 @called << :filter_with_error3 - raise CustomError3, 'Filter 3 failed' + fail CustomError3, 'Filter 3 failed' end def filter_with_runtime_error @called << :filter_with_runtime_error - raise 'Filter with runtime error failed' + fail 'Filter with runtime error failed' end def custom_error_occurred(ex) From b51ca10d8ada9936385216d30183534e9c8e9a7f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:19:12 -0700 Subject: [PATCH 135/298] Style/RaiseArgs --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/middleware/request_decoder.rb | 8 ++++---- lib/protobuf/rpc/middleware/response_encoder.rb | 4 ++-- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_dispatcher.rb | 2 +- 5 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cd9d0cb8..c2754be4 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -90,11 +90,6 @@ Style/NumericLiterals: Style/PredicateName: Enabled: false -# Offense count: 8 -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/RaiseArgs: - Enabled: false - # Offense count: 2 Style/RescueModifier: Enabled: false diff --git a/lib/protobuf/rpc/middleware/request_decoder.rb b/lib/protobuf/rpc/middleware/request_decoder.rb index 61bc6d3b..111d0c0d 100644 --- a/lib/protobuf/rpc/middleware/request_decoder.rb +++ b/lib/protobuf/rpc/middleware/request_decoder.rb @@ -37,7 +37,7 @@ def method_name method_name = request_wrapper.method_name.underscore.to_sym unless service.rpc_method?(method_name) - fail MethodNotFound.new("#{service.name}##{method_name} is not a defined RPC method.") + fail MethodNotFound, "#{service.name}##{method_name} is not a defined RPC method." end method_name @@ -50,7 +50,7 @@ def request rpc_method.request_type.decode(data) end rescue => exception - raise BadRequestData.new("Unable to decode request: #{exception.message}") + raise BadRequestData, "Unable to decode request: #{exception.message}" end # Decode the incoming request object into our expected request object @@ -61,7 +61,7 @@ def request_wrapper Socketrpc::Request.decode(env.encoded_request) end rescue => exception - raise BadRequestData.new("Unable to decode request: #{exception.message}") + raise BadRequestData, "Unable to decode request: #{exception.message}" end def rpc_method @@ -71,7 +71,7 @@ def rpc_method def service @service ||= service_name.constantize rescue NameError - raise ServiceNotFound.new("Service class #{service_name} is not defined.") + raise ServiceNotFound, "Service class #{service_name} is not defined." end def service_name diff --git a/lib/protobuf/rpc/middleware/response_encoder.rb b/lib/protobuf/rpc/middleware/response_encoder.rb index a4e652ea..d303a9b2 100644 --- a/lib/protobuf/rpc/middleware/response_encoder.rb +++ b/lib/protobuf/rpc/middleware/response_encoder.rb @@ -35,7 +35,7 @@ def encoded_response # Rescue encoding exceptions, re-wrap them as generic protobuf errors, # and re-raise them - raise PbError.new(exception.message) + raise PbError, exception.message end # Prod the object to see if we can produce a proto object as a response @@ -66,7 +66,7 @@ def validate!(candidate) expected = env.response_type if expected != actual - fail BadResponseProto.new("Expected response to be of type #{expected.name} but was #{actual.name}") + fail BadResponseProto, "Expected response to be of type #{expected.name} but was #{actual.name}" end candidate diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index dea54723..9b952b29 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -170,7 +170,7 @@ def response_type # def rpc_failed(message) message = message.message if message.respond_to?(:message) - fail RpcFailed.new(message) + fail RpcFailed, message end end diff --git a/lib/protobuf/rpc/service_dispatcher.rb b/lib/protobuf/rpc/service_dispatcher.rb index 5c1f151c..6e00523e 100644 --- a/lib/protobuf/rpc/service_dispatcher.rb +++ b/lib/protobuf/rpc/service_dispatcher.rb @@ -27,7 +27,7 @@ def rpc_service # Call the given service method. def dispatch_rpc_request unless rpc_service.respond_to?(method_name) - fail MethodNotFound.new("#{service_name}##{method_name} is not a publicly defined method.") + fail MethodNotFound, "#{service_name}##{method_name} is not a publicly defined method." end rpc_service.callable_rpc_method(method_name).call From ed29436e205215614f701a3a3ea47db40682e3d8 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:20:24 -0700 Subject: [PATCH 136/298] Style/IfUnlessModifier --- .rubocop_todo.yml | 5 ----- lib/protobuf/field/enum_field.rb | 4 +--- lib/protobuf/rpc/buffer.rb | 4 +--- 3 files changed, 2 insertions(+), 11 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index c2754be4..8f489f57 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -66,11 +66,6 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 2 -# Configuration parameters: MaxLineLength. -Style/IfUnlessModifier: - Enabled: false - # Offense count: 14 Style/Lambda: Enabled: false diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 4f31316f..ac26ea0e 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -25,9 +25,7 @@ def encode(value) end def decode(value) - if acceptable?(value) - value - end + value if acceptable?(value) end def enum? diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index dc63dbd6..aa4b4d1e 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -70,9 +70,7 @@ def get_data_size # rubocop:disable Style/AccessorMethodName private def check_for_flush - if !@size.nil? && @data.length == @size - @flush = true - end + @flush = true if !@size.nil? && @data.length == @size end end end From 272e075da02bdee8780d75993e09ef874a7e37ed Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:22:52 -0700 Subject: [PATCH 137/298] Style/PredicateName --- .rubocop_todo.yml | 5 ----- lib/protobuf/deprecator.rb | 2 +- lib/protobuf/generators/message_generator.rb | 22 ++++++++++---------- lib/protobuf/message.rb | 7 +++++-- 4 files changed, 17 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8f489f57..37b1d224 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -80,11 +80,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 7 -# Configuration parameters: NamePrefix, NamePrefixBlacklist. -Style/PredicateName: - Enabled: false - # Offense count: 2 Style/RescueModifier: Enabled: false diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index 856f8480..68167378 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -11,7 +11,7 @@ def warn_deprecated(old_method, new_method) def deprecate_method(old_method, new_method) class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) def #{old_method}(*args) - warn_deprecated("#{old_method}", "#{new_method}") + self.class.warn_deprecated("#{old_method}", "#{new_method}") new_meth = method("#{new_method}") if new_meth.arity == 0 __send__("#{new_method}") diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index cdfecf7d..c68b3ad0 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -23,7 +23,7 @@ def compile def compile_declaration run_once(:compile_declaration) do - if is_printable? + if printable? print_class(descriptor.name, :message) do group = GroupGenerator.new(current_indent) group.add_enums(descriptor.enum_type, :namespace => type_namespace) @@ -38,7 +38,7 @@ def compile_declaration def compile_message run_once(:compile_message) do - if is_printable? + if printable? print_class(descriptor.name, nil) do group = GroupGenerator.new(current_indent) group.add_messages(descriptor.nested_type, :extension_fields => @extension_fields, :namespace => type_namespace) @@ -61,31 +61,31 @@ def compile_message private - def has_extensions? + def extensions? !message_extension_fields.empty? end - def has_fields? + def fields? descriptor.field.count > 0 end - def has_nested_enums? + def nested_enums? descriptor.enum_type.count > 0 end - def has_nested_messages? + def nested_messages? descriptor.nested_type.count > 0 end - def has_nested_types? - has_nested_enums? || has_nested_messages? + def nested_types? + nested_enums? || nested_messages? end - def is_printable? + def printable? if @only_declarations - has_nested_types? + nested_types? else - has_fields? || has_nested_messages? || has_extensions? + fields? || nested_messages? || extensions? end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index c5b901ed..51cd5863 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -11,6 +11,8 @@ class Message # Includes & Extends # + extend ::Protobuf::Deprecator + extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization @@ -81,16 +83,17 @@ def each_field_for_serialization end end - def has_field?(name) + def field?(name) @values.key?(name) end + deprecate_method(:has_field?, :field?) def inspect to_hash.inspect end def respond_to_has?(key) - respond_to?(key) && has_field?(key) + respond_to?(key) && field?(key) end def respond_to_has_and_present?(key) From 9e8dca096d8bb92802c6a2b0ac820751e1c08f2e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 13:37:35 -0700 Subject: [PATCH 138/298] Style/RescueModifier --- .rubocop_todo.yml | 6 +----- lib/protobuf/rpc/connectors/zmq.rb | 6 +++++- lib/protobuf/rpc/servers/socket/server.rb | 6 +++++- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 37b1d224..fa2a0bc0 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -26,7 +26,7 @@ Metrics/LineLength: # Offense count: 47 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 41 + Max: 45 # Offense count: 2 # Configuration parameters: CountKeywordArgs. @@ -80,10 +80,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 2 -Style/RescueModifier: - Enabled: false - # Offense count: 126 # Cop supports --auto-correct. Style/SpaceInsideBrackets: diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 2af45f7d..8ed87637 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -165,7 +165,11 @@ def ping_port_open?(host) rescue false ensure - socket.close rescue nil + begin + socket && socket.close + rescue IOError + nil + end end # Trying a number of times, attempt to get a response from the server. diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index e096b7c7..b9e9c708 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -64,7 +64,11 @@ def run while running? logger.debug { sign_message("Waiting for connections") } - ready_cnxns = IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) rescue nil + ready_cnxns = begin + IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) + rescue IOError + nil + end if ready_cnxns cnxns = ready_cnxns.first From 09e5f7ab5bf08a66582404643d00e449f22a05fc Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 14:28:05 -0700 Subject: [PATCH 139/298] Style/FileName --- .rubocop.yml | 4 ++++ .rubocop_todo.yml | 5 ----- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 77a6182c..33450227 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -17,6 +17,10 @@ Style/EmptyLines: Exclude: - '**/*.pb.rb' +Style/FileName: + Exclude: + - '**/protoc-gen-ruby*' + Style/IndentHash: EnforcedStyle: consistent diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index fa2a0bc0..453b7653 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -50,11 +50,6 @@ Style/DoubleNegation: Style/EmptyLinesAroundBody: Enabled: false -# Offense count: 2 -# Configuration parameters: Exclude. -Style/FileName: - Enabled: false - # Offense count: 20 # Configuration parameters: MinBodyLength. Style/GuardClause: From eaf4a885b277bdae7cf7e0d21c5c5c760f70475a Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 14:41:31 -0700 Subject: [PATCH 140/298] Style/Lambda --- .rubocop_todo.yml | 4 ---- lib/protobuf/generators/file_generator.rb | 5 ++--- lib/protobuf/rpc/service.rb | 2 +- lib/protobuf/rpc/service_filters.rb | 8 ++++---- spec/lib/protobuf/rpc/connectors/common_spec.rb | 4 ++-- spec/lib/protobuf/rpc/service_dispatcher_spec.rb | 2 +- spec/lib/protobuf/rpc/service_filters_spec.rb | 8 ++++---- 7 files changed, 14 insertions(+), 19 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 453b7653..442f5ea3 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,10 +61,6 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 14 -Style/Lambda: - Enabled: false - # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 77580bfd..afeb5207 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -118,10 +118,9 @@ def print_import_requires end def print_package(&block) - final = lambda { block.call } namespaces = descriptor.package.split('.') - namespaces.reverse.reduce(final) do |previous, namespace| - lambda { print_module(namespace, &previous) } + namespaces.reverse.reduce(block) do |previous, namespace| + -> { print_module(namespace, &previous) } end.call end diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 9b952b29..327586ed 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -126,7 +126,7 @@ def self.rpc_method?(name) # is why we wrap the method call). # def callable_rpc_method(method_name) - lambda { run_filters(method_name) } + -> { run_filters(method_name) } end # Response object for this rpc cycle. Not assignable. diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 2c6b9b09..df09098e 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -120,7 +120,7 @@ def invoke_via_except?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_if?(_rpc_method, filter) - if_check = filter.fetch(:if) { lambda { |_service| return true } } + if_check = filter.fetch(:if) { ->(_service) { return true } } do_invoke = case when if_check.nil? then true @@ -150,7 +150,7 @@ def invoke_via_only?(rpc_method, filter) # or an object that responds to `call`. # def invoke_via_unless?(_rpc_method, filter) - unless_check = filter.fetch(:unless) { lambda { |_service| return false } } + unless_check = filter.fetch(:unless) { ->(_service) { return false } } skip_invoke = case when unless_check.nil? then false @@ -209,10 +209,10 @@ def run_unwrapped_filters(unwrapped_filters, rpc_method, stop_on_false_return = # end # def run_around_filters(rpc_method) - final = lambda { __send__(rpc_method) } + final = -> { __send__(rpc_method) } filters[:around].reverse.reduce(final) do |previous, filter| if invoke_filter?(rpc_method, filter) - lambda { call_or_send(filter[:callable], &previous) } + -> { call_or_send(filter[:callable], &previous) } else previous end diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 47ff900b..54ab8c33 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -111,7 +111,7 @@ end it "doesn't set @failure_cb when already defined" do - set_cb = lambda { true } + set_cb = -> { true } subject.instance_variable_set(:@failure_cb, set_cb) subject.verify_callbacks expect(subject.instance_variable_get(:@failure_cb)).to eq(set_cb) @@ -119,7 +119,7 @@ end it "doesn't set @success_cb when already defined" do - set_cb = lambda { true } + set_cb = -> { true } subject.instance_variable_set(:@success_cb, set_cb) subject.verify_callbacks expect(subject.instance_variable_get(:@success_cb)).to eq(set_cb) diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index 585b3b05..ca6f08df 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -42,7 +42,7 @@ end context "when the given RPC method is implemented and a NoMethodError is raised" do - before { allow(rpc_service).to receive(:callable_rpc_method).and_return(lambda { rpc_service.__send__(:foo) }) } + before { allow(rpc_service).to receive(:callable_rpc_method).and_return(-> { rpc_service.__send__(:foo) }) } it "raises the exeception" do expect { subject.call(env) }.to raise_exception(NoMethodError) diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index caae7b43..b4830ab4 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -161,7 +161,7 @@ def verify_before context 'when "if" option is a callable that returns true' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :if => lambda { |_service| true }) + FilterTest.before_filter(:verify_before, :if => ->(_service) { true }) end it 'invokes the filter' do @@ -185,7 +185,7 @@ def verify_before context 'when "if" option is a callable that returns false' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :if => lambda { |_service| false }) + FilterTest.before_filter(:verify_before, :if => ->(_service) { false }) end it 'skips the filter' do @@ -229,7 +229,7 @@ def verify_before context 'when "unless" option is a callable that returns true' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :unless => lambda { |_service| false }) + FilterTest.before_filter(:verify_before, :unless => ->(_service) { false }) end it 'invokes the filter' do @@ -253,7 +253,7 @@ def verify_before context 'when "unless" option is a callable that returns false' do before do FilterTest.clear_filters! - FilterTest.before_filter(:verify_before, :unless => lambda { |_service| true }) + FilterTest.before_filter(:verify_before, :unless => ->(_service) { true }) end it 'skips the filter' do From e11737d306f53b90f0dbe80f85a36524da38e7fd Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Wed, 15 Oct 2014 14:42:25 -0700 Subject: [PATCH 141/298] Style/SpaceInsideBrackets --- .rubocop_todo.yml | 5 --- lib/protobuf.rb | 2 +- lib/protobuf/generators/base.rb | 2 +- .../generators/extension_generator.rb | 2 +- lib/protobuf/generators/field_generator.rb | 2 +- lib/protobuf/generators/file_generator.rb | 10 ++--- lib/protobuf/generators/group_generator.rb | 2 +- lib/protobuf/generators/message_generator.rb | 2 +- lib/protobuf/rpc/servers/zmq/broker.rb | 4 +- lib/protobuf/rpc/service_filters.rb | 4 +- lib/protobuf/tasks/compile.rake | 4 +- spec/lib/protobuf/cli_spec.rb | 28 +++++++------- spec/lib/protobuf/code_generator_spec.rb | 4 +- spec/lib/protobuf/enum_spec.rb | 4 +- spec/lib/protobuf/field/float_field_spec.rb | 2 +- spec/lib/protobuf/field/string_field_spec.rb | 4 +- spec/lib/protobuf/generators/base_spec.rb | 4 +- spec/lib/protobuf/message_spec.rb | 10 ++--- spec/lib/protobuf/rpc/service_filters_spec.rb | 38 +++++++++---------- 19 files changed, 64 insertions(+), 69 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 442f5ea3..66a5aaa5 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -71,11 +71,6 @@ Style/Next: Style/NumericLiterals: MinDigits: 21 -# Offense count: 126 -# Cop supports --auto-correct. -Style/SpaceInsideBrackets: - Enabled: false - # Offense count: 464 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf.rb b/lib/protobuf.rb index ca3c311c..4ee58bda 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -12,7 +12,7 @@ module Protobuf # See Protobuf#connector_type documentation. - CONNECTORS = [ :socket, :zmq ].freeze + CONNECTORS = [:socket, :zmq].freeze # Default is Socket as it has no external dependencies. DEFAULT_CONNECTOR = :socket diff --git a/lib/protobuf/generators/base.rb b/lib/protobuf/generators/base.rb index 800e63fe..e2f5ff5d 100644 --- a/lib/protobuf/generators/base.rb +++ b/lib/protobuf/generators/base.rb @@ -62,7 +62,7 @@ def to_s end def type_namespace - @type_namespace ||= @namespace + [ descriptor.name ] + @type_namespace ||= @namespace + [descriptor.name] end end diff --git a/lib/protobuf/generators/extension_generator.rb b/lib/protobuf/generators/extension_generator.rb index 36c5c581..632753ee 100644 --- a/lib/protobuf/generators/extension_generator.rb +++ b/lib/protobuf/generators/extension_generator.rb @@ -16,7 +16,7 @@ def compile print_class(@message_type, :message) do group = GroupGenerator.new(current_indent) group.add_extension_fields(@field_descriptors) - group.order = [ :extension_field ] + group.order = [:extension_field] print group.to_s end end diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 91684914..0c92bc4c 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -54,7 +54,7 @@ def extension? def compile run_once(:compile) do - field_definition = [ "#{label} #{type_name}", name, number, applicable_options ] + field_definition = ["#{label} #{type_name}", name, number, applicable_options] puts field_definition.flatten.compact.join(', ') end end diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index afeb5207..3a81e1f2 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -22,7 +22,7 @@ def file_name def compile run_once(:compile) do - map_extensions(descriptor, [ descriptor.package ]) + map_extensions(descriptor, [descriptor.package]) print_file_comment print_generic_requires @@ -30,9 +30,9 @@ def compile print_package do group = GroupGenerator.new(current_indent) - group.add_enums(descriptor.enum_type, :namespace => [ descriptor.package ]) + group.add_enums(descriptor.enum_type, :namespace => [descriptor.package]) group.add_message_declarations(descriptor.message_type) - group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [ descriptor.package ]) + group.add_messages(descriptor.message_type, :extension_fields => @extension_fields, :namespace => [descriptor.package]) group.add_extended_messages(unknown_extensions) group.add_services(descriptor.service) @@ -80,13 +80,13 @@ def map_extensions(descriptor, namespaces) if descriptor.respond_to_has_and_present?(:message_type) descriptor.message_type.each do |message_descriptor| - map_extensions(message_descriptor, (namespaces + [ message_descriptor.name ])) + map_extensions(message_descriptor, (namespaces + [message_descriptor.name])) end end if descriptor.respond_to_has_and_present?(:nested_type) descriptor.nested_type.each do |nested_descriptor| - map_extensions(nested_descriptor, (namespaces + [ nested_descriptor.name ])) + map_extensions(nested_descriptor, (namespaces + [nested_descriptor.name])) end end end diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index 8c6a90c3..ddff717f 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -18,7 +18,7 @@ def initialize(indent_level = 0) @comments = {} @handlers = {} @indent_level = indent_level - @order = [ :enum, :message_declaration, :message, :extended_message, :service ] + @order = [:enum, :message_declaration, :message, :extended_message, :service] init_printer(indent_level) end diff --git a/lib/protobuf/generators/message_generator.rb b/lib/protobuf/generators/message_generator.rb index c68b3ad0..6d7bba0c 100644 --- a/lib/protobuf/generators/message_generator.rb +++ b/lib/protobuf/generators/message_generator.rb @@ -52,7 +52,7 @@ def compile_message group.add_extension_fields(message_extension_fields) - group.order = [ :message, :field, :extension_range, :extension_field ] + group.order = [:message, :field, :extension_range, :extension_field] print group.to_s end end diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index 4f70fbb5..bd98ff32 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -141,9 +141,9 @@ def process_frontend end else if @idle_workers.empty? - local_queue << [address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ].concat(frames) + local_queue << [address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message].concat(frames) else - write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message ]).concat(frames)) + write_to_backend([@idle_workers.shift, ::Protobuf::Rpc::Zmq::EMPTY_STRING].concat([address, ::Protobuf::Rpc::Zmq::EMPTY_STRING, message]).concat(frames)) end end end diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index df09098e..b1413ef3 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -108,7 +108,7 @@ def invoke_filter?(rpc_method, filter) # Value should be a symbol/string or an array of symbols/strings. # def invoke_via_except?(rpc_method, filter) - except = [ filter.fetch(:except) { [] } ].flatten + except = [filter.fetch(:except) { [] }].flatten except.empty? || !except.include?(rpc_method) end @@ -138,7 +138,7 @@ def invoke_via_if?(_rpc_method, filter) # Value should be a symbol/string or an array of symbols/strings. # def invoke_via_only?(rpc_method, filter) - only = [ filter.fetch(:only) { [] } ].flatten + only = [filter.fetch(:only) { [] }].flatten only.empty? || only.include?(rpc_method) end diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index 603a3efc..cd46e3ab 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -3,7 +3,7 @@ require 'fileutils' namespace :protobuf do desc 'Clean & Compile the protobuf source to ruby classes. Pass PB_NO_CLEAN=1 if you do not want to force-clean first.' - task :compile, [ :package, :source, :destination, :plugin, :file_extension ] do |_tasks, args| + task :compile, [:package, :source, :destination, :plugin, :file_extension] do |_tasks, args| args.with_defaults(:destination => 'lib') args.with_defaults(:source => 'definitions') args.with_defaults(:plugin => 'ruby') @@ -27,7 +27,7 @@ namespace :protobuf do end desc 'Clean the generated *.pb.rb files from the destination package. Pass PB_FORCE_CLEAN=1 to skip confirmation step.' - task :clean, [ :package, :destination, :file_extension ] do |_task, args| + task :clean, [:package, :destination, :file_extension] do |_task, args| args.with_defaults(:destination => 'lib') args.with_defaults(:file_extension => '.pb.rb') diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index b1767bf7..b0bcb5af 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -31,12 +31,12 @@ end describe '#start' do - let(:base_args) { [ 'start', app_file ] } + let(:base_args) { ['start', app_file] } let(:test_args) { [] } let(:args) { base_args + test_args } context 'host option' do - let(:test_args) { [ '--host=123.123.123.123' ] } + let(:test_args) { ['--host=123.123.123.123'] } it 'sends the host option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -47,7 +47,7 @@ end context 'port option' do - let(:test_args) { [ '--port=12345' ] } + let(:test_args) { ['--port=12345'] } it 'sends the port option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -58,7 +58,7 @@ end context 'threads option' do - let(:test_args) { [ '--threads=500' ] } + let(:test_args) { ['--threads=500'] } it 'sends the threads option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -69,7 +69,7 @@ end context 'backlog option' do - let(:test_args) { [ '--backlog=500' ] } + let(:test_args) { ['--backlog=500'] } it 'sends the backlog option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -80,7 +80,7 @@ end context 'threshold option' do - let(:test_args) { [ '--threshold=500' ] } + let(:test_args) { ['--threshold=500'] } it 'sends the backlog option to the runner' do expect(::Protobuf::Rpc::SocketRunner).to receive(:new) do |options| @@ -91,7 +91,7 @@ end context 'log options' do - let(:test_args) { [ '--log=mylog.log', '--level=0' ] } + let(:test_args) { ['--log=mylog.log', '--level=0'] } it 'sends the log file and level options to the runner' do expect(::Protobuf::Logging).to receive(:initialize_logger) do |file, level| @@ -115,7 +115,7 @@ unless defined?(JRUBY_VERSION) context 'request pausing' do - let(:test_args) { [ '--gc_pause_request' ] } + let(:test_args) { ['--gc_pause_request'] } it 'sets the configuration option to GC pause server request' do described_class.start(args) @@ -150,7 +150,7 @@ end context 'when enabled' do - let(:test_args) { [ '--print_deprecation_warnings' ] } + let(:test_args) { ['--print_deprecation_warnings'] } it 'sets the deprecation warning flag to true' do described_class.start(args) @@ -159,7 +159,7 @@ end context 'when disabled' do - let(:test_args) { [ '--no-print_deprecation_warnings' ] } + let(:test_args) { ['--no-print_deprecation_warnings'] } it 'sets the deprecation warning flag to false' do described_class.start(args) @@ -171,7 +171,7 @@ context 'run modes' do context 'socket' do - let(:test_args) { [ '--socket' ] } + let(:test_args) { ['--socket'] } let(:runner) { ::Protobuf::Rpc::SocketRunner } before do @@ -197,7 +197,7 @@ end context 'zmq workers only' do - let(:test_args) { [ '--workers_only', '--zmq' ] } + let(:test_args) { ['--workers_only', '--zmq'] } let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do @@ -224,7 +224,7 @@ end context 'zmq worker port' do - let(:test_args) { [ '--worker_port=1234', '--zmq' ] } + let(:test_args) { ['--worker_port=1234', '--zmq'] } let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do @@ -241,7 +241,7 @@ end context 'zmq' do - let(:test_args) { [ '--zmq' ] } + let(:test_args) { ['--zmq'] } let(:runner) { ::Protobuf::Rpc::ZmqRunner } before do diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 956d05ae..b41849d2 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -19,11 +19,11 @@ let(:file_generator2) { double('file generator 2', :generate_output_file => output_file2) } let(:request_bytes) do - COMPILER::CodeGeneratorRequest.encode(:proto_file => [ input_file1, input_file2 ]) + COMPILER::CodeGeneratorRequest.encode(:proto_file => [input_file1, input_file2]) end let(:expected_response_bytes) do - COMPILER::CodeGeneratorResponse.encode(:file => [ output_file1, output_file2 ]) + COMPILER::CodeGeneratorResponse.encode(:file => [output_file1, output_file2]) end before do diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 55a73602..036693a9 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -71,8 +71,8 @@ describe '.enums_for_tag' do it 'returns an array of Enums for the given tag, if any' do - expect(EnumAliasTest.enums_for_tag(1)).to eq([ EnumAliasTest::FOO, EnumAliasTest::BAR ]) - expect(EnumAliasTest.enums_for_tag(2)).to eq([ EnumAliasTest::BAZ ]) + expect(EnumAliasTest.enums_for_tag(1)).to eq([EnumAliasTest::FOO, EnumAliasTest::BAR]) + expect(EnumAliasTest.enums_for_tag(2)).to eq([EnumAliasTest::BAZ]) expect(EnumAliasTest.enums_for_tag(3)).to eq([]) end end diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb index 835885c0..7bda8a33 100644 --- a/spec/lib/protobuf/field/float_field_spec.rb +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -44,7 +44,7 @@ class SomeFloatMessage < ::Protobuf::Message end context 'when set with something that is not a float' do - let(:value) { [ 1, 2, 3 ] } + let(:value) { [1, 2, 3] } it 'throws an error' do expect { subject }.to raise_error(TypeError) diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index f1ad1a7e..24318531 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -8,7 +8,7 @@ context 'when a repeated string field contains frozen strings' do it 'does not raise an encoding error' do expect do - frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] + frozen_strings = ["foo".freeze, "bar".freeze, "baz".freeze] ::Test::ResourceFindRequest.encode(:name => 'resource', :widgets => frozen_strings) end.not_to raise_error end @@ -17,7 +17,7 @@ context 'when a repeated bytes field contains frozen strings' do it 'does not raise an encoding error' do expect do - frozen_strings = [ "foo".freeze, "bar".freeze, "baz".freeze ] + frozen_strings = ["foo".freeze, "bar".freeze, "baz".freeze] ::Test::ResourceFindRequest.encode(:name => 'resource', :widget_bytes => frozen_strings) end.not_to raise_error end diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 0162b1b2..82ffd269 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -9,8 +9,8 @@ context 'namespaces' do let(:descriptor) { double(:name => 'Baz') } - subject { described_class.new(descriptor, 0, :namespace => [ :foo, :bar ]) } - specify { expect(subject.type_namespace).to eq([ :foo, :bar, 'Baz' ]) } + subject { described_class.new(descriptor, 0, :namespace => [:foo, :bar]) } + specify { expect(subject.type_namespace).to eq([:foo, :bar, 'Baz']) } specify { expect(subject.fully_qualified_type_namespace).to eq('.foo.bar.Baz') } end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 56012dd6..d8e6fd90 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -54,18 +54,18 @@ context 'with a repeated field' do it 'treats the field as if it was unset when decoding' do - newer = newer_message.new(:enum_list => [ :HOORAY ]).serialize + newer = newer_message.new(:enum_list => [:HOORAY]).serialize expect(older_message.decode(newer).enum_list).to eq([]) end it 'rejects an unknown value when using the constructor' do - expect { older_message.new(:enum_list => [ :HOORAY ]) }.to raise_error + expect { older_message.new(:enum_list => [:HOORAY]) }.to raise_error end it 'rejects an unknown value when the setter' do older = older_message.new - expect { older.enum_field = [ :HOORAY ] }.to raise_error + expect { older.enum_field = [:HOORAY] }.to raise_error end end end @@ -372,8 +372,8 @@ end it 'converts repeated enum fields to an array of the tags' do - hash = Test::EnumTestMessage.new(:repeated_enums => [ :ONE, :TWO, :TWO, :ONE ]).to_hash - expect(hash).to eq(:repeated_enums => [ 1, 2, 2, 1 ]) + hash = Test::EnumTestMessage.new(:repeated_enums => [:ONE, :TWO, :TWO, :ONE]).to_hash + expect(hash).to eq(:repeated_enums => [1, 2, 2, 1]) end end diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index b4830ab4..ebedd21b 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -61,7 +61,7 @@ def foo it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :foo, :endpoint ] + expect(subject.called).to eq [:verify_before, :foo, :endpoint] expect(subject.before_filter_calls).to eq 1 end @@ -84,14 +84,14 @@ def endpoint_with_verify context 'when invoking a method defined in "only" option' do it 'invokes the filter' do subject.__send__(:run_filters, :endpoint_with_verify) - expect(subject.called).to eq [ :verify_before, :endpoint_with_verify ] + expect(subject.called).to eq [:verify_before, :endpoint_with_verify] end end context 'when invoking a method not defined by "only" option' do it 'does not invoke the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end end @@ -115,14 +115,14 @@ def endpoint_without_verify context 'when invoking a method not defined in "except" option' do it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end context 'when invoking a method defined by "except" option' do it 'does not invoke the filter' do subject.__send__(:run_filters, :endpoint_without_verify) - expect(subject.called).to eq [ :endpoint_without_verify ] + expect(subject.called).to eq [:endpoint_without_verify] end end end @@ -154,7 +154,7 @@ def verify_before it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end @@ -166,7 +166,7 @@ def verify_before it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end @@ -178,7 +178,7 @@ def verify_before it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end @@ -190,7 +190,7 @@ def verify_before it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end end @@ -222,7 +222,7 @@ def verify_before it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end @@ -234,7 +234,7 @@ def verify_before it 'invokes the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :verify_before, :endpoint ] + expect(subject.called).to eq [:verify_before, :endpoint] end end @@ -246,7 +246,7 @@ def verify_before it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end @@ -258,7 +258,7 @@ def verify_before it 'skips the filter' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint ] + expect(subject.called).to eq [:endpoint] end end end @@ -283,7 +283,7 @@ def short_circuit_filter it 'does not invoke the rpc method' do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :short_circuit_filter ] + expect(subject.called).to eq [:short_circuit_filter] end end end @@ -317,7 +317,7 @@ def foo it 'calls filters in the order they were defined' do subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq [ :endpoint, :verify_after, :foo ] + expect(subject.called).to eq [:endpoint, :verify_after, :foo] expect(subject.after_filter_calls).to eq 1 end end @@ -447,7 +447,7 @@ def custom_error_occurred(ex) expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :filter_with_error3, :custom_error_occurred ]) + expect(subject.called).to eq([:filter_with_error3, :custom_error_occurred]) expect(subject.ex_class).to eq CustomError3 end.not_to raise_error end @@ -468,7 +468,7 @@ def custom_error_occurred(ex) expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :filter_with_error1, :custom_error_occurred ]) + expect(subject.called).to eq([:filter_with_error1, :custom_error_occurred]) expect(subject.ex_class).to eq CustomError1 end.not_to raise_error end @@ -488,7 +488,7 @@ def custom_error_occurred(ex) expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :filter_with_error1, :block_rescue_handler ]) + expect(subject.called).to eq([:filter_with_error1, :block_rescue_handler]) expect(subject.ex_class).to eq CustomError1 end.not_to raise_error end @@ -507,7 +507,7 @@ def custom_error_occurred(ex) expect do expect(subject).not_to receive(:endpoint) subject.__send__(:run_filters, :endpoint) - expect(subject.called).to eq([ :filter_with_runtime_error, :standard_error_rescue_handler ]) + expect(subject.called).to eq([:filter_with_runtime_error, :standard_error_rescue_handler]) expect(subject.ex_class).to eq RuntimeError end.not_to raise_error end From aa2daa230114995eab59c87ba533d7f20726c6a5 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 27 Oct 2014 16:41:33 -0700 Subject: [PATCH 142/298] `int` is not a protobuf primitive --- lib/protobuf/message.rb | 2 +- spec/lib/protobuf/message_spec.rb | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 5076d0d9..788f92b6 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -90,7 +90,7 @@ def field?(name) def inspect attrs = self.class.fields.map do |field| - [ field.name, send(field.name).inspect ].join('=') + [field.name, send(field.name).inspect].join('=') end.join(' ') "#<#{self.class} #{attrs}>" diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 83f99e17..b8e1da86 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -363,15 +363,15 @@ let(:klass) do Class.new(Protobuf::Message) do optional :string, :name, 1 - repeated :int, :counts, 2 - optional :int, :timestamp, 2 + repeated :int32, :counts, 2 + optional :int32, :timestamp, 3 end end before { stub_const('MyMessage', klass) } it 'lists the fields' do - proto = klass.new(:name => 'wooo', :counts => [ 1, 2, 3 ]) + proto = klass.new(:name => 'wooo', :counts => [1, 2, 3]) expect(proto.inspect).to eq \ '#' end From b17aaae0c529712b8b7b1537b11fcbc6e2560ea3 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 09:28:34 -0800 Subject: [PATCH 143/298] Make the tests pass --- lib/protobuf/cli.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 592d7f09..222a55de 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -235,8 +235,6 @@ def start_server end logger.info { 'Shutdown complete' } - - exit 0 end end end From e7081e7cc595e00c409cf15fbe441db3fd12e2dc Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 09:45:09 -0800 Subject: [PATCH 144/298] Update autogenerated RuboCop config --- .rubocop_todo.yml | 49 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 39 insertions(+), 10 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 66a5aaa5..600b1fc8 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,15 +1,19 @@ # This configuration was generated by `rubocop --auto-gen-config` -# on 2014-10-15 12:57:34 -0700 using RuboCop version 0.26.1. +# on 2014-11-24 09:44:26 -0800 using RuboCop version 0.27.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 28 +Metrics/AbcSize: + Max: 59 + # Offense count: 3 Metrics/BlockNesting: Max: 5 -# Offense count: 8 +# Offense count: 9 # Configuration parameters: CountComments. Metrics/ClassLength: Max: 233 @@ -18,12 +22,12 @@ Metrics/ClassLength: Metrics/CyclomaticComplexity: Max: 11 -# Offense count: 505 +# Offense count: 508 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 196 -# Offense count: 47 +# Offense count: 48 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 45 @@ -37,7 +41,7 @@ Metrics/ParameterLists: Metrics/PerceivedComplexity: Max: 12 -# Offense count: 191 +# Offense count: 216 Style/Documentation: Enabled: false @@ -45,28 +49,46 @@ Style/Documentation: Style/DoubleNegation: Enabled: false -# Offense count: 146 +# Offense count: 100 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/EmptyLinesAroundClassBody: + Enabled: false + +# Offense count: 1 # Cop supports --auto-correct. -Style/EmptyLinesAroundBody: +Style/EmptyLinesAroundMethodBody: + Enabled: false + +# Offense count: 66 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/EmptyLinesAroundModuleBody: Enabled: false -# Offense count: 20 +# Offense count: 18 # Configuration parameters: MinBodyLength. Style/GuardClause: Enabled: false -# Offense count: 672 +# Offense count: 690 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/HashSyntax: Enabled: false +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/MultilineOperationIndentation: + Enabled: false + # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: Enabled: false -# Offense count: 46 +# Offense count: 53 # Cop supports --auto-correct. Style/NumericLiterals: MinDigits: 21 @@ -77,7 +99,14 @@ Style/NumericLiterals: Style/StringLiterals: Enabled: false +# Offense count: 1 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/StringLiteralsInInterpolation: + Enabled: false + # Offense count: 4 # Cop supports --auto-correct. +# Configuration parameters: WordRegex. Style/WordArray: MinSize: 2 From 1172fdd84198503b3eb56f945579225fb78801bb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 15:17:19 -0800 Subject: [PATCH 145/298] Force exit after rpc_server does its thing --- bin/rpc_server | 1 + 1 file changed, 1 insertion(+) diff --git a/bin/rpc_server b/bin/rpc_server index 18d8724b..7aed6c92 100755 --- a/bin/rpc_server +++ b/bin/rpc_server @@ -2,3 +2,4 @@ require 'protobuf/cli' ::Protobuf::CLI.start(ARGV) +exit From 2310e59145564905afc6d2cc4b394cdc67e6b3fb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 30 Sep 2014 08:46:30 -0700 Subject: [PATCH 146/298] Remove uses of class_eval --- lib/protobuf/deprecator.rb | 30 ++++++++---------------------- lib/protobuf/message/fields.rb | 8 +++----- lib/protobuf/rpc/env.rb | 22 +++++++++++----------- 3 files changed, 22 insertions(+), 38 deletions(-) diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb index 68167378..b7333324 100644 --- a/lib/protobuf/deprecator.rb +++ b/lib/protobuf/deprecator.rb @@ -9,33 +9,19 @@ def warn_deprecated(old_method, new_method) # Given deprecations should be a hash whose keys are the new methods # and values are a list of deprecated methods that should send to t def deprecate_method(old_method, new_method) - class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) - def #{old_method}(*args) - self.class.warn_deprecated("#{old_method}", "#{new_method}") - new_meth = method("#{new_method}") - if new_meth.arity == 0 - __send__("#{new_method}") - else - __send__("#{new_method}", *args) - end - end - DEPRECATED + define_method old_method do |*args| + self.class.warn_deprecated(old_method, new_method) + public_send(new_method, *args) + end end # Given deprecations should be a hash whose keys are the new methods # and values are a list of deprecated methods that should send to t def deprecate_class_method(old_method, new_method) - class_eval(<<-DEPRECATED, __FILE__, __LINE__ + 1) - def self.#{old_method}(*args) - warn_deprecated("#{old_method}", "#{new_method}") - new_meth = method("#{new_method}") - if new_meth.arity == 0 - __send__("#{new_method}") - else - __send__("#{new_method}", *args) - end - end - DEPRECATED + define_singleton_method old_method do |*args| + warn_deprecated(old_method, new_method) + public_send(new_method, *args) + end end end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 234c0dfa..808e7393 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -97,11 +97,9 @@ def define_field(rule, type_class, field_name, tag, options) field_store[field_name] = field field_store[tag] = field - class_eval(<<-RAW_GETTER, __FILE__, __LINE__ + 1) - define_method("#{field_name}!") do - @values[:#{field_name}] - end - RAW_GETTER + define_method("#{field_name}!") do + @values[field_name] + end end def raise_if_tag_collision(tag, field_name) diff --git a/lib/protobuf/rpc/env.rb b/lib/protobuf/rpc/env.rb index c719cadf..f89b2a1e 100644 --- a/lib/protobuf/rpc/env.rb +++ b/lib/protobuf/rpc/env.rb @@ -16,19 +16,19 @@ class Env < Hash # def self.hash_accessor(*names) #:nodoc: names.each do |name| - class_eval <<-METHOD, __FILE__, __LINE__ + 1 - def #{name} - self['#{name}'] - end + name_str = name.to_s.freeze - def #{name}=(value) - self['#{name}'] = value - end + define_method name do + self[name_str] + end - def #{name}? - ! self['#{name}'].nil? - end - METHOD + define_method "#{name}=" do |value| + self[name_str] = value + end + + define_method "#{name}?" do + !self[name_str].nil? + end end end From d5b713b039baf4dcd07fc65920e51da25fd1008c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 10:16:31 -0700 Subject: [PATCH 147/298] add backtrace output to logger when SIGTRAP --- lib/protobuf/rpc/servers/zmq_runner.rb | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 5d213640..e4e5eaf7 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -1,4 +1,5 @@ require 'ostruct' +require 'thread' module Protobuf module Rpc @@ -36,6 +37,17 @@ def stop private def register_signals + trap(:TRAP) do + ::Thread.list.each do |thread| + logger.info do + <<-THREAD_TRACE + #{thread.inspect}: + #{thread.backtrace.join($/)}" + THREAD_TRACE + end + end + end + trap(:TTIN) do @server.add_worker logger.info { "Increased worker size to: #{@server.total_workers}" } @@ -43,7 +55,7 @@ def register_signals trap(:TTOU) do logger.info { "Current worker size: #{@server.workers.size}" } - logger.info { "Current worker size: #{@server.busy_worker_count}" } + logger.info { "Current busy worker size: #{@server.busy_worker_count}" } end end end From 903c630e05618a6f8fcbe34e76bf2c06a5fc873d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 10:42:11 -0700 Subject: [PATCH 148/298] extract the socket availability check for zmq connector --- lib/protobuf/rpc/connectors/zmq.rb | 38 +++++++++++++++--------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 8ed87637..ac13efa2 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -82,25 +82,7 @@ def create_socket if socket # Make sure the context builds the socket socket.setsockopt(::ZMQ::LINGER, 0) zmq_error_check(socket.connect(server_uri), :socket_connect) - - if first_alive_load_balance? - begin - check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) - socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) - zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) - zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) - - if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE - zmq_recoverable_error_check(socket.close, :socket_close) - end - rescue ZmqRecoverableError - socket = nil # couldn't make a connection and need to try again - else - socket.setsockopt(::ZMQ::RCVTIMEO, -1) - socket.setsockopt(::ZMQ::SNDTIMEO, -1) - end - end + socket = socket_to_available_server(socket) if first_alive_load_balance? end end while socket.try(:socket).nil? @@ -189,6 +171,24 @@ def send_request_with_lazy_pirate end end + def socket_to_available_server(socket) + check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) + socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) + zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_recoverable_error_check(socket.close, :socket_close) + end + + socket.setsockopt(::ZMQ::RCVTIMEO, -1) + socket.setsockopt(::ZMQ::SNDTIMEO, -1) + socket + rescue ZmqRecoverableError + return nil # couldn't make a connection and need to try again + end + def rcv_timeout @rcv_timeout ||= begin case From ef72415dbedd980edf279f349aec6b0a48d95ba0 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 10:48:40 -0700 Subject: [PATCH 149/298] set socket before begin block --- lib/protobuf/rpc/connectors/zmq.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index ac13efa2..dc86de6b 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -75,6 +75,8 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket + socket = nil + begin server_uri = lookup_server_uri socket = zmq_context.socket(::ZMQ::REQ) From 73f58e784d791b4085eb92b771ad31f96640211f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:01:22 -0700 Subject: [PATCH 150/298] alpha the methods in zmq connector --- lib/protobuf/rpc/connectors/zmq.rb | 145 ++++++++++++++--------------- 1 file changed, 72 insertions(+), 73 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index dc86de6b..b4b2fa46 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -24,6 +24,10 @@ class Zmq < Base ## # Class Methods # + def self.ping_port_responses + @ping_port_responses ||= ::ThreadSafe::Cache.new + end + def self.zmq_context @zmq_contexts ||= Hash.new do |hash, key| hash[key] = ZMQ::Context.new @@ -32,13 +36,12 @@ def self.zmq_context @zmq_contexts[Process.pid] end - def self.ping_port_responses - @ping_port_responses ||= ::ThreadSafe::Cache.new - end - ## # Instance methods # + def log_signature + @_log_signature ||= "[client-#{self.class}]" + end # Start the request/response cycle. We implement the Lazy Pirate # req/reply reliability pattern as laid out in the ZMQ Guide, Chapter 4. @@ -50,10 +53,6 @@ def send_request send_request_with_lazy_pirate unless error? end - def log_signature - @_log_signature ||= "[client-#{self.class}]" - end - private ## @@ -97,6 +96,27 @@ def error? !! @error end + def host_alive?(host) + return true unless ping_port_enabled? + + if (last_response = self.class.ping_port_responses[host]) + if (Time.now.to_i - last_response[:at]) <= host_alive_check_interval + return last_response[:ping_port_open] + end + end + + ping_port_open = ping_port_open?(host) + self.class.ping_port_responses[host] = { + :at => Time.now.to_i, + :ping_port_open => ping_port_open, + } + ping_port_open + end + + def host_alive_check_interval + @host_alive_check_interval ||= [ENV["PB_ZMQ_CLIENT_HOST_ALIVE_CHECK_INTERVAL"].to_i, 1].max + end + # Lookup a server uri for the requested service in the service # directory. If the service directory is not running, default # to the host and port in the options @@ -119,27 +139,6 @@ def lookup_server_uri fail "Host not found for service #{service}" end - def host_alive?(host) - return true unless ping_port_enabled? - - if (last_response = self.class.ping_port_responses[host]) - if (Time.now.to_i - last_response[:at]) <= host_alive_check_interval - return last_response[:ping_port_open] - end - end - - ping_port_open = ping_port_open?(host) - self.class.ping_port_responses[host] = { - :at => Time.now.to_i, - :ping_port_open => ping_port_open, - } - ping_port_open - end - - def host_alive_check_interval - @host_alive_check_interval ||= [ENV["PB_ZMQ_CLIENT_HOST_ALIVE_CHECK_INTERVAL"].to_i, 1].max - end - def ping_port_open?(host) socket = TCPSocket.new(host, ping_port.to_i) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) @@ -156,6 +155,19 @@ def ping_port_open?(host) end end + def rcv_timeout + @rcv_timeout ||= begin + case + when options[:timeout] then + options[:timeout] + when ENV.key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then + ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i + else + 300_000 # 300 seconds + end + end + end + # Trying a number of times, attempt to get a response from the server. # If we haven't received a legitimate response in the CLIENT_RETRIES number # of retries, fail the request. @@ -173,50 +185,6 @@ def send_request_with_lazy_pirate end end - def socket_to_available_server(socket) - check_available_response = "" - socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) - socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) - zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) - zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) - - if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE - zmq_recoverable_error_check(socket.close, :socket_close) - end - - socket.setsockopt(::ZMQ::RCVTIMEO, -1) - socket.setsockopt(::ZMQ::SNDTIMEO, -1) - socket - rescue ZmqRecoverableError - return nil # couldn't make a connection and need to try again - end - - def rcv_timeout - @rcv_timeout ||= begin - case - when options[:timeout] then - options[:timeout] - when ENV.key?("PB_ZMQ_CLIENT_RCV_TIMEOUT") then - ENV["PB_ZMQ_CLIENT_RCV_TIMEOUT"].to_i - else - 300_000 # 300 seconds - end - end - end - - def snd_timeout - @snd_timeout ||= begin - case - when options[:timeout] then - options[:timeout] - when ENV.key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then - ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i - else - 300_000 # 300 seconds - end - end - end - def send_request_with_timeout(attempt = 0) socket = create_socket socket.setsockopt(::ZMQ::RCVTIMEO, rcv_timeout) @@ -251,6 +219,37 @@ def service_directory ::Protobuf::Rpc::ServiceDirectory.instance end + def snd_timeout + @snd_timeout ||= begin + case + when options[:timeout] then + options[:timeout] + when ENV.key?("PB_ZMQ_CLIENT_SND_TIMEOUT") then + ENV["PB_ZMQ_CLIENT_SND_TIMEOUT"].to_i + else + 300_000 # 300 seconds + end + end + end + + def socket_to_available_server(socket) + check_available_response = "" + socket.setsockopt(::ZMQ::RCVTIMEO, check_available_rcv_timeout) + socket.setsockopt(::ZMQ::SNDTIMEO, check_available_snd_timeout) + zmq_recoverable_error_check(socket.send_string(::Protobuf::Rpc::Zmq::CHECK_AVAILABLE_MESSAGE), :socket_send_string) + zmq_recoverable_error_check(socket.recv_string(check_available_response), :socket_recv_string) + + if check_available_response == ::Protobuf::Rpc::Zmq::NO_WORKERS_AVAILABLE + zmq_recoverable_error_check(socket.close, :socket_close) + end + + socket.setsockopt(::ZMQ::RCVTIMEO, -1) + socket.setsockopt(::ZMQ::SNDTIMEO, -1) + socket + rescue ZmqRecoverableError + return nil # couldn't make a connection and need to try again + end + # Return the ZMQ Context to use for this process. # If the context does not exist, create it, then register # an exit block to ensure the context is terminated correctly. From 33d2800e798aca3f556b1cb19af596ed34776fec Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:07:50 -0700 Subject: [PATCH 151/298] cause tap is weird --- lib/protobuf/message/serialization.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 22457b96..5850b5a6 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -44,10 +44,10 @@ def decode_from(stream) # Encode this message # def encode - ::StringIO.new.tap do |stream| - stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream) - end.string + stream = ::StringIO.new + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + stream.string end # Encode this message to the given stream. From b5333fdce5b0ea80bb1d1df8973b507583a0ce11 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:21:01 -0700 Subject: [PATCH 152/298] use any? instead of reduce --- lib/protobuf/rpc/connectors/common.rb | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index dd02b34f..f881fd27 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -8,9 +8,7 @@ module Common attr_reader :error def any_callbacks? - [@complete_cb, @failure_cb, @success_cb].reduce(false) do |reduction, cb| - reduction || !cb.nil? - end + [@complete_cb, @failure_cb, @success_cb].any? end def request_caller From dc863f82ae85acf9690b58e9a2b464897241caa4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:37:28 -0700 Subject: [PATCH 153/298] use $INPUT_RECORD_SEPARATOR and alpha methods --- lib/protobuf/rpc/servers/zmq/server.rb | 8 ++++---- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 87f663cb..c6fe5927 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -216,10 +216,6 @@ def teardown @last_reaping = @last_beacon = @timeout = nil end - def total_workers - @total_workers ||= [@options[:threads].to_i, 1].max - end - def timeout if @timeout.nil? @timeout = 0 @@ -228,6 +224,10 @@ def timeout end end + def total_workers + @total_workers ||= [@options[:threads].to_i, 1].max + end + def to_proto @proto ||= ::Protobuf::Rpc::DynamicDiscovery::Server.new( :uuid => uuid, diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index e4e5eaf7..e3396861 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -42,7 +42,7 @@ def register_signals logger.info do <<-THREAD_TRACE #{thread.inspect}: - #{thread.backtrace.join($/)}" + #{thread.backtrace.join($INPUT_RECORD_SEPARATOR)}" THREAD_TRACE end end From b48615dde30b63911b4687a8ae52ab52b9e3104b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 11:53:39 -0700 Subject: [PATCH 154/298] elevate broker polling milliseconds to env var --- lib/protobuf/rpc/servers/zmq/broker.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index aab79929..abb2ccad 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -26,7 +26,7 @@ def run loop do process_local_queue - rc = @poller.poll(500) + rc = @poller.poll(broker_polling_milliseconds) # The server was shutdown and no requests are pending break if rc == 0 && !running? && @server.workers.empty? @@ -51,6 +51,10 @@ def backend_poll_weight @backend_poll_weight ||= [ENV["PB_ZMQ_SERVER_BACKEND_POLL_WEIGHT"].to_i, 1].max end + def broker_polling_milliseconds + @broker_polling_milliseconds ||= [ENV["PB_ZMQ_BROKER_POLLING_MILLISECONDS"].to_i, 500].max + end + def check_and_process_backend readables_include_backend = @poller.readables.include?(@backend_socket) message_count_read_from_backend = 0 From 964ee36ecf309754c2123e638def1444e412d8f9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 14:29:27 -0700 Subject: [PATCH 155/298] check options before checking worker count --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index c6fe5927..993eecad 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -252,7 +252,7 @@ def wait_for_shutdown_signal end if broadcast_heartbeat? - if all_workers_busy? && options[:broadcast_busy] + if options[:broadcast_busy] && all_workers_busy? broadcast_flatline else broadcast_heartbeat From 8528015c72e2efcb54476c39ae3269587139e383 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 28 Nov 2014 14:40:53 -0700 Subject: [PATCH 156/298] set the server for logging/stats that is chosen in zmq host_live choice so all log lines are not the same --- lib/protobuf/rpc/connectors/zmq.rb | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index b4b2fa46..027c2ccf 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -126,12 +126,21 @@ def lookup_server_uri service_directory.all_listings_for(service).each do |listing| host = listing.try(:address) port = listing.try(:port) - return "tcp://#{host}:#{port}" if host_alive?(host) + + if host_alive?(host) + # @stats from Common, need to get a better public interface for it + @stats.server = [port, host] + return "tcp://#{host}:#{port}" + end end host = options[:host] port = options[:port] - return "tcp://#{host}:#{port}" if host_alive?(host) + + if host_alive?(host) + @stats.server = [port, host] + return "tcp://#{host}:#{port}" + end sleep(1.0 / 100.0) end From 1e68d79eebaa54814f7303e516c107f375ab29a2 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 30 Nov 2014 16:07:19 -0700 Subject: [PATCH 157/298] initialize the @stats in the initialize method and fix rubycop warnings --- lib/protobuf/rpc/connectors/base.rb | 1 + lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/connectors/zmq.rb | 8 +++----- 3 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/rpc/connectors/base.rb b/lib/protobuf/rpc/connectors/base.rb index 8f6d43c5..b2b0c98c 100644 --- a/lib/protobuf/rpc/connectors/base.rb +++ b/lib/protobuf/rpc/connectors/base.rb @@ -30,6 +30,7 @@ class Base def initialize(options) @options = DEFAULT_OPTIONS.merge(options) + @stats = ::Protobuf::Rpc::Stat.new(:CLIENT) end def first_alive_load_balance? diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index f881fd27..9d43dd17 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -52,7 +52,7 @@ def failure(code, message) end def initialize_stats - @stats = Protobuf::Rpc::Stat.new(:CLIENT) + @stats ||= ::Protobuf::Rpc::Stat.new(:CLIENT) @stats.server = [@options[:port], @options[:host]] @stats.service = @options[:service].name @stats.method_name = @options[:method].to_s diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 027c2ccf..422ef8b9 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -74,13 +74,11 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket - socket = nil + socket = zmq_context.socket(::ZMQ::REQ) begin - server_uri = lookup_server_uri - socket = zmq_context.socket(::ZMQ::REQ) - if socket # Make sure the context builds the socket + server_uri = lookup_server_uri socket.setsockopt(::ZMQ::LINGER, 0) zmq_error_check(socket.connect(server_uri), :socket_connect) socket = socket_to_available_server(socket) if first_alive_load_balance? @@ -258,7 +256,7 @@ def socket_to_available_server(socket) rescue ZmqRecoverableError return nil # couldn't make a connection and need to try again end - + # Return the ZMQ Context to use for this process. # If the context does not exist, create it, then register # an exit block to ensure the context is terminated correctly. From 1caaa6e3aa1b583fc67b163519d0954ea28b47d5 Mon Sep 17 00:00:00 2001 From: John Crepezzi Date: Tue, 28 Oct 2014 11:14:14 -0400 Subject: [PATCH 158/298] Test enum inspect display, and fix the failing test --- spec/lib/protobuf/message_spec.rb | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index b8e1da86..48458e95 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -362,18 +362,22 @@ describe '#inspect' do let(:klass) do Class.new(Protobuf::Message) do + EnumKlass = Class.new(Protobuf::Enum) do + define :YAY, 1 + end + optional :string, :name, 1 repeated :int32, :counts, 2 - optional :int32, :timestamp, 3 + optional EnumKlass, :enum, 3 end end before { stub_const('MyMessage', klass) } it 'lists the fields' do - proto = klass.new(:name => 'wooo', :counts => [1, 2, 3]) + proto = klass.new(:name => 'wooo', :counts => [1, 2, 3], :enum => klass::EnumKlass::YAY) expect(proto.inspect).to eq \ - '#' + '#>' end end From afa32a9f3dfe5c4f043a7e568a7671dcdf162497 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 14:49:44 -0800 Subject: [PATCH 159/298] DRY class methods --- lib/protobuf/lifecycle.rb | 63 +++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index fd688820..74f09ea9 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -1,46 +1,39 @@ module Protobuf class Lifecycle - include ::Protobuf::Logging + class << self + def register(event_name, &blk) + fail "Lifecycle register must have a block" unless block_given? + event_name = normalized_event_name(event_name) + + if ::Protobuf.print_deprecation_warnings? + $stderr.puts <<-ERROR + [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. + Use ::ActiveSupport::Notifications.subscribe('#{event_name}') + ERROR + end + + ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| + blk.call(*args) + end + end + alias_method :on, :register - def self.register(event_name, &blk) - fail "Lifecycle register must have a block" unless block_given? - event_name = normalized_event_name(event_name) + def trigger(event_name, *args) + if ::Protobuf.print_deprecation_warnings? + $stderr.puts <<-ERROR + [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. + Use ::ActiveSupport::Notifications.instrument(...) + ERROR + end - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. - Use ::ActiveSupport::Notifications.subscribe('#{event_name}') - ERROR - end + event_name = normalized_event_name(event_name) - ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| - blk.call(*args) + ::ActiveSupport::Notifications.instrument(event_name, args) end - end - def self.trigger(event_name, *args) - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. - Use ::ActiveSupport::Notifications.instrument(...) - ERROR + def normalized_event_name(event_name) + "#{event_name}".downcase end - - event_name = normalized_event_name(event_name) - - ::ActiveSupport::Notifications.instrument(event_name, args) end - - def self.normalized_event_name(event_name) - "#{event_name}".downcase - end - - class << self - attr_accessor :lifecycle_events - - alias_method :on, :register - end - - @lifecycle_events ||= {} end end From c38ad93adcdd0dcd545bba6d482853e87053825f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 14:56:58 -0800 Subject: [PATCH 160/298] interpolation -> `#to_s` --- lib/protobuf/lifecycle.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 74f09ea9..68804828 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -32,7 +32,7 @@ def trigger(event_name, *args) end def normalized_event_name(event_name) - "#{event_name}".downcase + event_name.to_s.downcase end end end From 48047302f0311037ed27cf536423f6277bd6fcfb Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 15:05:27 -0800 Subject: [PATCH 161/298] Protobuf::Deprecation is now much thinner We use the much better functionality from AS::Deprecation --- lib/protobuf.rb | 16 +++++++++--- lib/protobuf/deprecation.rb | 20 +++++++++++++++ lib/protobuf/deprecator.rb | 28 --------------------- lib/protobuf/enum.rb | 41 +++++++++---------------------- lib/protobuf/field/base_field.rb | 37 +++++++++++++--------------- lib/protobuf/field/bool_field.rb | 6 +++-- lib/protobuf/field/bytes_field.rb | 6 +++-- lib/protobuf/lifecycle.rb | 22 ++++++----------- lib/protobuf/message.rb | 4 +-- lib/protobuf/message/fields.rb | 14 +++++------ 10 files changed, 85 insertions(+), 109 deletions(-) create mode 100644 lib/protobuf/deprecation.rb delete mode 100644 lib/protobuf/deprecator.rb diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 4ee58bda..7a8d3c12 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -5,9 +5,11 @@ require 'active_support/core_ext/object/blank' require 'active_support/core_ext/object/try' -require 'active_support/notifications' require 'active_support/inflector' require 'active_support/json' +require 'active_support/notifications' + +require 'protobuf/deprecation' module Protobuf @@ -62,6 +64,13 @@ def self.gc_pause_server_request=(value) @gc_pause_server_request = !!value end + def self.deprecator + @deprecator ||= Deprecation.new('4.0', to_s).tap do |deprecation| + deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') + deprecation.behavior = :stderr + end + end + # Print Deprecation Warnings # # Default: true @@ -73,12 +82,11 @@ def self.gc_pause_server_request=(value) # # The rpc_server option will override the ENV setting. def self.print_deprecation_warnings? - return @print_deprecation_warnings unless @print_deprecation_warnings.nil? - self.print_deprecation_warnings = ENV.key?('PB_IGNORE_DEPRECATIONS') ? false : true + !deprecator.silenced end def self.print_deprecation_warnings=(value) - @print_deprecation_warnings = !!value + deprecator.silenced = !value end # Permit unknown field on Message initialization diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb new file mode 100644 index 00000000..24cad832 --- /dev/null +++ b/lib/protobuf/deprecation.rb @@ -0,0 +1,20 @@ +require 'active_support/deprecation' + +module Protobuf + class Deprecation < ::ActiveSupport::Deprecation + def deprecate_methods(*args) + args.last.merge!(:deprecator => self) if args.last.is_a?(Hash) + super + end + + def define_deprecated_methods(target_module, method_hash) + target_module.module_eval do + method_hash.each do |old_method, new_method| + alias_method old_method, new_method + end + end + + deprecate_methods(target_module, method_hash) + end + end +end diff --git a/lib/protobuf/deprecator.rb b/lib/protobuf/deprecator.rb deleted file mode 100644 index b7333324..00000000 --- a/lib/protobuf/deprecator.rb +++ /dev/null @@ -1,28 +0,0 @@ -module Protobuf - module Deprecator - - def warn_deprecated(old_method, new_method) - $stderr.puts %([DEPRECATED] #{name}.#{old_method} is deprecated and will disappear in a future version. - Please use #{name}.#{new_method} instead.\n) - end - - # Given deprecations should be a hash whose keys are the new methods - # and values are a list of deprecated methods that should send to t - def deprecate_method(old_method, new_method) - define_method old_method do |*args| - self.class.warn_deprecated(old_method, new_method) - public_send(new_method, *args) - end - end - - # Given deprecations should be a hash whose keys are the new methods - # and values are a list of deprecated methods that should send to t - def deprecate_class_method(old_method, new_method) - define_singleton_method old_method do |*args| - warn_deprecated(old_method, new_method) - public_send(new_method, *args) - end - end - - end -end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index f85665f8..c83e8215 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,33 +1,15 @@ require 'delegate' require 'protobuf/optionable' -require 'protobuf/deprecator' ## # Adding extension to Numeric until # we can get people to stop calling #value # on Enum instances. # -class Numeric - unless method_defined?(:value) - def value - $stderr.puts <<-DEPRECATION -[DEPRECATED] Enum#value is deprecated and will be removed in the next release. - Use Enum#to_i instead. -DEPRECATION - self - end - end -end +::Protobuf.deprecator.define_deprecated_methods(Numeric, :value => :to_int) module Protobuf class Enum < SimpleDelegator - - ## - # Deprecations - # - - extend ::Protobuf::Deprecator - # Public: Allows setting Options on the Enum class. include ::Protobuf::Optionable @@ -223,8 +205,6 @@ def self.valid_tag?(tag) # by their :name. # def self.values - warn_deprecated(:values, :enums) - @values ||= begin enums.each_with_object({}) do |enum, hash| hash[enum.name] = enum @@ -235,11 +215,17 @@ def self.values ## # Class Deprecations # + class << self + ::Protobuf.deprecator.define_deprecated_methods( + self, + :enum_by_value => :enum_for_tag, + :name_by_value => :name_for_tag, + :get_name_by_tag => :name_for_tag, + :value_by_name => :enum_for_name, + ) - deprecate_class_method :enum_by_value, :enum_for_tag - deprecate_class_method :name_by_value, :name_for_tag - deprecate_class_method :get_name_by_tag, :name_for_tag - deprecate_class_method :value_by_name, :enum_for_name + ::Protobuf.deprecator.deprecate_methods(self, :values => :enums) + end ## # Attributes @@ -303,10 +289,7 @@ def try(*args, &block) end end - def value - parent_class.warn_deprecated(:value, :to_i) - to_i - end + ::Protobuf.deprecator.define_deprecated_methods(self, :value => :to_i) ## # Instance Aliases diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 8b722e8a..85cbc90a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -153,16 +153,7 @@ def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" end - def type - $stderr.puts("[DEPRECATED] #{self.class.name}#type usage is deprecated.\nPlease use #type_class instead.") - type_class - end - - def warn_if_deprecated - if ::Protobuf.print_deprecation_warnings? && deprecated? - $stderr.puts("[WARNING] #{message_class.name}##{name} field usage is deprecated.") - end - end + ::Protobuf.deprecator.define_deprecated_methods(self, :type => :type_class) def wire_type ::Protobuf::WireType::VARINT @@ -186,20 +177,22 @@ def define_accessor def define_array_getter field = self + method_name = field.getter + message_class.class_eval do - define_method(field.getter) do - field.warn_if_deprecated + define_method(method_name) do @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) end + ::Protobuf.deprecator.deprecate_methods(method_name) end end def define_array_setter field = self - message_class.class_eval do - define_method(field.setter) do |val| - field.warn_if_deprecated + method_name = field.setter + message_class.class_eval do + define_method(method_name) do |val| if val.is_a?(Array) val = val.dup val.compact! @@ -217,25 +210,28 @@ def define_array_setter @values[field.name].replace(val) end end + ::Protobuf.deprecator.deprecate_methods(method_name) end end def define_getter field = self + method_name = field.getter + message_class.class_eval do - define_method(field.getter) do - field.warn_if_deprecated + define_method(method_name) do @values.fetch(field.name, field.default_value) end + ::Protobuf.deprecator.deprecate_methods(method_name) end end def define_setter field = self - message_class.class_eval do - define_method(field.setter) do |val| - field.warn_if_deprecated + method_name = field.setter + message_class.class_eval do + define_method(method_name) do |val| if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) @@ -244,6 +240,7 @@ def define_setter fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end + ::Protobuf.deprecator.deprecate_methods(method_name) end end diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 182d6295..a2534ef0 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -38,11 +38,13 @@ def define_getter super field = self + method_name = "#{field.getter}?" + message_class.class_eval do - define_method("#{field.getter}?") do - field.warn_if_deprecated + define_method(method_name) do @values.fetch(field.name, field.default_value) end + ::Protobuf.deprecator.deprecate_methods(method_name) end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 733e391e..a943745c 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -53,10 +53,11 @@ def wire_type def define_setter field = self + method_name = field.setter + message_class.class_eval do - define_method(field.setter) do |val| + define_method(method_name) do |val| begin - field.warn_if_deprecated val = "#{val}" if val.is_a?(Symbol) if val.nil? @@ -72,6 +73,7 @@ def define_setter raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" end end + ::Protobuf.deprecator.deprecate_methods(method_name) end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 68804828..5e96b444 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -5,13 +5,6 @@ def register(event_name, &blk) fail "Lifecycle register must have a block" unless block_given? event_name = normalized_event_name(event_name) - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. - Use ::ActiveSupport::Notifications.subscribe('#{event_name}') - ERROR - end - ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| blk.call(*args) end @@ -19,18 +12,19 @@ def register(event_name, &blk) alias_method :on, :register def trigger(event_name, *args) - if ::Protobuf.print_deprecation_warnings? - $stderr.puts <<-ERROR - [DEPRECATED] ::Protobuf::Lifecycle has been deprecated and will be removed in a future version. - Use ::ActiveSupport::Notifications.instrument(...) - ERROR - end - event_name = normalized_event_name(event_name) ::ActiveSupport::Notifications.instrument(event_name, args) end + replacement = ::ActiveSupport::Notifications + + ::Protobuf.deprecator.deprecate_methods( + self, + :register => "#{replacement}.#{replacement.method(:subscribe).name}".to_sym, + :trigger => "#{replacement}.#{replacement.method(:instrument).name}".to_sym, + ) + def normalized_event_name(event_name) event_name.to_s.downcase end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 788f92b6..b024c957 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -11,8 +11,6 @@ class Message # Includes & Extends # - extend ::Protobuf::Deprecator - extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization @@ -86,7 +84,7 @@ def each_field_for_serialization def field?(name) @values.key?(name) end - deprecate_method(:has_field?, :field?) + ::Protobuf.deprecator.define_deprecated_methods(self, :has_field? => :field?) def inspect attrs = self.class.fields.map do |field| diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 808e7393..eea33128 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -1,15 +1,15 @@ -require 'protobuf/deprecator' - module Protobuf class Message module Fields def self.extended(other) - other.extend(::Protobuf::Deprecator) - other.deprecate_class_method(:get_ext_field_by_name, :get_extension_field) - other.deprecate_class_method(:get_ext_field_by_tag, :get_extension_field) - other.deprecate_class_method(:get_field_by_name, :get_field) - other.deprecate_class_method(:get_field_by_tag, :get_field) + ::Protobuf.deprecator.define_deprecated_methods( + other.singleton_class, + :get_ext_field_by_name => :get_extension_field, + :get_ext_field_by_tag => :get_extension_field, + :get_field_by_name => :get_field, + :get_field_by_tag => :get_field, + ) end ## From 2f607ee1765909fbf238aca3f0e4ffbb51b55e55 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 15:11:18 -0800 Subject: [PATCH 162/298] Style --- spec/lib/protobuf/enum_spec.rb | 26 +++++++++++++++----------- 1 file changed, 15 insertions(+), 11 deletions(-) diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 036693a9..79913247 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -50,21 +50,25 @@ describe '.enums' do it 'provides an array of defined Enums' do - expect(Test::EnumTestType.enums).to eq([ - Test::EnumTestType::ONE, - Test::EnumTestType::TWO, - Test::EnumTestType::MINUS_ONE, - Test::EnumTestType::THREE, - ]) + expect(Test::EnumTestType.enums).to eq( + [ + Test::EnumTestType::ONE, + Test::EnumTestType::TWO, + Test::EnumTestType::MINUS_ONE, + Test::EnumTestType::THREE, + ], + ) end context 'when enum allows aliases' do it 'treats aliased enums as valid' do - expect(EnumAliasTest.enums).to eq([ - EnumAliasTest::FOO, - EnumAliasTest::BAR, - EnumAliasTest::BAZ, - ]) + expect(EnumAliasTest.enums).to eq( + [ + EnumAliasTest::FOO, + EnumAliasTest::BAR, + EnumAliasTest::BAZ, + ], + ) end end end From f96ab05df15b180cbccdcabcd72cf76e0bb5842d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 15:40:47 -0800 Subject: [PATCH 163/298] Silence deprecation warnings in tests --- lib/protobuf/rpc/connectors/common.rb | 4 ++-- spec/lib/protobuf/enum_spec.rb | 27 +++++++++++++++++++++++++-- spec/lib/protobuf/lifecycle_spec.rb | 7 ++++++- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index dd02b34f..3133131d 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -78,7 +78,7 @@ def parse_response response_wrapper = Protobuf::Socketrpc::Response.decode(@response_data) # Determine success or failure based on parsed data - if response_wrapper.has_field?(:error_reason) + if response_wrapper.field?(:error_reason) logger.debug { sign_message("Error response parsed") } # fail the call if we already know the client is failed @@ -90,7 +90,7 @@ def parse_response # Ensure client_response is an instance parsed = @options[:response_type].decode(response_wrapper.response_proto.to_s) - if parsed.nil? && !response_wrapper.has_field?(:error_reason) + if parsed.nil? && !response_wrapper.field?(:error_reason) failure(:BAD_RESPONSE_PROTO, 'Unable to parse response from server') else verify_callbacks diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 79913247..d2f3ef27 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -177,6 +177,11 @@ end describe '.values' do + around do |example| + # this method is deprecated + ::Protobuf.deprecator.silence(&example) + end + it 'provides a hash of defined Enums' do expect(Test::EnumTestType.values).to eq( :MINUS_ONE => Test::EnumTestType::MINUS_ONE, @@ -208,7 +213,16 @@ specify { expect(subject.parent_class).to eq(Test::EnumTestType) } specify { expect(subject.name).to eq(:ONE) } specify { expect(subject.tag).to eq(1) } - specify { expect(subject.value).to eq(1) } + + context 'deprecated' do + around do |example| + # this method is deprecated + ::Protobuf.deprecator.silence(&example) + end + + specify { expect(subject.value).to eq(1) } + end + specify { expect(subject.to_hash_value).to eq(1) } specify { expect(subject.to_s).to eq("1") } specify { expect(subject.inspect).to eq('#') } @@ -225,7 +239,16 @@ specify { expect(subject.try(:class)).to eq(subject.class) } specify { expect(subject.try(:name)).to eq(subject.name) } specify { expect(subject.try(:tag)).to eq(subject.tag) } - specify { expect(subject.try(:value)).to eq(subject.value) } + + context 'deprecated' do + around do |example| + # this method is deprecated + ::Protobuf.deprecator.silence(&example) + end + + specify { expect(subject.try(:value)).to eq(subject.value) } + end + specify { expect(subject.try(:to_i)).to eq(subject.to_i) } specify { expect(subject.try(:to_int)).to eq(subject.to_int) } specify { subject.try { |yielded| expect(yielded).to eq(subject) } } diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index de42520f..e882433b 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -4,7 +4,12 @@ describe ::Protobuf::Lifecycle do subject { described_class } - before(:each) do + around do |example| + # this entire class is deprecated + ::Protobuf.deprecator.silence(&example) + end + + before do ::ActiveSupport::Notifications.notifier = ::ActiveSupport::Notifications::Fanout.new end From 9c615958324cd3c11e6b1b93b637304199bb3711 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 15:42:45 -0800 Subject: [PATCH 164/298] Add pry debugger gems --- .rubocop.yml | 3 +++ protobuf.gemspec | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 33450227..b509a16c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,5 +1,8 @@ inherit_from: .rubocop_todo.yml +Lint/EndAlignment: + AlignWith: variable + Lint/Loop: Enabled: false diff --git a/protobuf.gemspec b/protobuf.gemspec index 3549a82f..463c0224 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -25,7 +25,6 @@ require "protobuf/version" s.add_dependency 'thread_safe' s.add_development_dependency 'ffi-rzmq' - s.add_development_dependency 'pry' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' s.add_development_dependency 'rubocop' @@ -33,6 +32,18 @@ require "protobuf/version" s.add_development_dependency 'timecop' s.add_development_dependency 'yard' + # debuggers only work in MRI + if RUBY_ENGINE.to_sym == :ruby + # we don't support MRI < 1.9.3 + pry_debugger = if RUBY_VERSION < '2.0.0' + 'pry-debugger' + else + 'pry-byebug' + end + + s.add_development_dependency pry_debugger + s.add_development_dependency 'pry-stack_explorer' + end + s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby - s.add_development_dependency 'pry-nav' unless RUBY_ENGINE.to_sym == :rbx end From db4fd435293ff2d7263b1d128d2f0222b3a13a6e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 16:39:46 -0800 Subject: [PATCH 165/298] Suppress more noisy test output --- spec/lib/protobuf/generators/base_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 82ffd269..668b3b1d 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -74,6 +74,7 @@ def compile context 'when tags are missing in the range' do it 'prints a warning' do + expect(::Protobuf::CodeGenerator).to receive(:print_tag_warning_suppress) expect(::Protobuf::CodeGenerator).to receive(:warn).with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) described_class.validate_tags("FooBar", [1, 2, 4, 5]) end From 4e383bfe3ab249a3381141fd9133dfb6f3eb515e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:02:20 -0800 Subject: [PATCH 166/298] Disable RSpec monkey patching --- spec/bin/protoc-gen-ruby_spec.rb | 2 +- spec/encoding/all_types_spec.rb | 2 +- spec/encoding/extreme_values_spec.rb | Bin 1358 -> 1364 bytes spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/cli_spec.rb | 2 +- spec/lib/protobuf/code_generator_spec.rb | 2 +- spec/lib/protobuf/enum_spec.rb | 2 +- spec/lib/protobuf/field/float_field_spec.rb | 2 +- spec/lib/protobuf/field/int32_field_spec.rb | 2 +- spec/lib/protobuf/field/string_field_spec.rb | 2 +- spec/lib/protobuf/field_spec.rb | 2 +- spec/lib/protobuf/generators/base_spec.rb | 2 +- .../generators/enum_generator_spec.rb | 2 +- .../generators/extension_generator_spec.rb | 2 +- .../generators/field_generator_spec.rb | 2 +- .../generators/file_generator_spec.rb | 2 +- .../generators/service_generator_spec.rb | 2 +- spec/lib/protobuf/lifecycle_spec.rb | 2 +- spec/lib/protobuf/message_spec.rb | 2 +- spec/lib/protobuf/optionable_spec.rb | 2 +- spec/lib/protobuf/rpc/client_spec.rb | 2 +- spec/lib/protobuf/rpc/connector_spec.rb | 2 +- spec/lib/protobuf/rpc/connectors/base_spec.rb | 2 +- .../protobuf/rpc/connectors/common_spec.rb | 2 +- .../protobuf/rpc/connectors/socket_spec.rb | 4 ++-- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 2 +- .../rpc/middleware/exception_handler_spec.rb | 2 +- .../protobuf/rpc/middleware/logger_spec.rb | 2 +- .../rpc/middleware/request_decoder_spec.rb | 2 +- .../rpc/middleware/response_encoder_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/server_spec.rb | 2 +- .../lib/protobuf/rpc/servers/zmq/util_spec.rb | 2 +- .../protobuf/rpc/servers/zmq/worker_spec.rb | 2 +- .../protobuf/rpc/service_directory_spec.rb | 2 +- .../protobuf/rpc/service_dispatcher_spec.rb | 2 +- spec/lib/protobuf/rpc/service_filters_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 2 +- spec/lib/protobuf/rpc/stat_spec.rb | 2 +- spec/lib/protobuf_spec.rb | 2 +- spec/spec_helper.rb | 2 ++ 42 files changed, 43 insertions(+), 41 deletions(-) diff --git a/spec/bin/protoc-gen-ruby_spec.rb b/spec/bin/protoc-gen-ruby_spec.rb index cbbce0da..1df8b155 100644 --- a/spec/bin/protoc-gen-ruby_spec.rb +++ b/spec/bin/protoc-gen-ruby_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/code_generator' -describe 'protoc-gen-ruby' do +RSpec.describe 'protoc-gen-ruby' do let(:binpath) { ::File.expand_path('../../../bin/protoc-gen-ruby', __FILE__) } let(:package) { 'test' } let(:request_bytes) do diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index 411a7a55..d56970fb 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ::Protobuf do +RSpec.describe ::Protobuf do it "correctly encodes all types" do message = GoogleUnittest::TestAllTypes.new( optional_int32: 101, diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index 39aa70d11d5507e16d460101de0cd74c967d8655..ded4fb02c2df33c6fb8798d5846630806c33659a 100644 GIT binary patch delta 17 YcmX@db%kq!I9pI~L29zzMsagi05=l_a{vGU delta 10 Rcmcb@b&hL-_(oZCRsa^m184vM diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index 6b034845..e46c36ae 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'spec/support/test/resource_service' -describe 'Functional Socket Client' do +RSpec.describe 'Functional Socket Client' do before(:all) do load "protobuf/socket.rb" @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 18d1941b..8996973d 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -3,7 +3,7 @@ require 'spec/support/test/resource_service' require 'protobuf/rpc/service_directory' -describe 'Functional ZMQ Client' do +RSpec.describe 'Functional ZMQ Client' do before(:all) do load "protobuf/zmq.rb" @runner = ::Protobuf::Rpc::ZmqRunner.new( diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index b0bcb5af..0c716bf2 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/cli' -describe ::Protobuf::CLI do +RSpec.describe ::Protobuf::CLI do let(:app_file) do File.expand_path('../../../support/test_app_file.rb', __FILE__) diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index b41849d2..48115829 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/code_generator' -describe ::Protobuf::CodeGenerator do +RSpec.describe ::Protobuf::CodeGenerator do # Some constants to shorten things up DESCRIPTOR = ::Google::Protobuf diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index d2f3ef27..399bd814 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Enum do +RSpec.describe Protobuf::Enum do describe 'class dsl' do let(:name) { :THREE } diff --git a/spec/lib/protobuf/field/float_field_spec.rb b/spec/lib/protobuf/field/float_field_spec.rb index 7bda8a33..a007871f 100644 --- a/spec/lib/protobuf/field/float_field_spec.rb +++ b/spec/lib/protobuf/field/float_field_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Field::FloatField do +RSpec.describe Protobuf::Field::FloatField do class SomeFloatMessage < ::Protobuf::Message optional :float, :some_float, 1 diff --git a/spec/lib/protobuf/field/int32_field_spec.rb b/spec/lib/protobuf/field/int32_field_spec.rb index 53281e23..5c1ff70b 100644 --- a/spec/lib/protobuf/field/int32_field_spec.rb +++ b/spec/lib/protobuf/field/int32_field_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Field::Int32Field do +RSpec.describe Protobuf::Field::Int32Field do it_behaves_like :packable_field, described_class diff --git a/spec/lib/protobuf/field/string_field_spec.rb b/spec/lib/protobuf/field/string_field_spec.rb index 24318531..f403c027 100644 --- a/spec/lib/protobuf/field/string_field_spec.rb +++ b/spec/lib/protobuf/field/string_field_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe ::Protobuf::Field::StringField do +RSpec.describe ::Protobuf::Field::StringField do describe '#encode' do context 'when a repeated string field contains frozen strings' do diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index 4dafd9f5..a8efb781 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/field' -describe ::Protobuf::Field do +RSpec.describe ::Protobuf::Field do describe '.build' do pending diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index 668b3b1d..f6bb027b 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -3,7 +3,7 @@ require 'protobuf/code_generator' require 'protobuf/generators/base' -describe ::Protobuf::Generators::Base do +RSpec.describe ::Protobuf::Generators::Base do subject { described_class.new(double) } diff --git a/spec/lib/protobuf/generators/enum_generator_spec.rb b/spec/lib/protobuf/generators/enum_generator_spec.rb index 086cb4a2..0d63ff2d 100644 --- a/spec/lib/protobuf/generators/enum_generator_spec.rb +++ b/spec/lib/protobuf/generators/enum_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/generators/enum_generator' -describe ::Protobuf::Generators::EnumGenerator do +RSpec.describe ::Protobuf::Generators::EnumGenerator do let(:values) do [ diff --git a/spec/lib/protobuf/generators/extension_generator_spec.rb b/spec/lib/protobuf/generators/extension_generator_spec.rb index b3f68c8d..55eb98ad 100644 --- a/spec/lib/protobuf/generators/extension_generator_spec.rb +++ b/spec/lib/protobuf/generators/extension_generator_spec.rb @@ -3,7 +3,7 @@ require 'protobuf/code_generator' require 'protobuf/generators/extension_generator' -describe ::Protobuf::Generators::ExtensionGenerator do +RSpec.describe ::Protobuf::Generators::ExtensionGenerator do let(:field_descriptors) do [ diff --git a/spec/lib/protobuf/generators/field_generator_spec.rb b/spec/lib/protobuf/generators/field_generator_spec.rb index 7ba88536..246e4649 100644 --- a/spec/lib/protobuf/generators/field_generator_spec.rb +++ b/spec/lib/protobuf/generators/field_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/generators/field_generator' -describe ::Protobuf::Generators::FieldGenerator do +RSpec.describe ::Protobuf::Generators::FieldGenerator do let(:label_enum) { :LABEL_OPTIONAL } let(:name) { 'foo_bar' } diff --git a/spec/lib/protobuf/generators/file_generator_spec.rb b/spec/lib/protobuf/generators/file_generator_spec.rb index 6560cf8d..3374d75e 100644 --- a/spec/lib/protobuf/generators/file_generator_spec.rb +++ b/spec/lib/protobuf/generators/file_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/generators/file_generator' -describe ::Protobuf::Generators::FileGenerator do +RSpec.describe ::Protobuf::Generators::FileGenerator do let(:base_descriptor_fields) { { :name => 'test/foo.proto' } } let(:descriptor_fields) { base_descriptor_fields } diff --git a/spec/lib/protobuf/generators/service_generator_spec.rb b/spec/lib/protobuf/generators/service_generator_spec.rb index 03622318..c3500877 100644 --- a/spec/lib/protobuf/generators/service_generator_spec.rb +++ b/spec/lib/protobuf/generators/service_generator_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/generators/service_generator' -describe ::Protobuf::Generators::ServiceGenerator do +RSpec.describe ::Protobuf::Generators::ServiceGenerator do let(:methods) do [ diff --git a/spec/lib/protobuf/lifecycle_spec.rb b/spec/lib/protobuf/lifecycle_spec.rb index e882433b..d1414477 100644 --- a/spec/lib/protobuf/lifecycle_spec.rb +++ b/spec/lib/protobuf/lifecycle_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/lifecycle' -describe ::Protobuf::Lifecycle do +RSpec.describe ::Protobuf::Lifecycle do subject { described_class } around do |example| diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 48458e95..8581fa50 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Protobuf::Message do +RSpec.describe Protobuf::Message do describe '.decode' do let(:message) { ::Test::Resource.new(:name => "Jim") } diff --git a/spec/lib/protobuf/optionable_spec.rb b/spec/lib/protobuf/optionable_spec.rb index 056f9092..e3428f64 100644 --- a/spec/lib/protobuf/optionable_spec.rb +++ b/spec/lib/protobuf/optionable_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/optionable' -describe 'Optionable' do +RSpec.describe 'Optionable' do describe '.set_option' do before(:all) do diff --git a/spec/lib/protobuf/rpc/client_spec.rb b/spec/lib/protobuf/rpc/client_spec.rb index cd2bfe13..8bdefc02 100644 --- a/spec/lib/protobuf/rpc/client_spec.rb +++ b/spec/lib/protobuf/rpc/client_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'spec/support/test/resource_service' -describe Protobuf::Rpc::Client do +RSpec.describe Protobuf::Rpc::Client do before(:each) do load 'protobuf/socket.rb' end diff --git a/spec/lib/protobuf/rpc/connector_spec.rb b/spec/lib/protobuf/rpc/connector_spec.rb index 4092ce0f..1d433b49 100644 --- a/spec/lib/protobuf/rpc/connector_spec.rb +++ b/spec/lib/protobuf/rpc/connector_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/socket' require 'protobuf/zmq' -describe ::Protobuf::Rpc::Connector do +RSpec.describe ::Protobuf::Rpc::Connector do describe '.connector_for_client(true)' do subject { described_class.connector_for_client } diff --git a/spec/lib/protobuf/rpc/connectors/base_spec.rb b/spec/lib/protobuf/rpc/connectors/base_spec.rb index 5a9945ae..2c5fc98d 100644 --- a/spec/lib/protobuf/rpc/connectors/base_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/base_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Connectors::Base do +RSpec.describe Protobuf::Rpc::Connectors::Base do let(:options) do { :timeout => 60 } diff --git a/spec/lib/protobuf/rpc/connectors/common_spec.rb b/spec/lib/protobuf/rpc/connectors/common_spec.rb index 54ab8c33..de98c551 100644 --- a/spec/lib/protobuf/rpc/connectors/common_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/common_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/rpc/service' -describe Protobuf::Rpc::Connectors::Common do +RSpec.describe Protobuf::Rpc::Connectors::Common do let(:common_class) do Class.new(Protobuf::Rpc::Connectors::Base) do include Protobuf::Rpc::Connectors::Common diff --git a/spec/lib/protobuf/rpc/connectors/socket_spec.rb b/spec/lib/protobuf/rpc/connectors/socket_spec.rb index 635c6590..12bd15d9 100644 --- a/spec/lib/protobuf/rpc/connectors/socket_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/socket_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/socket' -shared_examples "a Protobuf Connector" do +RSpec.shared_examples "a Protobuf Connector" do subject { described_class.new({}) } context "API" do @@ -13,7 +13,7 @@ end end -describe Protobuf::Rpc::Connectors::Socket do +RSpec.describe Protobuf::Rpc::Connectors::Socket do subject { described_class.new({}) } it_behaves_like "a Protobuf Connector" diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index 53a918b0..b15e94be 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/zmq' -describe ::Protobuf::Rpc::Connectors::Zmq do +RSpec.describe ::Protobuf::Rpc::Connectors::Zmq do subject { described_class.new(options) } let(:options) do diff --git a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb index 8ebe422b..0a71e43d 100644 --- a/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/exception_handler_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Middleware::ExceptionHandler do +RSpec.describe Protobuf::Rpc::Middleware::ExceptionHandler do let(:app) { proc { |env| env } } let(:env) { Protobuf::Rpc::Env.new } diff --git a/spec/lib/protobuf/rpc/middleware/logger_spec.rb b/spec/lib/protobuf/rpc/middleware/logger_spec.rb index 8ae5959d..1c5ddd66 100644 --- a/spec/lib/protobuf/rpc/middleware/logger_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/logger_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Middleware::Logger do +RSpec.describe Protobuf::Rpc::Middleware::Logger do let(:app) { proc { |inner_env| inner_env } } let(:env) do Protobuf::Rpc::Env.new( diff --git a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb index f95a05ab..3132c85c 100644 --- a/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/request_decoder_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Middleware::RequestDecoder do +RSpec.describe Protobuf::Rpc::Middleware::RequestDecoder do let(:app) { proc { |env| env } } let(:client_host) { 'client_host.test.co' } let(:env) do diff --git a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb index 00ab46cd..7189a31a 100644 --- a/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb +++ b/spec/lib/protobuf/rpc/middleware/response_encoder_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe Protobuf::Rpc::Middleware::ResponseEncoder do +RSpec.describe Protobuf::Rpc::Middleware::ResponseEncoder do let(:app) { proc { |env| env.response = response; env } } let(:env) do Protobuf::Rpc::Env.new( diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index 6497641c..d4947ea3 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -3,7 +3,7 @@ require 'protobuf/rpc/servers/socket_runner' require 'protobuf/socket' -describe Protobuf::Rpc::Socket::Server do +RSpec.describe Protobuf::Rpc::Socket::Server do before(:each) do load 'protobuf/socket.rb' end diff --git a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb index 215230ba..97736064 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/server_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/rpc/servers/zmq/server' -describe Protobuf::Rpc::Zmq::Server do +RSpec.describe Protobuf::Rpc::Zmq::Server do subject { described_class.new(options) } let(:options) do diff --git a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb index be2bdf62..002ac056 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/util_spec.rb @@ -4,7 +4,7 @@ class UtilTest include ::Protobuf::Rpc::Zmq::Util end -describe ::Protobuf::Rpc::Zmq::Util do +RSpec.describe ::Protobuf::Rpc::Zmq::Util do before(:each) do load 'protobuf/zmq.rb' end diff --git a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb index 1f779917..71c89282 100644 --- a/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb +++ b/spec/lib/protobuf/rpc/servers/zmq/worker_spec.rb @@ -1,6 +1,6 @@ require 'spec_helper' -describe ::Protobuf::Rpc::Zmq::Worker do +RSpec.describe ::Protobuf::Rpc::Zmq::Worker do before(:each) do load 'protobuf/zmq.rb' diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index 6f39ae20..d1d2aea4 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -2,7 +2,7 @@ require 'protobuf/rpc/service_directory' -describe ::Protobuf::Rpc::ServiceDirectory do +RSpec.describe ::Protobuf::Rpc::ServiceDirectory do subject { described_class.instance } let(:echo_server) do diff --git a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb index ca6f08df..5bf27318 100644 --- a/spec/lib/protobuf/rpc/service_dispatcher_spec.rb +++ b/spec/lib/protobuf/rpc/service_dispatcher_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf/rpc/service_dispatcher' -describe Protobuf::Rpc::ServiceDispatcher do +RSpec.describe Protobuf::Rpc::ServiceDispatcher do let(:app) { proc { |env| env } } let(:env) do Protobuf::Rpc::Env.new( diff --git a/spec/lib/protobuf/rpc/service_filters_spec.rb b/spec/lib/protobuf/rpc/service_filters_spec.rb index ebedd21b..97cc5b2d 100644 --- a/spec/lib/protobuf/rpc/service_filters_spec.rb +++ b/spec/lib/protobuf/rpc/service_filters_spec.rb @@ -27,7 +27,7 @@ def self.clear_filters! end end -describe Protobuf::Rpc::ServiceFilters do +RSpec.describe Protobuf::Rpc::ServiceFilters do let(:params) { {} } subject { FilterTest.new(params) } after(:each) { FilterTest.clear_filters! } diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 27518464..365d3c5f 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'spec/support/test/resource_service' -describe Protobuf::Rpc::Service do +RSpec.describe Protobuf::Rpc::Service do context 'class methods' do subject { Test::ResourceService } diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index eafb3dd7..f23ce783 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -2,7 +2,7 @@ require 'timecop' require 'active_support/core_ext/numeric/time' -describe ::Protobuf::Rpc::Stat do +RSpec.describe ::Protobuf::Rpc::Stat do before(:all) do unless defined?(BarService) diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 0f238013..314909c6 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -1,7 +1,7 @@ require 'spec_helper' require 'protobuf' -describe ::Protobuf do +RSpec.describe ::Protobuf do describe '.client_host' do after { ::Protobuf.client_host = nil } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 216c9415..17a01a55 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -29,6 +29,8 @@ support_proto_glob = File.expand_path('../support/**/*.pb.rb', __FILE__) Dir[support_proto_glob].each { |proto_file| require proto_file } +RSpec.configure(&:disable_monkey_patching!) + ::Protobuf::Rpc::Client.class_eval do def ==(other) connector.options == other.options && \ From fd0315a6b2dfc1d597d42b073019cfebbba67085 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:04:42 -0800 Subject: [PATCH 167/298] Remove old comment --- spec/spec_helper.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 17a01a55..ddee0881 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -3,7 +3,6 @@ require 'bundler' Bundler.setup :default, :development, :test require 'pry' -# require 'rspec/its' $LOAD_PATH << ::File.expand_path('../..', __FILE__) $LOAD_PATH << ::File.expand_path('../support', __FILE__) From 6e5de44d094949b8aa779db0a1d17e7d1d82e8b7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 09:47:52 -0800 Subject: [PATCH 168/298] Style/StringLiteralsInInterpolation --- .rubocop_todo.yml | 6 ------ lib/protobuf/rpc/servers/zmq/util.rb | 2 +- 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 600b1fc8..ba1c7755 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -99,12 +99,6 @@ Style/NumericLiterals: Style/StringLiterals: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/StringLiteralsInInterpolation: - Enabled: false - # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: WordRegex. diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index ee5e0f83..931cc0af 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -21,7 +21,7 @@ def self.included(base) def zmq_error_check(return_code, source = nil) unless ::ZMQ::Util.resultcode_ok?(return_code) fail <<-ERROR - Last ZMQ API call #{source ? "to #{source}" : ""} failed with "#{::ZMQ::Util.error_string}". + Last ZMQ API call #{source ? "to #{source}" : ''} failed with "#{::ZMQ::Util.error_string}". #{caller(1).join($INPUT_RECORD_SEPARATOR)} ERROR From ff5a48f5c0de875e5ceb5bd37824928b1b5dd40b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 10:00:21 -0800 Subject: [PATCH 169/298] Style/MultilineOperationIndentation --- .rubocop_todo.yml | 6 ------ spec/lib/protobuf/rpc/service_directory_spec.rb | 5 +++-- spec/lib/protobuf/rpc/service_spec.rb | 10 +++++----- 3 files changed, 8 insertions(+), 13 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ba1c7755..21b3d144 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -77,12 +77,6 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 3 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/MultilineOperationIndentation: - Enabled: false - # Offense count: 3 # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. Style/Next: diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index d1d2aea4..ea039ec8 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -57,8 +57,9 @@ def expect_event_trigger(event) expect(::ActiveSupport::Notifications).to receive(:instrument) - .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))) - .once + .with(event, hash_including( + :listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing), + )).once end def send_beacon(type, server) diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 365d3c5f..4c1fcf37 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -64,11 +64,11 @@ it 'initializes a client object for this service' do client = double('client') expect(::Protobuf::Rpc::Client).to receive(:new) - .with(hash_including( - :service => subject, - :host => subject.host, - :port => subject.port, - )).and_return(client) + .with(hash_including( + :service => subject, + :host => subject.host, + :port => subject.port, + )).and_return(client) expect(subject.client).to eq client end end From ddf7e0a54d31d72ad7961ef6b317d00ed55cd9d1 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 24 Nov 2014 10:01:42 -0800 Subject: [PATCH 170/298] Style/EmptyLinesAroundMethodBody --- .rubocop_todo.yml | 5 ----- lib/protobuf/rpc/servers/zmq_runner.rb | 1 - 2 files changed, 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 21b3d144..db40205b 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -55,11 +55,6 @@ Style/DoubleNegation: Style/EmptyLinesAroundClassBody: Enabled: false -# Offense count: 1 -# Cop supports --auto-correct. -Style/EmptyLinesAroundMethodBody: - Enabled: false - # Offense count: 66 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 5d213640..657986a7 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -14,7 +14,6 @@ def initialize(options) else fail "Cannot parser Zmq Server - server options" end - end def run From 335e2ab3ad08dee7ef92f2617650a32b175dc457 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:01:13 -0800 Subject: [PATCH 171/298] Style/Next --- .rubocop_todo.yml | 5 ---- lib/protobuf/generators/group_generator.rb | 28 +++++++++++----------- lib/protobuf/rpc/servers/zmq/server.rb | 13 +++++----- lib/protobuf/rpc/servers/zmq/worker.rb | 12 ++++------ 4 files changed, 25 insertions(+), 33 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index db40205b..6ba6256f 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -72,11 +72,6 @@ Style/GuardClause: Style/HashSyntax: Enabled: false -# Offense count: 3 -# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. -Style/Next: - Enabled: false - # Offense count: 53 # Cop supports --auto-correct. Style/NumericLiterals: diff --git a/lib/protobuf/generators/group_generator.rb b/lib/protobuf/generators/group_generator.rb index ddff717f..67eeb688 100644 --- a/lib/protobuf/generators/group_generator.rb +++ b/lib/protobuf/generators/group_generator.rb @@ -80,25 +80,25 @@ def add_services(service_descriptors) def compile @order.each do |type| items = @groups[type] - if items.count > 0 - item_handler = @handlers[type] + next if items.empty? - item_header = @headers[type] - header(item_header) if item_header + item_handler = @handlers[type] - item_comment = @comments[type] - comment(item_comment) if item_comment + item_header = @headers[type] + header(item_header) if item_header - items.each do |item| - if item_handler - puts item_handler.call(item) - else - print item.to_s - end - end + item_comment = @comments[type] + comment(item_comment) if item_comment - puts if type == :message_declaration + items.each do |item| + if item_handler + puts item_handler.call(item) + else + print item.to_s + end end + + puts if type == :message_declaration end end diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 87f663cb..1e1e12bf 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -251,14 +251,13 @@ def wait_for_shutdown_signal start_missing_workers end - if broadcast_heartbeat? - if all_workers_busy? && options[:broadcast_busy] - broadcast_flatline - else - broadcast_heartbeat - end - end + next unless broadcast_heartbeat? + if all_workers_busy? && options[:broadcast_busy] + broadcast_flatline + else + broadcast_heartbeat + end end end diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index e0c28357..63f1df3c 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -46,13 +46,11 @@ def run loop do rc = poller.poll(500) - # The server was shutdown and no requests are pending - break if rc == 0 && !running? - - # Something went wrong - break if rc == -1 - - if rc > 0 + if rc == 0 && !running? + break # The server was shutdown and no requests are pending + elsif rc == -1 + break # Something went wrong + elsif rc > 0 ::Thread.current[:busy] = true process_request ::Thread.current[:busy] = false From e2b50d6182b3db0485ee8ebe34d1e2cbbc728fc2 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:09:21 -0800 Subject: [PATCH 172/298] Style/HashSyntax Standardize on hash_rockets --- .rubocop.yml | 3 + .rubocop_todo.yml | 6 -- spec/encoding/all_types_spec.rb | 166 +++++++++++++++++--------------- spec/lib/protobuf/cli_spec.rb | 2 +- 4 files changed, 94 insertions(+), 83 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index b509a16c..2f36863f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,9 @@ Style/FileName: Exclude: - '**/protoc-gen-ruby*' +Style/HashSyntax: + EnforcedStyle: hash_rockets + Style/IndentHash: EnforcedStyle: consistent diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 6ba6256f..23cc0689 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -66,12 +66,6 @@ Style/EmptyLinesAroundModuleBody: Style/GuardClause: Enabled: false -# Offense count: 690 -# Cop supports --auto-correct. -# Configuration parameters: EnforcedStyle, SupportedStyles. -Style/HashSyntax: - Enabled: false - # Offense count: 53 # Cop supports --auto-correct. Style/NumericLiterals: diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index d56970fb..01b772a3 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -3,82 +3,96 @@ RSpec.describe ::Protobuf do it "correctly encodes all types" do message = GoogleUnittest::TestAllTypes.new( - optional_int32: 101, - optional_int64: 102, - optional_uint32: 103, - optional_uint64: 104, - optional_sint32: 105, - optional_sint64: 106, - optional_fixed32: 107, - optional_fixed64: 108, - optional_sfixed32: 109, - optional_sfixed64: 110, - optional_float: 111, - optional_double: 112, - optional_bool: true, - optional_string: "115", - optional_bytes: "116", - optional_nested_message: GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 118), - optional_foreign_message: GoogleUnittest::ForeignMessage.new(c: 119), - optional_import_message: GoogleUnittestImport::ImportMessage.new(d: 120), - optional_nested_enum: GoogleUnittest::TestAllTypes::NestedEnum::BAZ, - optional_foreign_enum: GoogleUnittest::ForeignEnum::FOREIGN_BAZ, - optional_import_enum: GoogleUnittestImport::ImportEnum::IMPORT_BAZ, - optional_string_piece: "124", - optional_cord: "125", - optional_public_import_message: GoogleUnittestImport::PublicImportMessage.new(e: 126), - optional_lazy_message: GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 127), - repeated_int32: [201, 301], - repeated_int64: [202, 302], - repeated_uint32: [203, 303], - repeated_uint64: [204, 304], - repeated_sint32: [205, 305], - repeated_sint64: [206, 306], - repeated_fixed32: [207, 307], - repeated_fixed64: [208, 308], - repeated_sfixed32: [209, 309], - repeated_sfixed64: [210, 310], - repeated_float: [211, 311], - repeated_double: [212, 312], - repeated_bool: [true, false], - repeated_string: ["215", "315"], - repeated_bytes: ["216", "316"], - repeated_nested_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 218), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 318)], - repeated_foreign_message: [::GoogleUnittest::ForeignMessage.new(c: 219), - ::GoogleUnittest::ForeignMessage.new(c: 319)], - repeated_import_message: [::GoogleUnittestImport::ImportMessage.new(d: 220), - ::GoogleUnittestImport::ImportMessage.new(d: 320)], - repeated_nested_enum: [::GoogleUnittest::TestAllTypes::NestedEnum::BAR, - ::GoogleUnittest::TestAllTypes::NestedEnum::BAZ], - repeated_foreign_enum: [::GoogleUnittest::ForeignEnum::FOREIGN_BAR, - ::GoogleUnittest::ForeignEnum::FOREIGN_BAZ], - repeated_import_enum: [::GoogleUnittestImport::ImportEnum::IMPORT_BAR, - ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ], - repeated_string_piece: ["224", "324"], - repeated_cord: ["225", "325"], - repeated_lazy_message: [::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 227), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(bb: 327)], - default_int32: 401, - default_int64: 402, - default_uint32: 403, - default_uint64: 404, - default_sint32: 405, - default_sint64: 406, - default_fixed32: 407, - default_fixed64: 408, - default_sfixed32: 409, - default_sfixed64: 410, - default_float: 411, - default_double: 412, - default_bool: false, - default_string: "415", - default_bytes: "416", - default_nested_enum: ::GoogleUnittest::TestAllTypes::NestedEnum::FOO, - default_foreign_enum: ::GoogleUnittest::ForeignEnum::FOREIGN_FOO, - default_import_enum: ::GoogleUnittestImport::ImportEnum::IMPORT_FOO, - default_string_piece: "424", - default_cord: "425", + :optional_int32 => 101, + :optional_int64 => 102, + :optional_uint32 => 103, + :optional_uint64 => 104, + :optional_sint32 => 105, + :optional_sint64 => 106, + :optional_fixed32 => 107, + :optional_fixed64 => 108, + :optional_sfixed32 => 109, + :optional_sfixed64 => 110, + :optional_float => 111, + :optional_double => 112, + :optional_bool => true, + :optional_string => "115", + :optional_bytes => "116", + :optional_nested_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 118), + :optional_foreign_message => GoogleUnittest::ForeignMessage.new(:c => 119), + :optional_import_message => GoogleUnittestImport::ImportMessage.new(:d => 120), + :optional_nested_enum => GoogleUnittest::TestAllTypes::NestedEnum::BAZ, + :optional_foreign_enum => GoogleUnittest::ForeignEnum::FOREIGN_BAZ, + :optional_import_enum => GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + :optional_string_piece => "124", + :optional_cord => "125", + :optional_public_import_message => GoogleUnittestImport::PublicImportMessage.new(:e => 126), + :optional_lazy_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 127), + :repeated_int32 => [201, 301], + :repeated_int64 => [202, 302], + :repeated_uint32 => [203, 303], + :repeated_uint64 => [204, 304], + :repeated_sint32 => [205, 305], + :repeated_sint64 => [206, 306], + :repeated_fixed32 => [207, 307], + :repeated_fixed64 => [208, 308], + :repeated_sfixed32 => [209, 309], + :repeated_sfixed64 => [210, 310], + :repeated_float => [211, 311], + :repeated_double => [212, 312], + :repeated_bool => [true, false], + :repeated_string => ["215", "315"], + :repeated_bytes => ["216", "316"], + :repeated_nested_message => [ + ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 218), + ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 318), + ], + :repeated_foreign_message => [ + ::GoogleUnittest::ForeignMessage.new(:c => 219), + ::GoogleUnittest::ForeignMessage.new(:c => 319), + ], + :repeated_import_message => [ + ::GoogleUnittestImport::ImportMessage.new(:d => 220), + ::GoogleUnittestImport::ImportMessage.new(:d => 320), + ], + :repeated_nested_enum => [ + ::GoogleUnittest::TestAllTypes::NestedEnum::BAR, + ::GoogleUnittest::TestAllTypes::NestedEnum::BAZ, + ], + :repeated_foreign_enum => [ + ::GoogleUnittest::ForeignEnum::FOREIGN_BAR, + ::GoogleUnittest::ForeignEnum::FOREIGN_BAZ, + ], + :repeated_import_enum => [ + ::GoogleUnittestImport::ImportEnum::IMPORT_BAR, + ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + ], + :repeated_string_piece => ["224", "324"], + :repeated_cord => ["225", "325"], + :repeated_lazy_message => [ + ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 227), + ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 327), + ], + :default_int32 => 401, + :default_int64 => 402, + :default_uint32 => 403, + :default_uint64 => 404, + :default_sint32 => 405, + :default_sint64 => 406, + :default_fixed32 => 407, + :default_fixed64 => 408, + :default_sfixed32 => 409, + :default_sfixed64 => 410, + :default_float => 411, + :default_double => 412, + :default_bool => false, + :default_string => "415", + :default_bytes => "416", + :default_nested_enum => ::GoogleUnittest::TestAllTypes::NestedEnum::FOO, + :default_foreign_enum => ::GoogleUnittest::ForeignEnum::FOREIGN_FOO, + :default_import_enum => ::GoogleUnittestImport::ImportEnum::IMPORT_FOO, + :default_string_piece => "424", + :default_cord => "425", ) data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__) diff --git a/spec/lib/protobuf/cli_spec.rb b/spec/lib/protobuf/cli_spec.rb index 0c716bf2..0ff3a36e 100644 --- a/spec/lib/protobuf/cli_spec.rb +++ b/spec/lib/protobuf/cli_spec.rb @@ -14,7 +14,7 @@ end let(:zmq_runner) do - runner = double "ZmqRunner", register_signals: nil + runner = double("ZmqRunner", :register_signals => nil) allow(runner).to receive(:run).and_return(::ActiveSupport::Notifications.publish("after_server_bind")) runner end From fd8b03b22d4caaca0697978bd65631313df3df7e Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:26:29 -0800 Subject: [PATCH 173/298] Style/GuardClause --- .rubocop.yml | 3 ++ .rubocop_todo.yml | 5 --- lib/protobuf/generators/file_generator.rb | 24 +++++------- lib/protobuf/rpc/connectors/zmq.rb | 46 +++++++++++------------ lib/protobuf/rpc/servers/zmq/util.rb | 12 +++--- 5 files changed, 42 insertions(+), 48 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 2f36863f..a2e37f1f 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -24,6 +24,9 @@ Style/FileName: Exclude: - '**/protoc-gen-ruby*' +Style/GuardClause: + MinBodyLength: 4 + Style/HashSyntax: EnforcedStyle: hash_rockets diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 23cc0689..463ec257 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -61,11 +61,6 @@ Style/EmptyLinesAroundClassBody: Style/EmptyLinesAroundModuleBody: Enabled: false -# Offense count: 18 -# Configuration parameters: MinBodyLength. -Style/GuardClause: - Enabled: false - # Offense count: 53 # Cop supports --auto-correct. Style/NumericLiterals: diff --git a/lib/protobuf/generators/file_generator.rb b/lib/protobuf/generators/file_generator.rb index 3a81e1f2..32016e0d 100644 --- a/lib/protobuf/generators/file_generator.rb +++ b/lib/protobuf/generators/file_generator.rb @@ -78,15 +78,11 @@ def map_extensions(descriptor, namespaces) @extension_fields[field_descriptor.extendee] << field_descriptor end - if descriptor.respond_to_has_and_present?(:message_type) - descriptor.message_type.each do |message_descriptor| - map_extensions(message_descriptor, (namespaces + [message_descriptor.name])) - end - end + [:message_type, :nested_type].each do |type| + next unless descriptor.respond_to_has_and_present?(type) - if descriptor.respond_to_has_and_present?(:nested_type) - descriptor.nested_type.each do |nested_descriptor| - map_extensions(nested_descriptor, (namespaces + [nested_descriptor.name])) + descriptor.public_send(type).each do |type_descriptor| + map_extensions(type_descriptor, (namespaces + [type_descriptor.name])) end end end @@ -106,15 +102,15 @@ def print_generic_requires end def print_import_requires - if descriptor.dependency.count > 0 - header "Imports" + return if descriptor.dependency.empty? - descriptor.dependency.each do |dependency| - print_require(convert_filename(dependency)) - end + header "Imports" - puts + descriptor.dependency.each do |dependency| + print_require(convert_filename(dependency)) end + + puts end def print_package(&block) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 8ed87637..5403541e 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -258,25 +258,15 @@ def zmq_context end def zmq_eagain_error_check(return_code, source) - unless ::ZMQ::Util.resultcode_ok?(return_code || -1) - if ::ZMQ::Util.errno == ::ZMQ::EAGAIN - fail ZmqEagainError, <<-ERROR - Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + return if ::ZMQ::Util.resultcode_ok?(return_code || -1) - #{caller(1).join($INPUT_RECORD_SEPARATOR)} - ERROR - else - fail <<-ERROR - Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - - #{caller(1).join($INPUT_RECORD_SEPARATOR)} - ERROR - end - end - end + if ::ZMQ::Util.errno == ::ZMQ::EAGAIN + fail ZmqEagainError, <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". - def zmq_error_check(return_code, source) - unless ::ZMQ::Util.resultcode_ok?(return_code || -1) + #{caller(1).join($INPUT_RECORD_SEPARATOR)} + ERROR + else fail <<-ERROR Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". @@ -285,14 +275,24 @@ def zmq_error_check(return_code, source) end end + def zmq_error_check(return_code, source) + return if ::ZMQ::Util.resultcode_ok?(return_code || -1) + + fail <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($INPUT_RECORD_SEPARATOR)} + ERROR + end + def zmq_recoverable_error_check(return_code, source) - unless ::ZMQ::Util.resultcode_ok?(return_code || -1) - fail ZmqRecoverableError, <<-ERROR - Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + return if ::ZMQ::Util.resultcode_ok?(return_code || -1) - #{caller(1).join($INPUT_RECORD_SEPARATOR)} - ERROR - end + fail ZmqRecoverableError, <<-ERROR + Last ZMQ API call to #{source} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($INPUT_RECORD_SEPARATOR)} + ERROR end end end diff --git a/lib/protobuf/rpc/servers/zmq/util.rb b/lib/protobuf/rpc/servers/zmq/util.rb index 931cc0af..2d0c9c8b 100644 --- a/lib/protobuf/rpc/servers/zmq/util.rb +++ b/lib/protobuf/rpc/servers/zmq/util.rb @@ -19,13 +19,13 @@ def self.included(base) end def zmq_error_check(return_code, source = nil) - unless ::ZMQ::Util.resultcode_ok?(return_code) - fail <<-ERROR - Last ZMQ API call #{source ? "to #{source}" : ''} failed with "#{::ZMQ::Util.error_string}". + return if ::ZMQ::Util.resultcode_ok?(return_code) - #{caller(1).join($INPUT_RECORD_SEPARATOR)} - ERROR - end + fail <<-ERROR + Last ZMQ API call #{source ? "to #{source}" : ''} failed with "#{::ZMQ::Util.error_string}". + + #{caller(1).join($INPUT_RECORD_SEPARATOR)} + ERROR end def log_signature From 0675eb49426a4c4cf8c0820276e793a86093f475 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 11:33:25 -0800 Subject: [PATCH 174/298] Remove spurious `begin` --- lib/protobuf/enum.rb | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index c83e8215..16d414ab 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -205,11 +205,9 @@ def self.valid_tag?(tag) # by their :name. # def self.values - @values ||= begin - enums.each_with_object({}) do |enum, hash| - hash[enum.name] = enum - end - end + @values ||= enums.each_with_object({}) do |enum, hash| + hash[enum.name] = enum + end end ## From d0791796fbd02d1fadf7ee6bd283a91b5f462ca4 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 18:08:03 -0800 Subject: [PATCH 175/298] Remove unused module --- spec/support/server.rb | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/spec/support/server.rb b/spec/support/server.rb index dd0817a9..d78c4617 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -10,24 +10,6 @@ # Want to abort if server dies? Thread.abort_on_exception = true -module StubProtobufServerFactory - def self.build(delay) - new_server = Class.new(Protobuf::Rpc::Socket::Server) do - class << self - attr_accessor :sleep_interval - end - - def post_init - sleep self.class.sleep_interval - super - end - end - - new_server.sleep_interval = delay - new_server - end -end - class StubServer include Protobuf::Logging From 577db2d5cc55fcd90eb56c566d035650415ddbae Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 19:08:08 -0800 Subject: [PATCH 176/298] Clarify that this is a monkeypatch --- spec/support/test/resource_service.rb | 37 ++++++++++++--------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/spec/support/test/resource_service.rb b/spec/support/test/resource_service.rb index 41e2f93a..d8642381 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/test/resource_service.rb @@ -1,26 +1,23 @@ require ::File.expand_path('../resource.pb', __FILE__) -module Test - class ResourceService - - # request -> Test::ResourceFindRequest - # response -> Test::Resource - def find - response.name = request.name - response.status = request.active ? 1 : 0 - end +Test::ResourceService.class_eval do + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find + response.name = request.name + response.status = request.active ? 1 : 0 + end - # request -> Test::ResourceSleepRequest - # response -> Test::Resource - def find_with_sleep - sleep(request.sleep || 1) - response.name = 'Request should have timed out' - end + # request -> Test::ResourceSleepRequest + # response -> Test::Resource + def find_with_sleep + sleep(request.sleep || 1) + response.name = 'Request should have timed out' + end - # request -> Test::ResourceFindRequest - # response -> Test::Resource - def find_with_rpc_failed - rpc_failed('Find failed') - end + # request -> Test::ResourceFindRequest + # response -> Test::Resource + def find_with_rpc_failed + rpc_failed('Find failed') end end From 88f73d91d2a13db8dffb4bba376be7fbfa060337 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 00:02:50 -0800 Subject: [PATCH 177/298] Fix top-level constant warning --- spec/lib/protobuf/message_spec.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 8581fa50..db4cd261 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -361,14 +361,16 @@ describe '#inspect' do let(:klass) do - Class.new(Protobuf::Message) do - EnumKlass = Class.new(Protobuf::Enum) do + Class.new(Protobuf::Message) do |klass| + enum_class = Class.new(Protobuf::Enum) do define :YAY, 1 end + klass.const_set(:EnumKlass, enum_class) + optional :string, :name, 1 repeated :int32, :counts, 2 - optional EnumKlass, :enum, 3 + optional enum_class, :enum, 3 end end @@ -376,8 +378,7 @@ it 'lists the fields' do proto = klass.new(:name => 'wooo', :counts => [1, 2, 3], :enum => klass::EnumKlass::YAY) - expect(proto.inspect).to eq \ - '#>' + expect(proto.inspect).to eq('#>') end end From 70efd5e8f55b11c7a62b0b5b56360785be502e56 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 00:04:10 -0800 Subject: [PATCH 178/298] Style --- spec/lib/protobuf/message_spec.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index db4cd261..052b570e 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -407,10 +407,12 @@ end it 'recursively hashes a repeated set of messages' do - proto = Test::Nested.new(:multiple_resources => [ - Test::Resource.new(:name => 'Resource 1'), - Test::Resource.new(:name => 'Resource 2'), - ]) + proto = Test::Nested.new( + :multiple_resources => [ + Test::Resource.new(:name => 'Resource 1'), + Test::Resource.new(:name => 'Resource 2'), + ], + ) expect(proto.to_hash).to eq( :multiple_resources => [ From 98681adc59c85700b20e1d4161a0e3130922e3f4 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 1 Dec 2014 19:07:53 -0800 Subject: [PATCH 179/298] Stricter params parsing --- spec/benchmark/tasks.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 899e882a..6a81bedf 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -39,7 +39,7 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) benchmark_wrapper(global_bench) do |bench| bench.report("SS / SC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) } end end end @@ -52,7 +52,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) benchmark_wrapper(global_bench) do |bench| bench.report("ZS / ZC") do - (1..number_tests.to_i).each { client.find(:name => "Test Name" * test_length.to_i, :active => true) } + Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) } end end server.stop @@ -81,7 +81,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do - args[:number].to_i.times { Test::Resource.new(create_params) } + Integer(args[:number]).times { Test::Resource.new(create_params) } end puts args[:profile_output] @@ -92,7 +92,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do - args[:number].to_i.times { Test::Resource.new(create_params).serialize } + Integer(args[:number]).times { Test::Resource.new(create_params).serialize } end puts args[:profile_output] From 17ce496c60fe9d164d4ff46f861f928c2e66ac75 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 01:03:21 -0800 Subject: [PATCH 180/298] Consistent log signatures --- lib/protobuf/rpc/servers/socket/server.rb | 2 +- lib/protobuf/rpc/servers/socket/worker.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index b9e9c708..f912bc20 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -35,7 +35,7 @@ def cleanup_threads end def log_signature - @_log_signature ||= "server-#{self.class.name}" + @_log_signature ||= "[server-#{self.class.name}]" end def new_worker(socket) diff --git a/lib/protobuf/rpc/servers/socket/worker.rb b/lib/protobuf/rpc/servers/socket/worker.rb index b64ee8db..6297d20a 100644 --- a/lib/protobuf/rpc/servers/socket/worker.rb +++ b/lib/protobuf/rpc/servers/socket/worker.rb @@ -44,7 +44,7 @@ def send_data(data) end def log_signature - @_log_signature ||= "server-#{self.class}-#{object_id}" + @_log_signature ||= "[server-#{self.class}-#{object_id}]" end def socket_writable? From ead37315f2cb59c5465725eb07dce8d044e2821d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 00:53:28 -0800 Subject: [PATCH 181/298] Randomize ports --- spec/benchmark/tasks.rb | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 6a81bedf..53c3c322 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -34,8 +34,10 @@ def benchmark_wrapper(global_bench = nil) def sock_client_sock_server(number_tests, test_length, global_bench = nil) load "protobuf/socket.rb" - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => 9399) do |_server| - client = ::Test::ResourceService.client(:port => 9399) + port = 1000 + Kernel.rand(2**16 - 1000) + + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do |_server| + client = ::Test::ResourceService.client(:port => port) benchmark_wrapper(global_bench) do |bench| bench.report("SS / SC") do @@ -47,8 +49,11 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) load "protobuf/zmq.rb" - StubServer.new(:port => 9399, :server => Protobuf::Rpc::Zmq::Server) do |server| - client = ::Test::ResourceService.client(:port => 9399) + + port = 1000 + Kernel.rand(2**16 - 1000) + + StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do |server| + client = ::Test::ResourceService.client(:port => port) benchmark_wrapper(global_bench) do |bench| bench.report("ZS / ZC") do From 0095cd651f2efbd86356a51fe4c1623197347c3b Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 01:22:44 -0800 Subject: [PATCH 182/298] Fix the benchmarks --- lib/protobuf/rpc/connectors/socket.rb | 4 +- lib/protobuf/rpc/servers/socket/server.rb | 140 +++++++++++----------- spec/benchmark/tasks.rb | 5 +- spec/support/server.rb | 66 +++++----- 4 files changed, 106 insertions(+), 109 deletions(-) diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 26fd0e97..4c060f3e 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -28,8 +28,8 @@ def close_connection end def connect_to_rpc_server - @socket = TCPSocket.new(options[:host], options[:port]) - logger.debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } + @socket ||= TCPSocket.new(options[:host], options[:port]) + logger.debug { sign_message("Connection established #{options[:host]}:#{options[:port]}") } end # Method to determine error state, must be used with Connector api diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index f912bc20..72b07a87 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -1,4 +1,5 @@ -require 'protobuf/rpc/server' +require 'set' + require 'protobuf/rpc/servers/socket/worker' module Protobuf @@ -9,29 +10,48 @@ class Server AUTO_COLLECT_TIMEOUT = 5 # seconds + private + + attr_accessor :threshold, :host, :port, :backlog + attr_writer :running + + public + + attr_reader :running + alias_method :running?, :running + def initialize(options) - @options = options + self.running = false + self.host = options.fetch(:host) + self.port = options.fetch(:port) + self.backlog = options.fetch(:backlog, 100) + self.threshold = options.fetch(:threshold, 100) + end + + def threads + @threads ||= [] + end + + def working + @working ||= Set.new end def cleanup? - # every 10 connections run a cleanup routine after closing the response - @threads.size > (@threshold - 1) && (@threads.size % @threshold) == 0 + # every `threshold` connections run a cleanup routine after closing the response + threads.size > 0 && threads.size % threshold == 0 end def cleanup_threads - logger.debug { sign_message("Thread cleanup - #{@threads.size} - start") } - - @threads = @threads.select do |t| - if t[:thread].alive? - true - else - t[:thread].join - @working.delete(t[:socket]) - false + logger.debug { sign_message("Thread cleanup - #{threads.size} - start") } + + threads.delete_if do |hash| + unless (thread = hash.fetch(:thread)).alive? + thread.join + working.delete(hash.fetch(:socket)) end end - logger.debug { sign_message("Thread cleanup - #{@threads.size} - complete") } + logger.debug { sign_message("Thread cleanup - #{threads.size} - complete") } end def log_signature @@ -48,68 +68,54 @@ def new_worker(socket) def run logger.debug { sign_message("Run") } - host = @options[:host] - port = @options[:port] - backlog = @options[:backlog] - @threshold = @options[:threshold] - - @threads = [] - @server = ::TCPServer.new(host, port) - fail "The server was unable to start properly." if @server.closed? - - @server.listen(backlog) - @working = [] - @listen_fds = [@server] - @running = true - - while running? - logger.debug { sign_message("Waiting for connections") } - ready_cnxns = begin - IO.select(@listen_fds, [], [], AUTO_COLLECT_TIMEOUT) - rescue IOError - nil - end - if ready_cnxns - cnxns = ready_cnxns.first - cnxns.each do |client| - case - when !running? then - # no-op - when client == @server then - logger.debug { sign_message("Accepted new connection") } - client, _sockaddr = @server.accept - @listen_fds << client - else - unless @working.include?(client) - @working << @listen_fds.delete(client) - logger.debug { sign_message("Working") } - @threads << { :thread => new_worker(client), :socket => client } - - cleanup_threads if cleanup? + server = ::TCPServer.new(host, port) + fail "The server was unable to start properly." if server.closed? + + begin + server.listen(backlog) + listen_fds = [server] + self.running = true + + while running? + logger.debug { sign_message("Waiting for connections") } + ready_cnxns = begin + IO.select(listen_fds, [], [], AUTO_COLLECT_TIMEOUT) + rescue IOError + nil + end + + if ready_cnxns + ready_cnxns.first.each do |client| + case + when !running? + # no-op + when client == server + logger.debug { sign_message("Accepted new connection") } + client, _sockaddr = server.accept + listen_fds << client + else + unless working.include?(client) + working << listen_fds.delete(client) + logger.debug { sign_message("Working") } + threads << { :thread => new_worker(client), :socket => client } + + cleanup_threads if cleanup? + end end end + else + # Run a cleanup if select times out while waiting + cleanup_threads if threads.size > 1 end - else - # Run a cleanup if select times out while waiting - cleanup_threads if @threads.size > 1 end + ensure + server.close end - - rescue Errno::EADDRINUSE - raise - rescue - # Closing the server causes the loop to raise an exception here - raise # if running? - end - - def running? - !!@running end def stop - @running = false - @server.try(:close) + self.running = false end end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 53c3c322..e6710d6c 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -36,7 +36,7 @@ def sock_client_sock_server(number_tests, test_length, global_bench = nil) port = 1000 + Kernel.rand(2**16 - 1000) - StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do |_server| + StubServer.new(:server => Protobuf::Rpc::Socket::Server, :port => port) do client = ::Test::ResourceService.client(:port => port) benchmark_wrapper(global_bench) do |bench| @@ -52,7 +52,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) port = 1000 + Kernel.rand(2**16 - 1000) - StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do |server| + StubServer.new(:port => port, :server => Protobuf::Rpc::Zmq::Server) do client = ::Test::ResourceService.client(:port => port) benchmark_wrapper(global_bench) do |bench| @@ -60,7 +60,6 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) Integer(number_tests).times { client.find(:name => "Test Name" * Integer(test_length), :active => true) } end end - server.stop end end diff --git a/spec/support/server.rb b/spec/support/server.rb index d78c4617..d4f30c7d 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -1,4 +1,7 @@ require 'ostruct' + +require 'active_support/core_ext/hash/reverse_merge' + require 'protobuf/logging' require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket/server' @@ -13,57 +16,46 @@ class StubServer include Protobuf::Logging - attr_accessor :options + private + + attr_accessor :options, :runner, :runner_thread + + public def initialize(options = {}) - @running = true - @options = OpenStruct.new({ :host => "127.0.0.1", - :port => 9399, - :worker_port => 9400, - :delay => 0, - :server => Protobuf::Rpc::Socket::Server }.merge(options)) + self.options = OpenStruct.new( + options.reverse_merge( + :host => '127.0.0.1', + :port => 9399, + :worker_port => 9400, + :delay => 0, + :server => Protobuf::Rpc::Socket::Server, + ), + ) start yield self ensure - stop if @running + stop end def start - case - when @options.server == Protobuf::Rpc::Zmq::Server - start_zmq_server - else - start_socket_server - end - logger.debug { sign_message("Server started #{@options.host}:#{@options.port}") } - end + runner_class = { + ::Protobuf::Rpc::Zmq::Server => ::Protobuf::Rpc::ZmqRunner, + ::Protobuf::Rpc::Socket::Server => ::Protobuf::Rpc::SocketRunner, + }.fetch(options.server) - def start_socket_server - @sock_runner = ::Protobuf::Rpc::SocketRunner.new(options) - @sock_thread = Thread.new(@sock_runner) { |runner| runner.run } - @sock_thread.abort_on_exception = true # Set for testing purposes - Thread.pass until @sock_runner.running? - end + self.runner = runner_class.new(options) + self.runner_thread = Thread.new(runner, &:run) + runner_thread.abort_on_exception = true # Set for testing purposes + Thread.pass until runner.running? - def start_zmq_server - @zmq_runner = ::Protobuf::Rpc::ZmqRunner.new(options) - @zmq_thread = Thread.new(@zmq_runner) { |runner| runner.run } - @zmq_thread.abort_on_exception = true # Set for testing purposes - Thread.pass until @zmq_runner.running? + logger.debug { sign_message("Server started #{options.host}:#{options.port}") } end def stop - case - when @options.server == Protobuf::Rpc::Zmq::Server then - @zmq_runner.try :stop - @zmq_thread.join if @zmq_thread - else - @sock_runner.stop - @sock_thread.join if @sock_thread - end - - @running = false + runner.stop + runner_thread.join end def log_signature From 37119ca2ee962b8f4f143aa0300f7422648ac2b9 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 01:36:21 -0800 Subject: [PATCH 183/298] Other rubies need pry too --- protobuf.gemspec | 2 ++ 1 file changed, 2 insertions(+) diff --git a/protobuf.gemspec b/protobuf.gemspec index 463c0224..e2b4b5df 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -43,6 +43,8 @@ require "protobuf/version" s.add_development_dependency pry_debugger s.add_development_dependency 'pry-stack_explorer' + else + s.add_development_dependency 'pry' end s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby From 4cbb1f7cb98bb5a63875f4fc0cdf0c8109feffa7 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 01:22:25 -0800 Subject: [PATCH 184/298] Remove useless ivars --- lib/protobuf/cli.rb | 57 ++++++++++++----------- lib/protobuf/code_generator.rb | 16 ++++--- lib/protobuf/encoder.rb | 10 +++- lib/protobuf/enum.rb | 14 ++++-- lib/protobuf/rpc/servers/socket_runner.rb | 16 +++++-- 5 files changed, 68 insertions(+), 45 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 222a55de..3fe340bf 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -11,7 +11,11 @@ class CLI < ::Thor include ::Thor::Actions include ::Protobuf::Logging - attr_accessor :runner, :mode + attr_accessor :runner, :mode, :exit_requested + + no_commands do + alias_method :exit_requested?, :exit_requested + end default_task :start @@ -102,27 +106,28 @@ def configure_logger # Re-write the $0 var to have a nice process name in ps. def configure_process_name(app_file) debug_say('Configuring process name') - $0 = "rpc_server --#{@runner_mode} #{options.host}:#{options.port} #{app_file}" + $0 = "rpc_server --#{mode} #{options.host}:#{options.port} #{app_file}" end # Configure the mode of the server and the runner class. def configure_runner_mode debug_say('Configuring runner mode') - if multi_mode? + self.mode = if multi_mode? say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow) - @runner_mode = :socket + :socket elsif options.zmq? - @runner_mode = :zmq - else + :zmq + else # rubocop:disable Style/ElseAlignment + # above: https://github.com/bbatsov/rubocop/pull/1470/files case server_type = ENV["PB_SERVER_TYPE"] when nil, /socket/i - @runner_mode = :socket + :socket when /zmq/i - @runner_mode = :zmq + :zmq else say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow - @runner_mode = :socket + :socket end end end @@ -139,7 +144,7 @@ def configure_traps debug_say("Registering trap for exit signal #{signal}", :blue) trap(signal) do - @exit_requested = true + self.exit_requested = true shutdown_server end end @@ -147,15 +152,15 @@ def configure_traps # Create the runner for the configured mode def create_runner - debug_say("Creating #{@runner_mode} runner") - @runner = case @runner_mode - when :zmq - create_zmq_runner - when :socket - create_socket_runner - else - say_and_exit("Unknown runner mode: #{@runner_mode}") - end + debug_say("Creating #{mode} runner") + self.runner = case mode + when :zmq + create_zmq_runner + when :socket + create_socket_runner + else + say_and_exit("Unknown runner mode: #{mode}") + end end # Say something if we're in debug mode. @@ -163,10 +168,6 @@ def debug_say(message, color = :yellow) say(message, color) if options.debug? end - def exit_requested? - !!@exit_requested - end - # Internal helper to determine if the modes are multi-set which is not valid. def multi_mode? options.zmq? && options.socket? @@ -207,18 +208,18 @@ def say_and_exit(message, exception = nil) def create_socket_runner require 'protobuf/socket' - @runner = ::Protobuf::Rpc::SocketRunner.new(runner_options) + self.runner = ::Protobuf::Rpc::SocketRunner.new(runner_options) end def create_zmq_runner require 'protobuf/zmq' - @runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options) + self.runner = ::Protobuf::Rpc::ZmqRunner.new(runner_options) end def shutdown_server logger.info { 'RPC Server shutting down...' } - @runner.try(:stop) + runner.stop ::Protobuf::Rpc::ServiceDirectory.instance.stop end @@ -226,9 +227,9 @@ def shutdown_server def start_server debug_say('Running server') - @runner.run do + runner.run do logger.info do - "pid #{::Process.pid} -- #{@runner_mode} RPC Server listening at #{options.host}:#{options.port}" + "pid #{::Process.pid} -- #{mode} RPC Server listening at #{options.host}:#{options.port}" end ::ActiveSupport::Notifications.instrument("after_server_bind") diff --git a/lib/protobuf/code_generator.rb b/lib/protobuf/code_generator.rb index cf39b0df..3ab75b72 100644 --- a/lib/protobuf/code_generator.rb +++ b/lib/protobuf/code_generator.rb @@ -18,22 +18,26 @@ def self.warn(message) STDERR.puts("[WARN] #{message}") end + private + + attr_accessor :request + + public + def initialize(request_bytes) - @request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes) - @generated_files = [] + self.request = ::Google::Protobuf::Compiler::CodeGeneratorRequest.decode(request_bytes) end def generate_file(file_descriptor) - file_generator = ::Protobuf::Generators::FileGenerator.new(file_descriptor) - @generated_files << file_generator.generate_output_file + ::Protobuf::Generators::FileGenerator.new(file_descriptor).generate_output_file end def response_bytes - @request.proto_file.each do |file_descriptor| + generated_files = request.proto_file.map do |file_descriptor| generate_file(file_descriptor) end - ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => @generated_files) + ::Google::Protobuf::Compiler::CodeGeneratorResponse.encode(:file => generated_files) end end diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 4c19ab08..d9d19a26 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -5,6 +5,12 @@ def self.encode(stream, message) new(stream, message).encode end + private + + attr_writer :message, :stream + + public + attr_reader :message, :stream def initialize(message, stream) @@ -12,8 +18,8 @@ def initialize(message, stream) fail ArgumentError, "Message instance must respond to :each_field_for_serialization" end - @message = message - @stream = stream + self.message = message + self.stream = stream end def encode diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 16d414ab..3fc171ac 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -229,6 +229,12 @@ class << self # Attributes # + private + + attr_writer :parent_class, :name, :tag + + public + attr_reader :parent_class, :name, :tag ## @@ -236,10 +242,10 @@ class << self # def initialize(parent_class, name, tag) - @parent_class = parent_class - @name = name - @tag = tag - super(@tag) + self.parent_class = parent_class + self.name = name + self.tag = tag + super(tag) end # Overriding the class so ActiveRecord/Arel visitor will visit the enum as a Fixnum diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index e81159aa..782ae70e 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -2,8 +2,14 @@ module Protobuf module Rpc class SocketRunner + private + + attr_accessor :server + + public + def initialize(options) - @options = case + options = case when options.is_a?(OpenStruct) then options.marshal_dump when options.is_a?(Hash) then @@ -14,20 +20,20 @@ def initialize(options) fail "Cannot parser Socket Server - server options" end - @server = ::Protobuf::Rpc::Socket::Server.new(@options) + self.server = ::Protobuf::Rpc::Socket::Server.new(options) end def run yield if block_given? - @server.run + server.run end def running? - @server.running? + server.running? end def stop - @server.stop + server.stop end end end From 76b4aac4096a420b57539b515b48b02fe5456c13 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 02:20:27 -0800 Subject: [PATCH 185/298] Specs pass under JRuby now! --- .travis.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 61185537..1f98e3da 100644 --- a/.travis.yml +++ b/.travis.yml @@ -11,7 +11,6 @@ rvm: - rbx-2 matrix: allow_failures: - - rvm: jruby - rvm: rbx-2 notifications: webhooks: From 9a46d8098ff322372b853c029e0ca8c4942b2fc1 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Dec 2014 11:16:06 -0700 Subject: [PATCH 186/298] don't memoize the @stats on a client --- lib/protobuf/rpc/connectors/common.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index b0795787..f5067b75 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -52,7 +52,7 @@ def failure(code, message) end def initialize_stats - @stats ||= ::Protobuf::Rpc::Stat.new(:CLIENT) + @stats = ::Protobuf::Rpc::Stat.new(:CLIENT) @stats.server = [@options[:port], @options[:host]] @stats.service = @options[:service].name @stats.method_name = @options[:method].to_s From 4bd3ae88cbc86c21a5026f4e53cb8f279a8a6f1c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Dec 2014 16:54:10 -0700 Subject: [PATCH 187/298] make rubocop happy --- lib/protobuf/rpc/connectors/zmq.rb | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index fef8489d..b3b2dc26 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -121,15 +121,15 @@ def host_alive_check_interval # def lookup_server_uri server_lookup_attempts.times do - service_directory.all_listings_for(service).each do |listing| - host = listing.try(:address) - port = listing.try(:port) - - if host_alive?(host) - # @stats from Common, need to get a better public interface for it - @stats.server = [port, host] - return "tcp://#{host}:#{port}" - end + first_alive_listing = service_directory.all_listings_for(service).find do |listing| + host_alive?(listing.try(:address)) + end + + if first_alive_listing + host = first_alive_listing.try(:address) + port = first_alive_listing.try(:port) + @stats.server = [port, host] + return "tcp://#{host}:#{port}" end host = options[:host] From f0023e517ad0a810e2d0c737180c19c607231424 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 4 Dec 2014 13:49:19 -0700 Subject: [PATCH 188/298] bump to 3.4.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 8dfbb929..41df5a37 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.3.6' + VERSION = '3.4.0' end From fb70f1fd9a3e1585946892010d371db2d7f132da Mon Sep 17 00:00:00 2001 From: Igor Kapkov Date: Fri, 5 Dec 2014 18:36:26 +0800 Subject: [PATCH 189/298] Start using svg in readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 3e0e7ead..7bdd0f2e 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # protobuf -[![Gem Version](https://badge.fury.io/rb/protobuf.png)](http://badge.fury.io/rb/protobuf) -[![Build Status](https://secure.travis-ci.org/localshred/protobuf.png?branch=master)](https://travis-ci.org/localshred/protobuf) -[![Gitter chat](https://badges.gitter.im/localshred/protobuf.png)](https://gitter.im/localshred/protobuf) +[![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf) +[![Build Status](https://secure.travis-ci.org/localshred/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) +[![Gitter chat](https://badges.gitter.im/localshred/protobuf.svg)](https://gitter.im/localshred/protobuf) Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. From c1055b4399697b6b32a80c2a20355a2466ce6831 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 9 Dec 2014 00:45:22 -0700 Subject: [PATCH 190/298] reset the zmq socket inside the loop block to prevent infinite loop when context returns nil instead of socket --- lib/protobuf/rpc/connectors/zmq.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index b3b2dc26..9c561894 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -74,9 +74,9 @@ def close_connection # service. The LINGER is set to 0 so we can close immediately in # the event of a timeout def create_socket - socket = zmq_context.socket(::ZMQ::REQ) - begin + socket = zmq_context.socket(::ZMQ::REQ) + if socket # Make sure the context builds the socket server_uri = lookup_server_uri socket.setsockopt(::ZMQ::LINGER, 0) From 34ce9245b909d022a6af2615881faeef239863db Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 9 Dec 2014 00:46:54 -0700 Subject: [PATCH 191/298] bump to 3.4.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 41df5a37..f21b2565 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.4.0' + VERSION = '3.4.1' end From 5d6df9de2a94907c5bac0a280435d343a2d8af91 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 2 Dec 2014 12:50:58 -0800 Subject: [PATCH 192/298] Fix deprecation warning logic - `ENV['PB_IGNORE_DEPRECATIONS']` now only controls field deprecations, as indicated in the documentation. Protobuf internal deprecations are always printed. - Field deprecations now only print when the field is actually deprecated, and provide a more useful message. --- lib/protobuf.rb | 11 +++++++++-- lib/protobuf/deprecation.rb | 27 +++++++++++++++++++++++++-- lib/protobuf/field/base_field.rb | 12 ++++++++---- lib/protobuf/field/bool_field.rb | 6 +----- lib/protobuf/field/bytes_field.rb | 4 ++-- 5 files changed, 45 insertions(+), 15 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 7a8d3c12..04b5c9ba 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -71,6 +71,13 @@ def self.deprecator end end + def self.field_deprecator + @field_deprecator ||= FieldDeprecation.new.tap do |deprecation| + deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') + deprecation.behavior = :stderr + end + end + # Print Deprecation Warnings # # Default: true @@ -82,11 +89,11 @@ def self.deprecator # # The rpc_server option will override the ENV setting. def self.print_deprecation_warnings? - !deprecator.silenced + !field_deprecator.silenced end def self.print_deprecation_warnings=(value) - deprecator.silenced = !value + field_deprecator.silenced = !value end # Permit unknown field on Message initialization diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index 24cad832..088519da 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -1,12 +1,21 @@ require 'active_support/deprecation' module Protobuf - class Deprecation < ::ActiveSupport::Deprecation + class DeprecationBase < ::ActiveSupport::Deprecation def deprecate_methods(*args) - args.last.merge!(:deprecator => self) if args.last.is_a?(Hash) + deprecation_options = { :deprecator => self } + + if args.last.is_a?(Hash) + args.last.merge!(deprecation_options) + else + args.push(deprecation_options) + end + super end + end + class Deprecation < DeprecationBase def define_deprecated_methods(target_module, method_hash) target_module.module_eval do method_hash.each do |old_method, new_method| @@ -17,4 +26,18 @@ def define_deprecated_methods(target_module, method_hash) deprecate_methods(target_module, method_hash) end end + + class FieldDeprecation < DeprecationBase + # this is a convenience deprecator for deprecated proto fields + + def deprecate_method(target_module, method_name) + deprecate_methods(target_module, method_name => target_module) + end + + private + + def deprecated_method_warning(method_name, target_module) + "#{target_module.name}##{method_name} field usage is deprecated" + end + end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 85cbc90a..440bbd72 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -183,8 +183,9 @@ def define_array_getter define_method(method_name) do @values[field.name] ||= ::Protobuf::Field::FieldArray.new(field) end - ::Protobuf.deprecator.deprecate_methods(method_name) end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end def define_array_setter @@ -210,8 +211,9 @@ def define_array_setter @values[field.name].replace(val) end end - ::Protobuf.deprecator.deprecate_methods(method_name) end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end def define_getter @@ -222,8 +224,9 @@ def define_getter define_method(method_name) do @values.fetch(field.name, field.default_value) end - ::Protobuf.deprecator.deprecate_methods(method_name) end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end def define_setter @@ -240,8 +243,9 @@ def define_setter fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end - ::Protobuf.deprecator.deprecate_methods(method_name) end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end def typed_default_value diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index a2534ef0..57f20906 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -38,13 +38,9 @@ def define_getter super field = self - method_name = "#{field.getter}?" message_class.class_eval do - define_method(method_name) do - @values.fetch(field.name, field.default_value) - end - ::Protobuf.deprecator.deprecate_methods(method_name) + alias_method "#{field.getter}?", field.getter end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index a943745c..851daee1 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -73,10 +73,10 @@ def define_setter raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" end end - ::Protobuf.deprecator.deprecate_methods(method_name) end - end + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? + end end end end From d4d414dff7ec77252083c491b66861b6ded0877d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Tue, 23 Dec 2014 08:22:26 -0800 Subject: [PATCH 193/298] Refresh RuboCop config --- .rubocop_todo.yml | 42 ++++++++++++++++++++++++++---------------- 1 file changed, 26 insertions(+), 16 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 463ec257..93749c19 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,11 +1,11 @@ # This configuration was generated by `rubocop --auto-gen-config` -# on 2014-11-24 09:44:26 -0800 using RuboCop version 0.27.1. +# on 2014-12-23 08:21:59 -0800 using RuboCop version 0.28.0. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 28 +# Offense count: 29 Metrics/AbcSize: Max: 59 @@ -13,60 +13,70 @@ Metrics/AbcSize: Metrics/BlockNesting: Max: 5 -# Offense count: 9 +# Offense count: 8 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 233 + Max: 232 # Offense count: 3 Metrics/CyclomaticComplexity: - Max: 11 + Max: 10 -# Offense count: 508 +# Offense count: 491 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 196 -# Offense count: 48 +# Offense count: 43 # Configuration parameters: CountComments. Metrics/MethodLength: - Max: 45 + Max: 38 # Offense count: 2 # Configuration parameters: CountKeywordArgs. Metrics/ParameterLists: Max: 6 -# Offense count: 2 +# Offense count: 3 Metrics/PerceivedComplexity: - Max: 12 + Max: 11 -# Offense count: 216 +# Offense count: 189 Style/Documentation: Enabled: false -# Offense count: 15 +# Offense count: 12 Style/DoubleNegation: Enabled: false -# Offense count: 100 +# Offense count: 2 +Style/EmptyElse: + Enabled: false + +# Offense count: 73 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +Style/EmptyLinesAroundBlockBody: + Enabled: false + +# Offense count: 90 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/EmptyLinesAroundClassBody: Enabled: false -# Offense count: 66 +# Offense count: 50 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/EmptyLinesAroundModuleBody: Enabled: false -# Offense count: 53 +# Offense count: 46 # Cop supports --auto-correct. Style/NumericLiterals: MinDigits: 21 -# Offense count: 464 +# Offense count: 463 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/StringLiterals: From 5be7e59990937ee5eaf61ff18101eb0cf02fec17 Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Thu, 18 Dec 2014 14:49:59 -0800 Subject: [PATCH 194/298] Restore Rails 3.2 compatibility Closes #239. --- lib/protobuf.rb | 32 ---------- lib/protobuf/deprecation.rb | 115 ++++++++++++++++++++++++++++-------- 2 files changed, 92 insertions(+), 55 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 04b5c9ba..18564148 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -64,38 +64,6 @@ def self.gc_pause_server_request=(value) @gc_pause_server_request = !!value end - def self.deprecator - @deprecator ||= Deprecation.new('4.0', to_s).tap do |deprecation| - deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') - deprecation.behavior = :stderr - end - end - - def self.field_deprecator - @field_deprecator ||= FieldDeprecation.new.tap do |deprecation| - deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') - deprecation.behavior = :stderr - end - end - - # Print Deprecation Warnings - # - # Default: true - # - # Simple boolean to define whether we want field deprecation warnings to - # be printed to stderr or not. The rpc_server has an option to set this value - # explicitly, or you can turn this option off by setting - # ENV['PB_IGNORE_DEPRECATIONS'] to a non-empty value. - # - # The rpc_server option will override the ENV setting. - def self.print_deprecation_warnings? - !field_deprecator.silenced - end - - def self.print_deprecation_warnings=(value) - field_deprecator.silenced = !value - end - # Permit unknown field on Message initialization # # Default: true diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index 088519da..eac6e4b1 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -1,43 +1,112 @@ require 'active_support/deprecation' module Protobuf - class DeprecationBase < ::ActiveSupport::Deprecation - def deprecate_methods(*args) - deprecation_options = { :deprecator => self } + if ::ActiveSupport::Deprecation.is_a?(Class) + class DeprecationBase < ::ActiveSupport::Deprecation + def deprecate_methods(*args) + deprecation_options = { :deprecator => self } - if args.last.is_a?(Hash) - args.last.merge!(deprecation_options) - else - args.push(deprecation_options) + if args.last.is_a?(Hash) + args.last.merge!(deprecation_options) + else + args.push(deprecation_options) + end + + super end + end - super + class Deprecation < DeprecationBase + def define_deprecated_methods(target_module, method_hash) + target_module.module_eval do + method_hash.each do |old_method, new_method| + alias_method old_method, new_method + end + end + + deprecate_methods(target_module, method_hash) + end end - end - class Deprecation < DeprecationBase - def define_deprecated_methods(target_module, method_hash) - target_module.module_eval do - method_hash.each do |old_method, new_method| - alias_method old_method, new_method + class FieldDeprecation < DeprecationBase + # this is a convenience deprecator for deprecated proto fields + + def deprecate_method(target_module, method_name) + deprecate_methods(target_module, method_name => target_module) + end + + private + + def deprecated_method_warning(method_name, target_module) + "#{target_module.name}##{method_name} field usage is deprecated" + end + end + else + # TODO: remove this clause when Rails < 4 support is no longer needed + deprecator = ::ActiveSupport::Deprecation.clone + deprecator.instance_eval do + def new(deprecation_horizon = nil, *) + self.deprecation_horizon = deprecation_horizon if deprecation_horizon + self + end + end + Deprecation = deprecator.clone + FieldDeprecation = deprecator.clone + + Deprecation.instance_eval do + def define_deprecated_methods(target_module, method_hash) + target_module.module_eval do + method_hash.each do |old_method, new_method| + alias_method old_method, new_method + end end + + deprecate_methods(target_module, method_hash) end + end + + FieldDeprecation.instance_eval do + def deprecate_method(target_module, method_name) + deprecate_methods(target_module, method_name => target_module) + end + + private - deprecate_methods(target_module, method_hash) + def deprecated_method_warning(method_name, target_module) + "#{target_module.name}##{method_name} field usage is deprecated" + end end end - class FieldDeprecation < DeprecationBase - # this is a convenience deprecator for deprecated proto fields + def self.deprecator + @deprecator ||= Deprecation.new('4.0', to_s).tap do |deprecation| + deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') + deprecation.behavior = :stderr + end + end - def deprecate_method(target_module, method_name) - deprecate_methods(target_module, method_name => target_module) + def self.field_deprecator + @field_deprecator ||= FieldDeprecation.new.tap do |deprecation| + deprecation.silenced = ENV.key?('PB_IGNORE_DEPRECATIONS') + deprecation.behavior = :stderr end + end - private + # Print Deprecation Warnings + # + # Default: true + # + # Simple boolean to define whether we want field deprecation warnings to + # be printed to stderr or not. The rpc_server has an option to set this value + # explicitly, or you can turn this option off by setting + # ENV['PB_IGNORE_DEPRECATIONS'] to a non-empty value. + # + # The rpc_server option will override the ENV setting. + def self.print_deprecation_warnings? + !field_deprecator.silenced + end - def deprecated_method_warning(method_name, target_module) - "#{target_module.name}##{method_name} field usage is deprecated" - end + def self.print_deprecation_warnings=(value) + field_deprecator.silenced = !value end end From 09f2193ac723001e43f8e5eada93791441924d42 Mon Sep 17 00:00:00 2001 From: Brian Ferris Date: Mon, 5 Jan 2015 21:06:40 -0800 Subject: [PATCH 195/298] Support for Foo::SomeMessage.decode_from(stream) The Serialization documentation: https://github.com/localshred/protobuf/wiki/Serialization implies that the following idioms should work for decoding an object: Foo::User.decode(bytes) Foo::User.decode_from(stream) However, in practice, decode_from(...) only seems to be supported as an instance method, not a class method. By comparison, decode(...) is supported as both an instance method and a class method. Let's fix that. --- lib/protobuf/message/serialization.rb | 4 ++++ spec/lib/protobuf/message_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 5850b5a6..5528c10a 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -11,6 +11,10 @@ def decode(bytes) new.decode(bytes) end + def decode_from(stream) + new.decode_from(stream) + end + # Create a new object with the given values and return the encoded bytes. def encode(fields = {}) new(fields).encode diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 052b570e..e6ff7b96 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -1,5 +1,6 @@ # encoding: utf-8 +require 'stringio' require 'spec_helper' RSpec.describe Protobuf::Message do @@ -71,6 +72,15 @@ end end + describe '.decode_from' do + let(:message) { ::Test::Resource.new(:name => "Jim") } + + it 'creates a new message object decoded from the given byte stream' do + stream = ::StringIO.new(message.encode) + expect(::Test::Resource.decode_from(stream)).to eq message + end + end + describe 'defining a new field' do context 'when defining a field with a tag that has already been used' do it 'raises a TagCollisionError' do From b21661bddabcff1a16494aa5346ed35d922a2a08 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Jan 2015 20:27:16 -0700 Subject: [PATCH 196/298] make snd and rcv timeout on check avail actually work with env vars add functionality to recover from broker exception or not starting up correctly, will now wait for broker to start and will restart on crash --- lib/protobuf/rpc/connectors/zmq.rb | 18 ++++++++++++-- lib/protobuf/rpc/servers/zmq/broker.rb | 4 +++- lib/protobuf/rpc/servers/zmq/server.rb | 33 +++++++++++++++----------- lib/protobuf/rpc/servers/zmq/worker.rb | 5 ++-- 4 files changed, 41 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 9c561894..0059c07d 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -59,11 +59,25 @@ def send_request # Private Instance methods # def check_available_rcv_timeout - @check_available_rcv_timeout ||= [ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_RCV_TIMEOUT"].to_i, 200].max + @check_available_rcv_timeout ||= begin + case + when ENV.key?("PB_ZMQ_CLIENT_CHECK_AVAILABLE_RCV_TIMEOUT") then + ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_RCV_TIMEOUT"].to_i + else + 200 # ms + end + end end def check_available_snd_timeout - @check_available_snd_timeout ||= [ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_SND_TIMEOUT"].to_i, 200].max + @check_available_snd_timeout ||= begin + case + when ENV.key?("PB_ZMQ_CLIENT_CHECK_AVAILABLE_SND_TIMEOUT") then + ENV["PB_ZMQ_CLIENT_CHECK_AVAILABLE_SND_TIMEOUT"].to_i + else + 200 # ms + end + end end def close_connection diff --git a/lib/protobuf/rpc/servers/zmq/broker.rb b/lib/protobuf/rpc/servers/zmq/broker.rb index abb2ccad..84017e57 100644 --- a/lib/protobuf/rpc/servers/zmq/broker.rb +++ b/lib/protobuf/rpc/servers/zmq/broker.rb @@ -23,6 +23,7 @@ def initialize(server) def run @idle_workers = [] + @running = true loop do process_local_queue @@ -39,10 +40,11 @@ def run end ensure teardown + @running = false end def running? - @server.running? + @running && @server.running? end private diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index bd187ffb..df6be786 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -76,6 +76,10 @@ def broadcast_beacons? !brokerless? && options[:broadcast_beacons] end + def broadcast_busy? + broadcast_beacons? && options[:broadcast_busy] + end + def broadcast_flatline flatline = ::Protobuf::Rpc::DynamicDiscovery::Beacon.new( :beacon_type => ::Protobuf::Rpc::DynamicDiscovery::BeaconType::FLATLINE, @@ -176,15 +180,11 @@ def reaping_interval def run @running = true - - start_broker unless brokerless? - start_missing_workers - yield if block_given? # runs on startup wait_for_shutdown_signal broadcast_flatline if broadcast_beacons? Thread.pass until reap_dead_workers.empty? - @broker.join unless brokerless? + @broker_thread.join unless brokerless? ensure @running = false teardown @@ -246,14 +246,13 @@ def wait_for_shutdown_signal loop do break if IO.select([@shutdown_r], nil, nil, timeout) - if reap_dead_workers? - reap_dead_workers - start_missing_workers - end + start_broker unless brokerless? + reap_dead_workers if reap_dead_workers? + start_missing_workers next unless broadcast_heartbeat? - if options[:broadcast_busy] && all_workers_busy? + if broadcast_busy? && all_workers_busy? broadcast_flatline else broadcast_heartbeat @@ -285,15 +284,21 @@ def init_zmq_context end def start_broker - @broker = Thread.new(self) do |server| - ::Protobuf::Rpc::Zmq::Broker.new(server).run + return if @broker && @broker.running? && !@broker_thread.stop? + broadcast_flatline if broadcast_busy? + @broker = ::Protobuf::Rpc::Zmq::Broker.new(self) + + @broker_thread = Thread.new(@broker) do |broker| + broker.run end + + ::Thread.pass until @broker.running? end def start_worker - @workers << Thread.new(self) do |server| + @workers << Thread.new(self, @broker) do |server, broker| begin - ::Protobuf::Rpc::Zmq::Worker.new(server).run + ::Protobuf::Rpc::Zmq::Worker.new(server, broker).run rescue => e message = "Worker failed: #{e.inspect}\n #{e.backtrace.join($INPUT_RECORD_SEPARATOR)}" $stderr.puts(message) diff --git a/lib/protobuf/rpc/servers/zmq/worker.rb b/lib/protobuf/rpc/servers/zmq/worker.rb index 63f1df3c..cf606615 100644 --- a/lib/protobuf/rpc/servers/zmq/worker.rb +++ b/lib/protobuf/rpc/servers/zmq/worker.rb @@ -12,8 +12,9 @@ class Worker ## # Constructor # - def initialize(server) + def initialize(server, broker) @server = server + @broker = broker init_zmq_context init_backend_socket @@ -61,7 +62,7 @@ def run end def running? - @server.running? + @broker.running? && @server.running? end private From cd3964c06bdd5fcb53ddf2013ea4ea7131d13cb3 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Jan 2015 20:33:47 -0700 Subject: [PATCH 197/298] catch and report if error in broker thread --- lib/protobuf/rpc/servers/zmq/server.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index df6be786..1333bb4f 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -289,7 +289,13 @@ def start_broker @broker = ::Protobuf::Rpc::Zmq::Broker.new(self) @broker_thread = Thread.new(@broker) do |broker| - broker.run + begin + broker.run + rescue => e + message = "Broker failed: #{e.inspect}\n #{e.backtrace.join($INPUT_RECORD_SEPARATOR)}" + $stderr.puts(message) + logger.error { message } + end end ::Thread.pass until @broker.running? From 10bcc3b877767ea303ae593b13aa84aa427c078c Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 15 Jan 2015 22:02:52 -0700 Subject: [PATCH 198/298] restart context and join broker thread if broker dies --- lib/protobuf/rpc/servers/zmq/server.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 1333bb4f..83e21d2d 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -285,9 +285,13 @@ def init_zmq_context def start_broker return if @broker && @broker.running? && !@broker_thread.stop? - broadcast_flatline if broadcast_busy? - @broker = ::Protobuf::Rpc::Zmq::Broker.new(self) + if @broker && !@broker.running? + broadcast_flatline if broadcast_busy? + @broker_thread.join if @broker_thread + init_zmq_context # need a new context to restart the broker + end + @broker = ::Protobuf::Rpc::Zmq::Broker.new(self) @broker_thread = Thread.new(@broker) do |broker| begin broker.run @@ -297,8 +301,6 @@ def start_broker logger.error { message } end end - - ::Thread.pass until @broker.running? end def start_worker From b9fb942f3fa33ac1bb7c38e0de980e60951562aa Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 16 Jan 2015 09:17:45 -0700 Subject: [PATCH 199/298] disable Metrics/ClassLength in rubocop --- .rubocop.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index a2e37f1f..c4311848 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -6,6 +6,9 @@ Lint/EndAlignment: Lint/Loop: Enabled: false +Metrics/ClassLength: + Enabled: false + Style/CaseIndentation: IndentWhenRelativeTo: end From 9eb9520ab8dc8240622c9af3f4c2a8d65961b4a3 Mon Sep 17 00:00:00 2001 From: Adam Greene Date: Mon, 2 Feb 2015 12:45:36 -0800 Subject: [PATCH 200/298] allow Protobuf::Message based classes to be inherited --- lib/protobuf/message/fields.rb | 168 ++++++++++++---------- spec/functional/class_inheritance_spec.rb | 52 +++++++ 2 files changed, 143 insertions(+), 77 deletions(-) create mode 100644 spec/functional/class_inheritance_spec.rb diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index eea33128..5b081ffc 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -3,6 +3,7 @@ class Message module Fields def self.extended(other) + other.extend(ClassMethods) ::Protobuf.deprecator.define_deprecated_methods( other.singleton_class, :get_ext_field_by_name => :get_extension_field, @@ -10,110 +11,123 @@ def self.extended(other) :get_field_by_name => :get_field, :get_field_by_tag => :get_field, ) + + def inherited(subclass) + inherit_fields!(subclass) + end end - ## - # Field Definition Methods - # + module ClassMethods - # Define an optional field. - # - def optional(type_class, name, tag, options = {}) - define_field(:optional, type_class, name, tag, options) - end + ## + # Field Definition Methods + # - # Define a repeated field. - # - def repeated(type_class, name, tag, options = {}) - define_field(:repeated, type_class, name, tag, options) - end + # Define an optional field. + # + def optional(type_class, name, tag, options = {}) + define_field(:optional, type_class, name, tag, options) + end - # Define a required field. - # - def required(type_class, name, tag, options = {}) - define_field(:required, type_class, name, tag, options) - end + # Define a repeated field. + # + def repeated(type_class, name, tag, options = {}) + define_field(:repeated, type_class, name, tag, options) + end - # Define an extension range. - # - def extensions(range) - extension_ranges << range - end + # Define a required field. + # + def required(type_class, name, tag, options = {}) + define_field(:required, type_class, name, tag, options) + end - ## - # Field Access Methods - # + # Define an extension range. + # + def extensions(range) + extension_ranges << range + end - def all_fields - @all_fields ||= field_store.values.uniq.sort_by(&:tag) - end + ## + # Field Access Methods + # + def all_fields + @all_fields ||= field_store.values.uniq.sort_by(&:tag) + end - def extension_fields - @extension_fields ||= all_fields.select(&:extension?) - end + def extension_fields + @extension_fields ||= all_fields.select(&:extension?) + end - def extension_ranges - @extension_ranges ||= [] - end + def extension_ranges + @extension_ranges ||= [] + end - def extension_tag?(tag) - tag.respond_to?(:to_i) && get_extension_field(tag).present? - end + def extension_tag?(tag) + tag.respond_to?(:to_i) && get_extension_field(tag).present? + end - def field_store - @field_store ||= {} - end + def field_store + @field_store ||= {} + end - def fields - @fields ||= all_fields.reject(&:extension?) - end + def fields + @fields ||= all_fields.reject(&:extension?) + end - def field_tag?(tag, allow_extension = false) - tag.respond_to?(:to_i) && get_field(tag, allow_extension).present? - end + def field_tag?(tag, allow_extension = false) + tag.respond_to?(:to_i) && get_field(tag, allow_extension).present? + end - def get_extension_field(name_or_tag) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] - field if field.try(:extension?) { false } - end + def get_extension_field(name_or_tag) + name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) + field = field_store[name_or_tag] + field if field.try(:extension?) { false } + end - def get_field(name_or_tag, allow_extension = false) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] + def get_field(name_or_tag, allow_extension = false) + name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) + field = field_store[name_or_tag] - if field && (allow_extension || !field.extension?) - field - else - nil + if field && (allow_extension || !field.extension?) + field + else + nil + end end - end - def define_field(rule, type_class, field_name, tag, options) - raise_if_tag_collision(tag, field_name) - raise_if_name_collision(field_name) + def define_field(rule, type_class, field_name, tag, options) + raise_if_tag_collision(tag, field_name) + raise_if_name_collision(field_name) - field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) - field_store[field_name] = field - field_store[tag] = field + field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) + field_store[field_name] = field + field_store[tag] = field - define_method("#{field_name}!") do - @values[field_name] + define_method("#{field_name}!") do + @values[field_name] + end end - end - def raise_if_tag_collision(tag, field_name) - if get_field(tag, true) - fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) + def raise_if_tag_collision(tag, field_name) + if get_field(tag, true) + fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) + end end - end - def raise_if_name_collision(field_name) - if get_field(field_name, true) - fail DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) + def raise_if_name_collision(field_name) + if get_field(field_name, true) + fail DuplicateFieldNameError, %(Field name #{field_name} has already been used in "#{name}".) + end end - end + def inherit_fields!(subclass) + instance_variables.each do |iv| + subclass.instance_variable_set(iv, instance_variable_get(iv)) + end + end + private :inherit_fields! + + end end end end diff --git a/spec/functional/class_inheritance_spec.rb b/spec/functional/class_inheritance_spec.rb new file mode 100644 index 00000000..513d7210 --- /dev/null +++ b/spec/functional/class_inheritance_spec.rb @@ -0,0 +1,52 @@ +require 'spec_helper' +require 'spec/support/test/resource_service' + +RSpec.describe 'works through class inheritance' do + module Corp + module Protobuf + class Error < ::Protobuf::Message + required :string, :foo, 1 + end + end + end + module Corp + class ErrorHandler < Corp::Protobuf::Error + end + end + + let(:args) { { :foo => 'bar' } } + let(:parent_class) { Corp::Protobuf::Error } + let(:inherited_class) { Corp::ErrorHandler } + + specify '#encode' do + expected_result = "\n\x03bar" + expected_result.force_encoding(Encoding::BINARY) + expect(parent_class.new(args).encode).to eq(expected_result) + expect(inherited_class.new(args).encode).to eq(expected_result) + end + + specify '#to_hash' do + expect(parent_class.new(args).to_hash).to eq(args) + expect(inherited_class.new(args).to_hash).to eq(args) + end + + specify '#to_json' do + expect(parent_class.new(args).to_json).to eq(args.to_json) + expect(inherited_class.new(args).to_json).to eq(args.to_json) + end + + specify '.encode' do + expected_result = "\n\x03bar" + expected_result.force_encoding(Encoding::BINARY) + expect(parent_class.encode(args)).to eq(expected_result) + expect(inherited_class.encode(args)).to eq(expected_result) + end + + specify '.decode' do + raw_value = "\n\x03bar" + raw_value.force_encoding(Encoding::BINARY) + expect(parent_class.decode(raw_value).to_hash).to eq(args) + expect(inherited_class.decode(raw_value).to_hash).to eq(args) + end + +end From c3cb5f9d49cd5b75860e3197acc206afe411ca4d Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Feb 2015 21:45:22 -0700 Subject: [PATCH 201/298] Bump version 3.4.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index f21b2565..86b92f42 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.4.1' + VERSION = '3.4.4' end From bf3729bc582406c5591af21089334dccf023eaf7 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Feb 2015 22:03:55 -0700 Subject: [PATCH 202/298] Trying to get rubocop to shut the fuck up --- spec/lib/protobuf/message_spec.rb | 2 +- spec/lib/protobuf/rpc/service_directory_spec.rb | 4 +--- spec/lib/protobuf/rpc/stat_spec.rb | 4 +--- 3 files changed, 3 insertions(+), 7 deletions(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e6ff7b96..e645c355 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -401,7 +401,7 @@ it 'does not populate default values' do hash = Test::EnumTestMessage.new.to_hash - expect(hash).to eq(Hash.new) + expect(hash).to eq({}) end it 'converts repeated enum fields to an array of the tags' do diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index ea039ec8..c15af6a3 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -57,9 +57,7 @@ def expect_event_trigger(event) expect(::ActiveSupport::Notifications).to receive(:instrument) - .with(event, hash_including( - :listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing), - )).once + .with(event, hash_including(:listing => an_instance_of(::Protobuf::Rpc::ServiceDirectory::Listing))).once end def send_beacon(type, server) diff --git a/spec/lib/protobuf/rpc/stat_spec.rb b/spec/lib/protobuf/rpc/stat_spec.rb index f23ce783..14c4556d 100644 --- a/spec/lib/protobuf/rpc/stat_spec.rb +++ b/spec/lib/protobuf/rpc/stat_spec.rb @@ -5,9 +5,7 @@ RSpec.describe ::Protobuf::Rpc::Stat do before(:all) do - unless defined?(BarService) - class BarService < ::Struct.new(:method_name); end - end + BarService = ::Struct.new(:method_name) unless defined?(BarService) end describe 'server mode' do From 65cc475c9ee0005809f3ab3e00aa0a59aeb56282 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Tue, 17 Feb 2015 22:14:06 -0700 Subject: [PATCH 203/298] Again, rubocop. I hate it --- spec/lib/protobuf/rpc/service_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/protobuf/rpc/service_spec.rb b/spec/lib/protobuf/rpc/service_spec.rb index 4c1fcf37..514f35e2 100644 --- a/spec/lib/protobuf/rpc/service_spec.rb +++ b/spec/lib/protobuf/rpc/service_spec.rb @@ -65,9 +65,9 @@ client = double('client') expect(::Protobuf::Rpc::Client).to receive(:new) .with(hash_including( - :service => subject, - :host => subject.host, - :port => subject.port, + :service => subject, + :host => subject.host, + :port => subject.port, )).and_return(client) expect(subject.client).to eq client end From 2ea42e846a429beed8de75a8d797164bafc11de8 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Thu, 19 Feb 2015 10:21:14 -0700 Subject: [PATCH 204/298] Add omniref doc badge --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 7bdd0f2e..2a7d16b1 100644 --- a/README.md +++ b/README.md @@ -3,6 +3,7 @@ [![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf) [![Build Status](https://secure.travis-ci.org/localshred/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) [![Gitter chat](https://badges.gitter.im/localshred/protobuf.svg)](https://gitter.im/localshred/protobuf) +[![protobuf API Documentation](https://www.omniref.com/ruby/gems/protobuf.png)](https://www.omniref.com/ruby/gems/protobuf) Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. From 12aa393d5d61a8125455a5e96bd19bfa8be126cd Mon Sep 17 00:00:00 2001 From: Richard Heycock Date: Fri, 27 Feb 2015 00:25:27 +1100 Subject: [PATCH 205/298] Allow the Message to be constructed with a block. Allow Messages to be constructed in the following manner: Protobuf::Message.new do |p| p.field = x ... end --- lib/protobuf/message.rb | 10 +++++++--- spec/lib/protobuf/message_spec.rb | 6 ++++++ 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index b024c957..32379824 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -26,11 +26,15 @@ def self.to_json # Constructor # - def initialize(fields = {}) + def initialize(fields = {}, &blk) @values = {} - fields.to_hash.each_pair do |name, value| - self[name] = value + if blk + blk.call(self) + else + fields.to_hash.each_pair do |name, value| + self[name] = value + end end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index e645c355..bd6c4909 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -175,6 +175,12 @@ expect(test_enum.non_default_enum).to eq(2) end + it "initializes with an object with a block" do + hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) + test_enum = Test::EnumTestMessage.new { |p| p.non_default_enum = 2 } + expect(test_enum.non_default_enum).to eq(2) + end + context 'ignoring unknown fields' do before { ::Protobuf.ignore_unknown_fields = true } From 216fe1fca473d4eb417c2d9ea0a3bb2d828fbc6c Mon Sep 17 00:00:00 2001 From: Richard Heycock Date: Fri, 27 Feb 2015 01:02:07 +1100 Subject: [PATCH 206/298] Remove unused variable. --- spec/lib/protobuf/message_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index bd6c4909..79c3f331 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -176,7 +176,6 @@ end it "initializes with an object with a block" do - hashie_object = OpenStruct.new(:to_hash => { :non_default_enum => 2 }) test_enum = Test::EnumTestMessage.new { |p| p.non_default_enum = 2 } expect(test_enum.non_default_enum).to eq(2) end From 6cd68498d4f4a779839fa34ad17278f174f51905 Mon Sep 17 00:00:00 2001 From: Adam Greene Date: Tue, 3 Mar 2015 22:25:32 -0800 Subject: [PATCH 207/298] don't downcast when assigning to a field_array --- lib/protobuf/field/field_array.rb | 2 + lib/protobuf/field/message_field.rb | 2 +- spec/lib/protobuf/field/field_array_spec.rb | 75 +++++++++++++++++++++ 3 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 spec/lib/protobuf/field/field_array_spec.rb diff --git a/lib/protobuf/field/field_array.rb b/lib/protobuf/field/field_array.rb index 65447a31..78bb79e0 100644 --- a/lib/protobuf/field/field_array.rb +++ b/lib/protobuf/field/field_array.rb @@ -66,6 +66,8 @@ def normalize(value) if field.is_a?(::Protobuf::Field::EnumField) field.type_class.fetch(value) + elsif field.is_a?(::Protobuf::Field::MessageField) && value.is_a?(field.type_class) + value elsif field.is_a?(::Protobuf::Field::MessageField) && value.respond_to?(:to_hash) field.type_class.new(value.to_hash) else diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 45dec389..eb6e8fa1 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -9,7 +9,7 @@ class MessageField < BaseField # def acceptable?(val) - unless val.instance_of?(type_class) || val.respond_to?(:to_hash) + unless val.is_a?(type_class) || val.is_a?(Hash) fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end diff --git a/spec/lib/protobuf/field/field_array_spec.rb b/spec/lib/protobuf/field/field_array_spec.rb new file mode 100644 index 00000000..cec33885 --- /dev/null +++ b/spec/lib/protobuf/field/field_array_spec.rb @@ -0,0 +1,75 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::FieldArray do + + class SomeBasicMessage < ::Protobuf::Message + optional :string, :field, 1 + end + + class MoreComplexMessage < SomeBasicMessage + end + + class OtherBasicMessage < ::Protobuf::Message + optional :string, :other_field, 1 + end + + class SomeRepeatMessage < ::Protobuf::Message + optional :string, :some_string, 1 + repeated :string, :multiple_strings, 2 + repeated SomeBasicMessage, :multiple_basic_msgs, 3 + end + + let(:instance) { SomeRepeatMessage.new } + + %w(<< push).each do |method| + describe "\##{method}" do + context 'when applied to a string field array' do + it 'adds a string' do + expect(instance.multiple_strings).to be_empty + instance.multiple_strings.send(method, 'string 1') + expect(instance.multiple_strings).to eq(['string 1']) + instance.multiple_strings.send(method, 'string 2') + expect(instance.multiple_strings).to eq(['string 1', 'string 2']) + end + + it 'fails if not adding a string' do + expect { instance.multiple_strings.send(method, 100.0) }.to raise_error(TypeError) + end + end + + context 'when applied to a MessageField field array' do + it 'adds a MessageField object' do + expect(instance.multiple_basic_msgs).to be_empty + basic_msg1 = SomeBasicMessage.new + instance.multiple_basic_msgs.send(method, basic_msg1) + expect(instance.multiple_basic_msgs).to eq([basic_msg1]) + basic_msg2 = SomeBasicMessage.new + instance.multiple_basic_msgs.send(method, basic_msg2) + expect(instance.multiple_basic_msgs).to eq([basic_msg1, basic_msg2]) + end + + it 'adds a Hash from a MessageField object' do + expect(instance.multiple_basic_msgs).to be_empty + basic_msg1 = SomeBasicMessage.new + basic_msg1.field = 'my value' + instance.multiple_basic_msgs.send(method, basic_msg1.to_hash) + expect(instance.multiple_basic_msgs).to eq([basic_msg1]) + end + + it 'does not downcast a MessageField' do + expect(instance.multiple_basic_msgs).to be_empty + basic_msg1 = MoreComplexMessage.new + instance.multiple_basic_msgs.send(method, basic_msg1) + expect(instance.multiple_basic_msgs).to eq([basic_msg1]) + expect(instance.multiple_basic_msgs.first).to be_a(MoreComplexMessage) + end + + it 'fails if not adding the expected MessageField object' do + expect { instance.multiple_basic_msgs.send(method, 100.0) }.to raise_error(TypeError) + expect { instance.multiple_basic_msgs.send(method, OtherBasicMessage.new) }.to raise_error(TypeError) + end + end + end + + end +end From f4ade201e4160b4bc9752c4a8db11ee5f64d343d Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 26 Jan 2015 16:57:47 -0800 Subject: [PATCH 208/298] Update `protobuf` to 2.6.1 and simplify the install --- install-protobuf.sh | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/install-protobuf.sh b/install-protobuf.sh index 22488b28..d9ad119e 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -1,8 +1,10 @@ +#!/usr/bin/env sh + set -ex -basename=protobuf-2.6.0 -tarball=$basename.tar.bz2 +version=2.6.1 +basename=protobuf-$version + +curl -sL https://github.com/google/protobuf/releases/download/v$version/$basename.tar.bz2 | tar jx -wget https://protobuf.googlecode.com/svn/rc/$tarball -tar -xvf $tarball cd $basename && ./configure --prefix=/usr && make && make install From 06a66fb0d583831689f340e2594d35743ac2598f Mon Sep 17 00:00:00 2001 From: Tamir Duberstein Date: Mon, 16 Mar 2015 09:32:46 -0700 Subject: [PATCH 209/298] Test against protobuf 3 --- .travis.yml | 6 +++++- install-protobuf.sh | 26 ++++++++++++++++++++++---- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 1f98e3da..3b77fb78 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y libzmq3-dev - - sudo ./install-protobuf.sh + - sudo -E ./install-protobuf.sh language: ruby rvm: - 1.9.3 @@ -9,9 +9,13 @@ rvm: - 2.1 - jruby - rbx-2 +env: + - PROTOBUF_VERSION=2.6.1 + - PROTOBUF_VERSION=3.0.0-alpha-2 matrix: allow_failures: - rvm: rbx-2 + - env: PROTOBUF_VERSION=3.0.0-alpha-2 notifications: webhooks: urls: diff --git a/install-protobuf.sh b/install-protobuf.sh index d9ad119e..b3872fd0 100755 --- a/install-protobuf.sh +++ b/install-protobuf.sh @@ -2,9 +2,27 @@ set -ex -version=2.6.1 -basename=protobuf-$version +gdie() { + echo "$@" >&2 + exit 1 +} -curl -sL https://github.com/google/protobuf/releases/download/v$version/$basename.tar.bz2 | tar jx +test -n "$PROTOBUF_VERSION" || die "PROTOBUF_VERSION env var is undefined" -cd $basename && ./configure --prefix=/usr && make && make install +case "$PROTOBUF_VERSION" in +2*) + basename=protobuf-$PROTOBUF_VERSION + ;; +3*) + basename=protobuf-cpp-$PROTOBUF_VERSION + ;; +*) + die "unknown protobuf version: $PROTOBUF_VERSION" + ;; +esac + +curl -sL https://github.com/google/protobuf/releases/download/v$PROTOBUF_VERSION/$basename.tar.gz | tar zx + +cd protobuf-$PROTOBUF_VERSION + +./configure --prefix=/usr && make -j2 && make install From 74f1e39d63974e13f99b24a5f1cb4e002c451f61 Mon Sep 17 00:00:00 2001 From: Harshit Chopra Date: Mon, 30 Mar 2015 16:02:27 -0400 Subject: [PATCH 210/298] Adds support to specify integer and bool proto fields as string. Also fixes the range check for integer types. --- lib/protobuf/field/bool_field.rb | 12 ++- lib/protobuf/field/varint_field.rb | 8 +- spec/lib/protobuf/field/bool_field_spec.rb | 51 +++++++++++++ spec/lib/protobuf/field/int32_field_spec.rb | 82 +++++++++++++++++++++ 4 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 spec/lib/protobuf/field/bool_field_spec.rb diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 57f20906..d1b9efc8 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -17,7 +17,17 @@ def self.default # # def acceptable?(val) - [true, false].include?(val) + [true, false].include?(val) || %w(true false).include?(val) + end + + def coerce!(val) + if val == 'true' + true + elsif val == 'false' + false + else + val + end end def decode(value) diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 448610dd..affaf393 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -37,11 +37,17 @@ def self.encode(value) # def acceptable?(val) - (val > self.class.min || val < self.class.max) + int_val = coerce!(val) + int_val >= self.class.min && int_val <= self.class.max rescue false end + def coerce!(val) + return val.to_i if val.is_a?(Numeric) + Integer(val, 10) + end + def decode(value) value end diff --git a/spec/lib/protobuf/field/bool_field_spec.rb b/spec/lib/protobuf/field/bool_field_spec.rb new file mode 100644 index 00000000..af254716 --- /dev/null +++ b/spec/lib/protobuf/field/bool_field_spec.rb @@ -0,0 +1,51 @@ +require 'spec_helper' + +RSpec.describe Protobuf::Field::Int32Field do + + class SomeBoolMessage < ::Protobuf::Message + optional :bool, :some_bool, 1 + end + + let(:instance) { SomeBoolMessage.new } + + describe '#define_setter' do + subject { instance.some_bool = value; instance.some_bool } + + [true, false].each do |val| + context "when set with #{val}" do + let(:value) { val } + + it 'is readable as a bool' do + expect(subject).to eq(val) + end + end + end + + [['true', true], ['false', false]].each do |val, expected| + context "when set with a string of #{val}" do + let(:value) { val } + + it 'is readable as a bool' do + expect(subject).to eq(expected) + end + end + end + + context 'when set with a non-bool string' do + let(:value) { "aaaa" } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with something that is not a bool' do + let(:value) { [1, 2, 3] } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + end + +end diff --git a/spec/lib/protobuf/field/int32_field_spec.rb b/spec/lib/protobuf/field/int32_field_spec.rb index 5c1ff70b..b65a778c 100644 --- a/spec/lib/protobuf/field/int32_field_spec.rb +++ b/spec/lib/protobuf/field/int32_field_spec.rb @@ -4,4 +4,86 @@ it_behaves_like :packable_field, described_class + class SomeInt32Message < ::Protobuf::Message + optional :int32, :some_int, 1 + end + + let(:instance) { SomeInt32Message.new } + + describe '#define_setter' do + subject { instance.some_int = value; instance.some_int } + + context 'when set with an int' do + let(:value) { 100 } + + it 'is readable as an int' do + expect(subject).to eq(100) + end + end + + context 'when set with a float' do + let(:value) { 100.1 } + + it 'is readable as an int' do + expect(subject).to eq(100) + end + end + + context 'when set with a string of an int' do + let(:value) { "101" } + + it 'is readable as an int' do + expect(subject).to eq(101) + end + end + + context 'when set with a negative representation of an int as string' do + let(:value) { "-101" } + + it 'is readable as a negative int' do + expect(subject).to eq(-101) + end + end + + context 'when set with a non-numeric string' do + let(:value) { "aaaa" } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with a string of an int in hex format' do + let(:value) { "0x101" } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with a string of an int larger than int32 max' do + let(:value) { (described_class.max + 1).to_s } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with something that is not an int' do + let(:value) { [1, 2, 3] } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + + context 'when set with a timestamp' do + let(:value) { Time.now } + + it 'throws an error' do + expect { subject }.to raise_error(TypeError) + end + end + end + end From 3321da5d4ce08466a51d3e19be8beec351229fd7 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 6 Apr 2015 21:09:41 -0600 Subject: [PATCH 211/298] restart service listener if it dies --- lib/protobuf/rpc/service_directory.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 6aec7b4d..802ab082 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -82,6 +82,7 @@ def initialize def all_listings_for(service) if running? && @listings_by_service.key?(service.to_s) + start_listener_thread if listener_dead? @listings_by_service[service.to_s].entries.shuffle else [] @@ -89,39 +90,53 @@ def all_listings_for(service) end def each_listing(&block) + start_listener_thread if listener_dead? @listings_by_uuid.each_value(&block) end def lookup(service) if running? + start_listener_thread if listener_dead? + if @listings_by_service.key?(service.to_s) @listings_by_service[service.to_s].entries.sample end end end + def listener_dead? + @thread.nil? || !@thread.alive? + end + def restart stop start end def running? - !!@thread.try(:alive?) + !!@running end def start unless running? init_socket logger.info { sign_message("listening to udp://#{self.class.address}:#{self.class.port}") } - @thread = Thread.new { send(:run) } + @running = true end + start_listener_thread if listener_dead? self end + def start_listener_thread + return if @thread.try(:alive?) + @thread = Thread.new { send(:run) } + end + def stop logger.info { sign_message("Stopping directory") } + @running = false @thread.try(:kill).try(:join) @socket.try(:close) From 37d3ed9d08abda05ad352d9a54ed7203af716fc4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 7 Apr 2015 11:33:56 -0600 Subject: [PATCH 212/298] use guard clause and make the cops happy --- lib/protobuf/rpc/service_directory.rb | 11 ++++------- lib/protobuf/rpc/service_filters.rb | 8 ++++---- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 802ab082..81696853 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -95,13 +95,10 @@ def each_listing(&block) end def lookup(service) - if running? - start_listener_thread if listener_dead? - - if @listings_by_service.key?(service.to_s) - @listings_by_service[service.to_s].entries.sample - end - end + return unless running? + start_listener_thread if listener_dead? + return unless @listings_by_service.key?(service.to_s) + @listings_by_service[service.to_s].entries.sample end def listener_dead? diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index b1413ef3..5d76460f 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -94,10 +94,10 @@ def filters # if the filter should not be invoked, true if invocation should occur. # def invoke_filter?(rpc_method, filter) - invoke_via_only?(rpc_method, filter) \ - && invoke_via_except?(rpc_method, filter) \ - && invoke_via_if?(rpc_method, filter) \ - && invoke_via_unless?(rpc_method, filter) + invoke_via_only?(rpc_method, filter) && + invoke_via_except?(rpc_method, filter) && + invoke_via_if?(rpc_method, filter) && + invoke_via_unless?(rpc_method, filter) end # If the target rpc endpoint method is listed under an :except option, From f572eff4550ee724601a472cea8c8843eae892c2 Mon Sep 17 00:00:00 2001 From: Brian Stien Date: Wed, 8 Apr 2015 12:51:37 -0600 Subject: [PATCH 213/298] Fix unhandled error in trap signal handler Thread#backtrace can be nil. If this is the case, this signal handler will throw an error and terminate the process. In the case of nil here, we will just print nothing and continue on. --- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index a867c2d4..33d2030d 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -41,7 +41,7 @@ def register_signals logger.info do <<-THREAD_TRACE #{thread.inspect}: - #{thread.backtrace.join($INPUT_RECORD_SEPARATOR)}" + #{thread.backtrace.try(:join, $INPUT_RECORD_SEPARATOR)}" THREAD_TRACE end end From 0077acddba3eab5e74007b644ee6ea4bff093d97 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 13 Apr 2015 20:29:41 -0600 Subject: [PATCH 214/298] clean up block syntax --- lib/protobuf/message.rb | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 32379824..0e8f95df 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -26,16 +26,13 @@ def self.to_json # Constructor # - def initialize(fields = {}, &blk) + def initialize(fields = {}) @values = {} - - if blk - blk.call(self) - else - fields.to_hash.each_pair do |name, value| - self[name] = value - end + fields.to_hash.each_pair do |name, value| + self[name] = value end + + yield self if block_given? end ## From 83f599e0ec05eed4243c692755e476b74c2b09be Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 13 Apr 2015 20:35:35 -0600 Subject: [PATCH 215/298] keep check to to_hash in message_field as it is a valid use-case --- lib/protobuf/field/message_field.rb | 2 +- spec/lib/protobuf/field/field_array_spec.rb | 6 ------ 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index eb6e8fa1..2d9f3c92 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -9,7 +9,7 @@ class MessageField < BaseField # def acceptable?(val) - unless val.is_a?(type_class) || val.is_a?(Hash) + unless val.is_a?(type_class) || val.respond_to?(:to_hash) fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" end diff --git a/spec/lib/protobuf/field/field_array_spec.rb b/spec/lib/protobuf/field/field_array_spec.rb index cec33885..48133381 100644 --- a/spec/lib/protobuf/field/field_array_spec.rb +++ b/spec/lib/protobuf/field/field_array_spec.rb @@ -63,13 +63,7 @@ class SomeRepeatMessage < ::Protobuf::Message expect(instance.multiple_basic_msgs).to eq([basic_msg1]) expect(instance.multiple_basic_msgs.first).to be_a(MoreComplexMessage) end - - it 'fails if not adding the expected MessageField object' do - expect { instance.multiple_basic_msgs.send(method, 100.0) }.to raise_error(TypeError) - expect { instance.multiple_basic_msgs.send(method, OtherBasicMessage.new) }.to raise_error(TypeError) - end end end - end end From 474897be311f56db5b21a932eba2ac9bb1320d40 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 13 Apr 2015 20:39:32 -0600 Subject: [PATCH 216/298] bump to 3.5.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 86b92f42..4a7a8256 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.4.4' + VERSION = '3.5.0' end From a2e448e1f6f2f1ea3568f9e607e1e4d4d2d6b09e Mon Sep 17 00:00:00 2001 From: Bob Bonifield Date: Thu, 23 Apr 2015 13:29:40 -0600 Subject: [PATCH 217/298] Move input file expansion into Ruby --- lib/protobuf/tasks/compile.rake | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/protobuf/tasks/compile.rake b/lib/protobuf/tasks/compile.rake index cd46e3ab..65c09576 100644 --- a/lib/protobuf/tasks/compile.rake +++ b/lib/protobuf/tasks/compile.rake @@ -18,8 +18,7 @@ namespace :protobuf do command << "protoc" command << "--#{args[:plugin]}_out=#{args[:destination]}" command << "-I #{args[:source]}" - command << "#{args[:source]}/#{args[:package]}/*.proto" - command << "#{args[:source]}/#{args[:package]}/**/*.proto" + command << Dir["#{args[:source]}/#{args[:package]}/**/*.proto"].join(" ") full_command = command.join(' ') puts full_command From 329ac77e97d7ef5f99f3df82a2ba8de24dd6df42 Mon Sep 17 00:00:00 2001 From: BJ Neilsen Date: Fri, 24 Apr 2015 10:09:33 -0600 Subject: [PATCH 218/298] Fix wording around stable branches --- CONTRIBUTING.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 4cc6d5dd..beb902ad 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -6,7 +6,7 @@ your code merged. 1. Use GitHub Issues or Pull Requests over sending an email. It's much easier for me to keep track of your issue through GitHub. 2. For __compiler issues__, please provide both a gist for the __source definition(s)__ as well as the __generated output__ (if any). -3. For __existing issues or functionality__, please use __`2-8-stable`__ as the base branch for the pull request. This helps us maintain a stable gem release strategy. All commits merged to `2-8-stable` will also be merged down to `master`. +3. For __existing issues or functionality__, please use the latest stable branch (currently __`3-5-stable`__) as the base branch for the pull request. This helps us maintain a stable gem release strategy. All commits merged to stable will also be merged down to `master`. 4. For __new functionality__, please use __`master`__ as the base branch for the pull request. The `master` branch is used to stage all "next iteration" work. 5. Be patient with me as I work on your issue. From d4bb25701f7d1920d8a93074d353a55f5f07f95b Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 10:30:06 -0600 Subject: [PATCH 219/298] Move symbolize_keys to the constructors of socket and zmq runners Thor's HashWithIndifferentAccess has no `symbolize_keys` method. This moves the symbolize_keys call to the constructor of socket_runner and zmq_runner. The tests were also updated to use string hash keys to reflect the type of keys found in HashWithIndifferentAccess. --- lib/protobuf/cli.rb | 2 +- lib/protobuf/rpc/servers/socket_runner.rb | 4 +--- lib/protobuf/rpc/servers/zmq_runner.rb | 2 +- spec/functional/zmq_server_spec.rb | 12 ++++++------ 4 files changed, 9 insertions(+), 11 deletions(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3fe340bf..b522b5e6 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -182,7 +182,7 @@ def require_application(app_file) end def runner_options - opt = options.symbolize_keys + opt = options.to_hash opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 782ae70e..53cfc964 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -12,10 +12,8 @@ def initialize(options) options = case when options.is_a?(OpenStruct) then options.marshal_dump - when options.is_a?(Hash) then - options when options.respond_to?(:to_hash) then - options.to_hash + options.to_hash.symbolize_keys else fail "Cannot parser Socket Server - server options" end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 33d2030d..50f26a15 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -11,7 +11,7 @@ def initialize(options) when options.is_a?(OpenStruct) then options.marshal_dump when options.respond_to?(:to_hash) then - options.to_hash + options.to_hash.symbolize_keys else fail "Cannot parser Zmq Server - server options" end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index 8996973d..a764dc1d 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -7,12 +7,12 @@ before(:all) do load "protobuf/zmq.rb" @runner = ::Protobuf::Rpc::ZmqRunner.new( - :host => "127.0.0.1", - :port => 9399, - :worker_port => 9408, - :backlog => 100, - :threshold => 100, - :threads => 5, + 'host' => '127.0.0.1', + 'port' => 9399, + 'worker_port' => 9408, + 'backlog' => 100, + 'threshold' => 100, + 'threads' => 5, ) @server_thread = Thread.new(@runner) { |runner| runner.run } Thread.pass until @runner.running? From bd0084fcb433927079d2dd2819752ad6a95f6976 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 11:04:17 -0600 Subject: [PATCH 220/298] Require active_support/core_ext/class to use subclasses in Rpc::Service --- lib/protobuf/rpc/service.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/rpc/service.rb b/lib/protobuf/rpc/service.rb index 327586ed..017acdb0 100644 --- a/lib/protobuf/rpc/service.rb +++ b/lib/protobuf/rpc/service.rb @@ -1,3 +1,5 @@ +require 'active_support/core_ext/class' + require 'protobuf/logging' require 'protobuf/rpc/client' require 'protobuf/rpc/error' From 29194138e85ed00ef897aaa6d16ab0d4515060d4 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 11:21:36 -0600 Subject: [PATCH 221/298] Force cli to symbolize keys so mocked constructor tests pass --- lib/protobuf/cli.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index b522b5e6..3e485b88 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -182,7 +182,7 @@ def require_application(app_file) end def runner_options - opt = options.to_hash + opt = options.to_hash.symbolize_keys opt[:workers_only] = (!!ENV['PB_WORKERS_ONLY']) || options.workers_only From 23e1a181be2bec07d9517e2235f506ee68a12b98 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 11:38:47 -0600 Subject: [PATCH 222/298] Update readme to point at correct travis project --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2a7d16b1..5308e37f 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # protobuf [![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf) -[![Build Status](https://secure.travis-ci.org/localshred/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) +[![Build Status](https://secure.travis-ci.org/ruby-protobuf/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) [![Gitter chat](https://badges.gitter.im/localshred/protobuf.svg)](https://gitter.im/localshred/protobuf) [![protobuf API Documentation](https://www.omniref.com/ruby/gems/protobuf.png)](https://www.omniref.com/ruby/gems/protobuf) From bf9b0276554841ba2afe18dbb933d642eb693de8 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 1 Jul 2015 15:58:08 -0600 Subject: [PATCH 223/298] a newer rubocop was released and this updates the code to stay inline with new cops/updates --- .rubocop.yml | 3 +++ lib/protobuf/cli.rb | 3 +-- lib/protobuf/message/fields.rb | 6 ++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index c4311848..1fc5df61 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -9,6 +9,9 @@ Lint/Loop: Metrics/ClassLength: Enabled: false +Metrics/ModuleLength: + Enabled: false + Style/CaseIndentation: IndentWhenRelativeTo: end diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 3fe340bf..a0c2c307 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -118,8 +118,7 @@ def configure_runner_mode :socket elsif options.zmq? :zmq - else # rubocop:disable Style/ElseAlignment - # above: https://github.com/bbatsov/rubocop/pull/1470/files + else case server_type = ENV["PB_SERVER_TYPE"] when nil, /socket/i :socket diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 5b081ffc..906d46fc 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -12,8 +12,10 @@ def self.extended(other) :get_field_by_tag => :get_field, ) - def inherited(subclass) - inherit_fields!(subclass) + other.class_eval do + def self.inherited(subclass) + inherit_fields!(subclass) + end end end From a5b69ce0b5e195bd4ce6b97314b2943acea7a728 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 1 Jul 2015 21:45:01 -0600 Subject: [PATCH 224/298] Thread can be sleeping under MRI, fix by using alive? For some reason, the broker thread will be sleeping under MRI and therefore will fail the !@broker_thread.stop? condition. Switching to @broker_thread.alive? fixes this and allows protobuf to function normally. --- lib/protobuf/rpc/servers/zmq/server.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/servers/zmq/server.rb b/lib/protobuf/rpc/servers/zmq/server.rb index 83e21d2d..f2c2d9e8 100644 --- a/lib/protobuf/rpc/servers/zmq/server.rb +++ b/lib/protobuf/rpc/servers/zmq/server.rb @@ -284,7 +284,7 @@ def init_zmq_context end def start_broker - return if @broker && @broker.running? && !@broker_thread.stop? + return if @broker && @broker.running? && @broker_thread.alive? if @broker && !@broker.running? broadcast_flatline if broadcast_busy? @broker_thread.join if @broker_thread From 71fd6ae9185c53764dd665da7e45e8fbb73853da Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 2 Jul 2015 08:40:15 -0600 Subject: [PATCH 225/298] move inherited hook to ClassMethods --- lib/protobuf/message/fields.rb | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 906d46fc..32cbb90b 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -11,15 +11,12 @@ def self.extended(other) :get_field_by_name => :get_field, :get_field_by_tag => :get_field, ) - - other.class_eval do - def self.inherited(subclass) - inherit_fields!(subclass) - end - end end module ClassMethods + def inherited(subclass) + inherit_fields!(subclass) + end ## # Field Definition Methods From b5c07d11453a9ae5664aa60e91b7a573a0b18797 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 2 Jul 2015 10:10:00 -0600 Subject: [PATCH 226/298] bump to 3.5.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 4a7a8256..5408793c 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.0' + VERSION = '3.5.1' end From 580efd65ae7108f1fd2d5f901bb3a8bf0dd5e870 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 2 Jul 2015 10:11:32 -0600 Subject: [PATCH 227/298] add changes for 3.5.1 --- CHANGES.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index ad027618..aba3d531 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,11 @@ # Stable (3.x) +3.5.1 +-------- +- Adds compatibility for Rails 4.2+ as CLI options were broken +- Fixes bug with MRI and "dead" thread in zmq broker +- Fixes Rubocop compatability with new version + 3.0.4 -------- From 095e7197743430fa5a73133619b721b83610ce07 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Fri, 25 Sep 2015 10:47:30 -0700 Subject: [PATCH 228/298] Optimized valid_tag?, enums_for_tag and enums_for_tags --- lib/protobuf/enum.rb | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 3fc171ac..fdf0725d 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -58,6 +58,15 @@ def self.define(name, tag) const_set(name, enum) end + # Internal: A mapping of enum number -> enums defined + # used for speeding up our internal enum methods. + def self.mapped_enums + @mapped_enums ||= enums.each_with_object({}) do |enum, hash| + list = hash[enum.to_i] ||= [] + list << enum + end + end + # Public: All defined enums. # class << self @@ -83,9 +92,7 @@ class << self # Returns an array with zero or more Enum objects or nil. # def self.enums_for_tag(tag) - enums.select do |enum| - enum.to_i == tag.to_i - end + mapped_enums[tag.to_i] || [] end # Public: Get the Enum associated with the given name. @@ -120,7 +127,8 @@ def self.enum_for_name(name) # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) - enums_for_tag(tag).first + value = mapped_enums[tag.to_i] + value ? value.first : nil end # Public: Get an Enum by a variety of type-checking mechanisms. @@ -198,7 +206,7 @@ def self.name_for_tag(tag) # Returns a boolean. # def self.valid_tag?(tag) - tag.respond_to?(:to_i) && all_tags.include?(tag.to_i) + tag.respond_to?(:to_i) && mapped_enums.key?(tag.to_i) end # Public: [DEPRECATED] Return a hash of Enum objects keyed From a08db9dea9ff73754c4c219ca2ab0188da48e6a1 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Fri, 25 Sep 2015 12:35:32 -0700 Subject: [PATCH 229/298] Updated rubocop_todo.yml --- .rubocop_todo.yml | 92 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 74 insertions(+), 18 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 93749c19..bda0f0ee 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,33 +1,35 @@ -# This configuration was generated by `rubocop --auto-gen-config` -# on 2014-12-23 08:21:59 -0800 using RuboCop version 0.28.0. +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2015-09-25 12:31:31 -0700 using RuboCop version 0.34.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 29 +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect. +Lint/EndAlignment: + Enabled: false + +# Offense count: 31 Metrics/AbcSize: Max: 59 -# Offense count: 3 +# Offense count: 1 Metrics/BlockNesting: Max: 5 -# Offense count: 8 -# Configuration parameters: CountComments. -Metrics/ClassLength: - Max: 232 - -# Offense count: 3 +# Offense count: 6 Metrics/CyclomaticComplexity: Max: 10 -# Offense count: 491 +# Offense count: 493 # Configuration parameters: AllowURI, URISchemes. Metrics/LineLength: Max: 196 -# Offense count: 43 +# Offense count: 44 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 38 @@ -37,23 +39,41 @@ Metrics/MethodLength: Metrics/ParameterLists: Max: 6 -# Offense count: 3 +# Offense count: 6 Metrics/PerceivedComplexity: Max: 11 -# Offense count: 189 +# Offense count: 1 +# Cop supports --auto-correct. +Performance/StringReplacement: + Exclude: + - 'lib/protobuf/rpc/buffer.rb' + +# Offense count: 127 +# Configuration parameters: Exclude. Style/Documentation: Enabled: false # Offense count: 12 Style/DoubleNegation: - Enabled: false + Exclude: + - 'lib/protobuf.rb' + - 'lib/protobuf/cli.rb' + - 'lib/protobuf/rpc/connectors/zmq.rb' + - 'lib/protobuf/rpc/servers/zmq/broker.rb' + - 'lib/protobuf/rpc/servers/zmq/server.rb' + - 'lib/protobuf/rpc/servers/zmq/worker.rb' + - 'lib/protobuf/rpc/service_directory.rb' # Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. Style/EmptyElse: - Enabled: false + Exclude: + - 'lib/protobuf/enum.rb' + - 'lib/protobuf/message/fields.rb' -# Offense count: 73 +# Offense count: 77 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/EmptyLinesAroundBlockBody: @@ -71,17 +91,53 @@ Style/EmptyLinesAroundClassBody: Style/EmptyLinesAroundModuleBody: Enabled: false +# Offense count: 2 +Style/IndentationWidth: + Exclude: + - 'protobuf.gemspec' + - 'lib/protobuf/cli.rb' + +# Offense count: 3 +Style/ElseAlignment: + Exclude: + - 'protobuf.gemspec' + - 'lib/protobuf/cli.rb' + +# Offense count: 8 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Style/ExtraSpacing: + Exclude: + - 'lib/protobuf/rpc/connectors/common.rb' + - 'lib/protobuf/rpc/connectors/socket.rb' + - 'lib/protobuf/rpc/connectors/zmq.rb' + - 'lib/protobuf/rpc/servers/socket/server.rb' + - 'spec/lib/protobuf/rpc/service_directory_spec.rb' + # Offense count: 46 # Cop supports --auto-correct. Style/NumericLiterals: MinDigits: 21 -# Offense count: 463 +# Offense count: 473 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. Style/StringLiterals: Enabled: false +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +Style/SymbolProc: + Exclude: + - 'lib/protobuf/generators/printable.rb' + - 'lib/protobuf/rpc/servers/socket/server.rb' + - 'spec/encoding/all_types_spec.rb' + - 'spec/encoding/extreme_values_spec.rb' + - 'spec/functional/socket_server_spec.rb' + - 'spec/functional/zmq_server_spec.rb' + - 'spec/lib/protobuf/rpc/servers/socket_server_spec.rb' + # Offense count: 4 # Cop supports --auto-correct. # Configuration parameters: WordRegex. From f04d6706f1b4b337d57a6bcd314802b5e7cb4416 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Fri, 25 Sep 2015 17:13:52 -0600 Subject: [PATCH 230/298] bump to 3.5.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 5408793c..8badc1e3 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.1' + VERSION = '3.5.2' end From 5bac686b7ba9dda4e6c1892515cd53b36ce263b0 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Fri, 25 Sep 2015 14:03:44 -0700 Subject: [PATCH 231/298] Optimized get_extension_field and get_field calls --- lib/protobuf/message/fields.rb | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 32cbb90b..bc0309a4 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -78,14 +78,12 @@ def field_tag?(tag, allow_extension = false) end def get_extension_field(name_or_tag) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] + field = field_store[name_or_tag] || str_field_store[name_or_tag] field if field.try(:extension?) { false } end def get_field(name_or_tag, allow_extension = false) - name_or_tag = name_or_tag.to_sym if name_or_tag.respond_to?(:to_sym) - field = field_store[name_or_tag] + field = field_store[name_or_tag] || str_field_store[name_or_tag] if field && (allow_extension || !field.extension?) field @@ -102,6 +100,8 @@ def define_field(rule, type_class, field_name, tag, options) field_store[field_name] = field field_store[tag] = field + str_field_store[field_name.to_s] = field + define_method("#{field_name}!") do @values[field_name] end @@ -126,6 +126,10 @@ def inherit_fields!(subclass) end private :inherit_fields! + def str_field_store + @str_field_store ||= {} + end + private :str_field_store end end end From e44e4ce911e8aabdcddf8649e2c9e969b1fede3e Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 27 Sep 2015 11:49:20 -0600 Subject: [PATCH 232/298] bump to 3.5.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 8badc1e3..483c12cc 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.2' + VERSION = '3.5.3' end From 654d1946a51d6c35ed3f609e79d0fc116eb21bee Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Sun, 27 Sep 2015 21:05:30 -0700 Subject: [PATCH 233/298] Run tests against MRI 2.2 --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index 3b77fb78..e868f214 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,6 +7,7 @@ rvm: - 1.9.3 - 2.0.0 - 2.1 + - 2.2 - jruby - rbx-2 env: From 7f68087c8c10914ba5c18634658d0bbb203d6341 Mon Sep 17 00:00:00 2001 From: Zach Anker Date: Sun, 27 Sep 2015 19:50:59 -0700 Subject: [PATCH 234/298] Optimized varint decoding when varint is available --- lib/protobuf/decoder.rb | 11 ++--------- lib/protobuf/message.rb | 11 +++++++++++ lib/protobuf/varint.rb | 11 +++++++++++ lib/protobuf/varint_pure.rb | 13 +++++++++++++ protobuf.gemspec | 5 +++-- spec/lib/protobuf/varint_spec.rb | 29 +++++++++++++++++++++++++++++ 6 files changed, 69 insertions(+), 11 deletions(-) create mode 100644 lib/protobuf/varint.rb create mode 100644 lib/protobuf/varint_pure.rb create mode 100644 spec/lib/protobuf/varint_spec.rb diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 601e06f5..ce1255d2 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -16,7 +16,7 @@ def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type when ::Protobuf::WireType::VARINT then - read_varint(stream) + Varint.decode(stream) when ::Protobuf::WireType::FIXED64 then read_fixed64(stream) when ::Protobuf::WireType::LENGTH_DELIMITED then @@ -60,14 +60,7 @@ def self.read_length_delimited(stream) # Read varint integer value from +stream+. def self.read_varint(stream) - value = index = 0 - begin - byte = stream.readbyte - value |= (byte & 0x7f) << (7 * index) - index += 1 - end while (byte & 0x80).nonzero? - value + Varint.decode(stream) end - end end diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 0e8f95df..6aa70047 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -4,6 +4,17 @@ require 'protobuf/message/fields' require 'protobuf/message/serialization' +# Under MRI, this optimizes proto decoding by around 15% in tests. +# When unavailable, we fall to pure Ruby. +# rubocop:disable Lint/HandleExceptions +begin + require 'varint/varint' +rescue LoadError +end +# rubocop:enable Lint/HandleExceptions + +require 'protobuf/varint' + module Protobuf class Message diff --git a/lib/protobuf/varint.rb b/lib/protobuf/varint.rb new file mode 100644 index 00000000..cfdd1857 --- /dev/null +++ b/lib/protobuf/varint.rb @@ -0,0 +1,11 @@ +require 'protobuf/varint_pure' + +module Protobuf + class Varint + if defined?(::Varint) + extend ::Varint + else + extend VarintPure + end + end +end diff --git a/lib/protobuf/varint_pure.rb b/lib/protobuf/varint_pure.rb new file mode 100644 index 00000000..eeffbecc --- /dev/null +++ b/lib/protobuf/varint_pure.rb @@ -0,0 +1,13 @@ +module Protobuf + module VarintPure + def decode(stream) + value = index = 0 + begin + byte = stream.readbyte + value |= (byte & 0x7f) << (7 * index) + index += 1 + end while (byte & 0x80).nonzero? + value + end + end +end diff --git a/protobuf.gemspec b/protobuf.gemspec index e2b4b5df..ecde63dc 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -43,9 +43,10 @@ require "protobuf/version" s.add_development_dependency pry_debugger s.add_development_dependency 'pry-stack_explorer' + + s.add_development_dependency 'varint' + s.add_development_dependency 'ruby-prof' else s.add_development_dependency 'pry' end - - s.add_development_dependency 'ruby-prof' if RUBY_ENGINE.to_sym == :ruby end diff --git a/spec/lib/protobuf/varint_spec.rb b/spec/lib/protobuf/varint_spec.rb new file mode 100644 index 00000000..3a03d306 --- /dev/null +++ b/spec/lib/protobuf/varint_spec.rb @@ -0,0 +1,29 @@ +require 'base64' +require 'spec_helper' + +RSpec.describe Protobuf::Varint do + VALUES = { + 0 => "AA==", + 5 => "BQ==", + 51 => "Mw==", + 9_192 => "6Ec=", + 80_389 => "hfQE", + 913_389 => "7d83", + 516_192_829_912_693 => "9eyMkpivdQ==", + 9_999_999_999_999_999_999 => "//+fz8jgyOOKAQ==", + } + + [defined?(::Varint) ? ::Varint : nil, Protobuf::VarintPure].compact.each do |klass| + context "with #{klass}" do + before { described_class.extend(klass) } + after { load ::File.expand_path('../../../../lib/protobuf/varint.rb', __FILE__) } + + VALUES.each do |number, encoded| + it "decodes #{number}" do + io = StringIO.new(Base64.decode64(encoded)) + expect(described_class.decode(io)).to eq(number) + end + end + end + end +end From 620a9376dc2e12a442cc89ac0abf927fc996df58 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 28 Sep 2015 10:56:12 -0600 Subject: [PATCH 235/298] Ensure ActiveSupport::Deprecation doesn't look for a caller when we have PB_IGNORE_DEPRECATIONS set to true. This turns out to be very expensive --- lib/protobuf/deprecation.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index eac6e4b1..012a3435 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -14,6 +14,15 @@ def deprecate_methods(*args) super end + + def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil) + if ENV.key?('PB_IGNORE_DEPRECATIONS') + # This ensures ActiveSupport::Deprecation doesn't look for the caller, which is very costly. + super(deprecated_method_name, message, ["IGNORING TRACE"]) + else + super(deprecated_method_name, message, caller_backtrace) + end + end end class Deprecation < DeprecationBase From d803c96fafc40fee14a4db4c0983345b229418b2 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 28 Sep 2015 11:16:03 -0600 Subject: [PATCH 236/298] Refactor deprecation caller trace to not call super --- lib/protobuf/deprecation.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/protobuf/deprecation.rb b/lib/protobuf/deprecation.rb index 012a3435..8c0d415e 100644 --- a/lib/protobuf/deprecation.rb +++ b/lib/protobuf/deprecation.rb @@ -16,12 +16,8 @@ def deprecate_methods(*args) end def deprecation_warning(deprecated_method_name, message = nil, caller_backtrace = nil) - if ENV.key?('PB_IGNORE_DEPRECATIONS') - # This ensures ActiveSupport::Deprecation doesn't look for the caller, which is very costly. - super(deprecated_method_name, message, ["IGNORING TRACE"]) - else - super(deprecated_method_name, message, caller_backtrace) - end + # This ensures ActiveSupport::Deprecation doesn't look for the caller, which is very costly. + super(deprecated_method_name, message, caller_backtrace) unless ENV.key?('PB_IGNORE_DEPRECATIONS') end end From 01002f7266b0481ba39b49474c0b58144e58e350 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 28 Sep 2015 11:22:17 -0600 Subject: [PATCH 237/298] bump to 3.5.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 483c12cc..c3f26808 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.3' + VERSION = '3.5.4' end From 2e0081f754faf8a2263d84689093feb7c78d67ce Mon Sep 17 00:00:00 2001 From: Michael Ries Date: Fri, 25 Sep 2015 13:50:59 -0600 Subject: [PATCH 238/298] resolve rubocop issues --- lib/protobuf/decoder.rb | 30 ++++++++-------- lib/protobuf/field/base_field.rb | 8 ++--- lib/protobuf/generators/printable.rb | 2 +- lib/protobuf/rpc/buffer.rb | 2 +- lib/protobuf/rpc/connectors/common.rb | 2 +- lib/protobuf/rpc/connectors/socket.rb | 4 +-- lib/protobuf/rpc/connectors/zmq.rb | 4 +-- lib/protobuf/rpc/servers/socket/server.rb | 6 ++-- lib/protobuf/rpc/servers/socket_runner.rb | 14 ++++---- lib/protobuf/rpc/servers/zmq_runner.rb | 14 ++++---- lib/protobuf/rpc/service_filters.rb | 34 +++++++++--------- spec/encoding/all_types_spec.rb | 5 +-- spec/encoding/extreme_values_spec.rb | Bin 1364 -> 1337 bytes spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- .../protobuf/rpc/service_directory_spec.rb | 4 +-- 17 files changed, 65 insertions(+), 70 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 601e06f5..5b29e6aa 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -15,21 +15,21 @@ def self.decode_each_field(stream, &block) def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type - when ::Protobuf::WireType::VARINT then - read_varint(stream) - when ::Protobuf::WireType::FIXED64 then - read_fixed64(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED then - read_length_delimited(stream) - when ::Protobuf::WireType::FIXED32 then - read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP then - fail NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP then - fail NotImplementedError, 'Group is deprecated.' - else - fail InvalidWireType, wire_type - end + when ::Protobuf::WireType::VARINT then + read_varint(stream) + when ::Protobuf::WireType::FIXED64 then + read_fixed64(stream) + when ::Protobuf::WireType::LENGTH_DELIMITED then + read_length_delimited(stream) + when ::Protobuf::WireType::FIXED32 then + read_fixed32(stream) + when ::Protobuf::WireType::START_GROUP then + fail NotImplementedError, 'Group is deprecated.' + when ::Protobuf::WireType::END_GROUP then + fail NotImplementedError, 'Group is deprecated.' + else + fail InvalidWireType, wire_type + end [tag, bytes] end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 440bbd72..993f06f7 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -69,10 +69,10 @@ def default def default_value @default_value ||= case - when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze - when required? then nil - when optional? then typed_default_value - end + when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze + when required? then nil + when optional? then typed_default_value + end end def deprecated? diff --git a/lib/protobuf/generators/printable.rb b/lib/protobuf/generators/printable.rb index 6347afe2..065ee11d 100644 --- a/lib/protobuf/generators/printable.rb +++ b/lib/protobuf/generators/printable.rb @@ -61,7 +61,7 @@ def indent # def modulize(name) name = name.gsub(/\./, '::') - name = name.gsub(/(^(?:::)?[a-z]|::[a-z])/) { |match| match.upcase } + name = name.gsub(/(^(?:::)?[a-z]|::[a-z])/, &:upcase) name end diff --git a/lib/protobuf/rpc/buffer.rb b/lib/protobuf/rpc/buffer.rb index aa4b4d1e..92309c04 100644 --- a/lib/protobuf/rpc/buffer.rb +++ b/lib/protobuf/rpc/buffer.rb @@ -63,7 +63,7 @@ def flushed? def get_data_size # rubocop:disable Style/AccessorMethodName if @size == 0 || @data.match(SIZE_REGEX) sliced_size = @data.slice!(SIZE_REGEX) - @size = sliced_size.gsub('-', '').to_i unless sliced_size.nil? + @size = sliced_size.delete('-').to_i unless sliced_size.nil? end end diff --git a/lib/protobuf/rpc/connectors/common.rb b/lib/protobuf/rpc/connectors/common.rb index f5067b75..c0fc26bd 100644 --- a/lib/protobuf/rpc/connectors/common.rb +++ b/lib/protobuf/rpc/connectors/common.rb @@ -37,7 +37,7 @@ def data_callback(data) # @param [Symbol] code The code we're using (see ::Protobuf::Socketrpc::ErrorReason) # @param [String] message The error message def failure(code, message) - @error = ClientError.new + @error = ClientError.new @error.code = Protobuf::Socketrpc::ErrorReason.fetch(code) @error.message = message logger.debug { sign_message("Server failed request (invoking on_failure): #{@error.inspect}") } diff --git a/lib/protobuf/rpc/connectors/socket.rb b/lib/protobuf/rpc/connectors/socket.rb index 4c060f3e..d570e7e0 100644 --- a/lib/protobuf/rpc/connectors/socket.rb +++ b/lib/protobuf/rpc/connectors/socket.rb @@ -24,7 +24,7 @@ def log_signature def close_connection @socket.close - logger.debug { sign_message('Connector closed') } + logger.debug { sign_message('Connector closed') } end def connect_to_rpc_server @@ -35,7 +35,7 @@ def connect_to_rpc_server # Method to determine error state, must be used with Connector api def error? return true if @error - logger.debug { sign_message("Error state : #{@socket.closed?}") } + logger.debug { sign_message("Error state : #{@socket.closed?}") } @socket.closed? end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 0059c07d..d34239e6 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -220,9 +220,9 @@ def send_request_with_timeout(attempt = 0) logger.debug { sign_message("Timed out waiting for response (attempt #{attempt}, #{socket})") } raise RequestTimeout ensure - logger.debug { sign_message("Closing Socket") } + logger.debug { sign_message("Closing Socket") } zmq_error_check(socket.close, :socket_close) if socket - logger.debug { sign_message("Socket closed") } + logger.debug { sign_message("Socket closed") } end def server_lookup_attempts diff --git a/lib/protobuf/rpc/servers/socket/server.rb b/lib/protobuf/rpc/servers/socket/server.rb index 72b07a87..eabbbd61 100644 --- a/lib/protobuf/rpc/servers/socket/server.rb +++ b/lib/protobuf/rpc/servers/socket/server.rb @@ -60,9 +60,7 @@ def log_signature def new_worker(socket) Thread.new(socket) do |sock| - ::Protobuf::Rpc::Socket::Worker.new(sock) do |s| - s.close - end + ::Protobuf::Rpc::Socket::Worker.new(sock, &:close) end end @@ -97,7 +95,7 @@ def run else unless working.include?(client) working << listen_fds.delete(client) - logger.debug { sign_message("Working") } + logger.debug { sign_message("Working") } threads << { :thread => new_worker(client), :socket => client } cleanup_threads if cleanup? diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 53cfc964..1edb4ab7 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -10,13 +10,13 @@ class SocketRunner def initialize(options) options = case - when options.is_a?(OpenStruct) then - options.marshal_dump - when options.respond_to?(:to_hash) then - options.to_hash.symbolize_keys - else - fail "Cannot parser Socket Server - server options" - end + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash.symbolize_keys + else + fail "Cannot parser Socket Server - server options" + end self.server = ::Protobuf::Rpc::Socket::Server.new(options) end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index 50f26a15..e4d22838 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -8,13 +8,13 @@ class ZmqRunner def initialize(options) @options = case - when options.is_a?(OpenStruct) then - options.marshal_dump - when options.respond_to?(:to_hash) then - options.to_hash.symbolize_keys - else - fail "Cannot parser Zmq Server - server options" - end + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash.symbolize_keys + else + fail "Cannot parser Zmq Server - server options" + end end def run diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 5d76460f..d0c1cace 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -122,11 +122,11 @@ def invoke_via_except?(rpc_method, filter) def invoke_via_if?(_rpc_method, filter) if_check = filter.fetch(:if) { ->(_service) { return true } } do_invoke = case - when if_check.nil? then - true - else - call_or_send(if_check) - end + when if_check.nil? then + true + else + call_or_send(if_check) + end do_invoke end @@ -152,11 +152,11 @@ def invoke_via_only?(rpc_method, filter) def invoke_via_unless?(_rpc_method, filter) unless_check = filter.fetch(:unless) { ->(_service) { return false } } skip_invoke = case - when unless_check.nil? then - false - else - call_or_send(unless_check) - end + when unless_check.nil? then + false + else + call_or_send(unless_check) + end !skip_invoke end @@ -254,13 +254,13 @@ def run_rescue_filters # def call_or_send(callable, *args, &block) return_value = case - when callable.respond_to?(:call) then - callable.call(self, *args, &block) - when respond_to?(callable, true) then - __send__(callable, *args, &block) - else - fail "Object #{callable} is not callable" - end + when callable.respond_to?(:call) then + callable.call(self, *args, &block) + when respond_to?(callable, true) then + __send__(callable, *args, &block) + else + fail "Object #{callable} is not callable" + end return_value end diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index 01b772a3..29122478 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -96,10 +96,7 @@ ) data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__) - data = File.open(data_file_path, 'rb') do |file| - file.read - end - + data = File.open(data_file_path, 'rb', &:read) expect(data).to eq(message.serialize_to_string) end end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index ded4fb02c2df33c6fb8798d5846630806c33659a..a81a4c3d0706b131d0599e2f1e5798440995815f 100644 GIT binary patch delta 21 ccmcb@wUcYZM;1;U1vRUp)Wj6c$)c?G08^F*tpET3 delta 48 ucmdnVb%krgM-~-Lg_L}SnzYQE)EX`YFaWXjic%9(!2Hy_6t2m?SnL6Uiw_O} diff --git a/spec/functional/socket_server_spec.rb b/spec/functional/socket_server_spec.rb index e46c36ae..9f8b1ec0 100644 --- a/spec/functional/socket_server_spec.rb +++ b/spec/functional/socket_server_spec.rb @@ -6,7 +6,7 @@ load "protobuf/socket.rb" @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @runner = ::Protobuf::Rpc::SocketRunner.new(@options) - @server_thread = Thread.new(@runner) { |runner| runner.run } + @server_thread = Thread.new(@runner, &:run) Thread.pass until @runner.running? end diff --git a/spec/functional/zmq_server_spec.rb b/spec/functional/zmq_server_spec.rb index a764dc1d..bb90974a 100644 --- a/spec/functional/zmq_server_spec.rb +++ b/spec/functional/zmq_server_spec.rb @@ -14,7 +14,7 @@ 'threshold' => 100, 'threads' => 5, ) - @server_thread = Thread.new(@runner) { |runner| runner.run } + @server_thread = Thread.new(@runner, &:run) Thread.pass until @runner.running? end diff --git a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb index d4947ea3..eccfe5eb 100644 --- a/spec/lib/protobuf/rpc/servers/socket_server_spec.rb +++ b/spec/lib/protobuf/rpc/servers/socket_server_spec.rb @@ -14,7 +14,7 @@ @options = OpenStruct.new(:host => "127.0.0.1", :port => 9399, :backlog => 100, :threshold => 100) @runner = ::Protobuf::Rpc::SocketRunner.new(@options) @server = @runner.instance_variable_get(:@server) - @server_thread = Thread.new(@runner) { |runner| runner.run } + @server_thread = Thread.new(@runner, &:run) Thread.pass until @server.running? end diff --git a/spec/lib/protobuf/rpc/service_directory_spec.rb b/spec/lib/protobuf/rpc/service_directory_spec.rb index c15af6a3..268bb021 100644 --- a/spec/lib/protobuf/rpc/service_directory_spec.rb +++ b/spec/lib/protobuf/rpc/service_directory_spec.rb @@ -283,8 +283,8 @@ def send_beacon(type, server) it "should perform lookups in constant time" do print "\n\n" Benchmark.bm(17) do |x| - x.report(" 1_000 lookups:") { 1_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } - x.report(" 10_000 lookups:") { 10_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } + x.report(" 1_000 lookups:") { 1_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } + x.report(" 10_000 lookups:") { 10_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } x.report("100_000 lookups:") { 100_000.times { subject.lookup("PerformanceService#{rand(0..9)}") } } end end From 86ef9075a2115904b59612c6152717c475164ea9 Mon Sep 17 00:00:00 2001 From: Michael Ries Date: Mon, 28 Sep 2015 22:47:10 -0600 Subject: [PATCH 239/298] peg the rubocop version, use keyword version of EndAlignment --- .rubocop.yml | 2 +- lib/protobuf/cli.rb | 44 +++++++++++------------ lib/protobuf/decoder.rb | 30 ++++++++-------- lib/protobuf/field/base_field.rb | 8 ++--- lib/protobuf/rpc/servers/socket_runner.rb | 14 ++++---- lib/protobuf/rpc/servers/zmq_runner.rb | 14 ++++---- lib/protobuf/rpc/service_filters.rb | 34 +++++++++--------- protobuf.gemspec | 10 +++--- 8 files changed, 78 insertions(+), 78 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 1fc5df61..9f5f9e92 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -1,7 +1,7 @@ inherit_from: .rubocop_todo.yml Lint/EndAlignment: - AlignWith: variable + AlignWith: keyword Lint/Loop: Enabled: false diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index 08ec236c..df4d3bc8 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -114,21 +114,21 @@ def configure_runner_mode debug_say('Configuring runner mode') self.mode = if multi_mode? - say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow) - :socket - elsif options.zmq? - :zmq - else - case server_type = ENV["PB_SERVER_TYPE"] - when nil, /socket/i - :socket - when /zmq/i - :zmq - else - say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow - :socket - end - end + say('WARNING: You have provided multiple mode options. Defaulting to socket mode.', :yellow) + :socket + elsif options.zmq? + :zmq + else + case server_type = ENV["PB_SERVER_TYPE"] + when nil, /socket/i + :socket + when /zmq/i + :zmq + else + say "WARNING: You have provided incorrect option 'PB_SERVER_TYPE=#{server_type}'. Defaulting to socket mode.", :yellow + :socket + end + end end # Configure signal traps. @@ -153,13 +153,13 @@ def configure_traps def create_runner debug_say("Creating #{mode} runner") self.runner = case mode - when :zmq - create_zmq_runner - when :socket - create_socket_runner - else - say_and_exit("Unknown runner mode: #{mode}") - end + when :zmq + create_zmq_runner + when :socket + create_socket_runner + else + say_and_exit("Unknown runner mode: #{mode}") + end end # Say something if we're in debug mode. diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 5b29e6aa..601e06f5 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -15,21 +15,21 @@ def self.decode_each_field(stream, &block) def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type - when ::Protobuf::WireType::VARINT then - read_varint(stream) - when ::Protobuf::WireType::FIXED64 then - read_fixed64(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED then - read_length_delimited(stream) - when ::Protobuf::WireType::FIXED32 then - read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP then - fail NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP then - fail NotImplementedError, 'Group is deprecated.' - else - fail InvalidWireType, wire_type - end + when ::Protobuf::WireType::VARINT then + read_varint(stream) + when ::Protobuf::WireType::FIXED64 then + read_fixed64(stream) + when ::Protobuf::WireType::LENGTH_DELIMITED then + read_length_delimited(stream) + when ::Protobuf::WireType::FIXED32 then + read_fixed32(stream) + when ::Protobuf::WireType::START_GROUP then + fail NotImplementedError, 'Group is deprecated.' + when ::Protobuf::WireType::END_GROUP then + fail NotImplementedError, 'Group is deprecated.' + else + fail InvalidWireType, wire_type + end [tag, bytes] end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 993f06f7..440bbd72 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -69,10 +69,10 @@ def default def default_value @default_value ||= case - when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze - when required? then nil - when optional? then typed_default_value - end + when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze + when required? then nil + when optional? then typed_default_value + end end def deprecated? diff --git a/lib/protobuf/rpc/servers/socket_runner.rb b/lib/protobuf/rpc/servers/socket_runner.rb index 1edb4ab7..881daa4c 100644 --- a/lib/protobuf/rpc/servers/socket_runner.rb +++ b/lib/protobuf/rpc/servers/socket_runner.rb @@ -10,13 +10,13 @@ class SocketRunner def initialize(options) options = case - when options.is_a?(OpenStruct) then - options.marshal_dump - when options.respond_to?(:to_hash) then - options.to_hash.symbolize_keys - else - fail "Cannot parser Socket Server - server options" - end + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash.symbolize_keys + else + fail "Cannot parser Socket Server - server options" + end self.server = ::Protobuf::Rpc::Socket::Server.new(options) end diff --git a/lib/protobuf/rpc/servers/zmq_runner.rb b/lib/protobuf/rpc/servers/zmq_runner.rb index e4d22838..50f26a15 100644 --- a/lib/protobuf/rpc/servers/zmq_runner.rb +++ b/lib/protobuf/rpc/servers/zmq_runner.rb @@ -8,13 +8,13 @@ class ZmqRunner def initialize(options) @options = case - when options.is_a?(OpenStruct) then - options.marshal_dump - when options.respond_to?(:to_hash) then - options.to_hash.symbolize_keys - else - fail "Cannot parser Zmq Server - server options" - end + when options.is_a?(OpenStruct) then + options.marshal_dump + when options.respond_to?(:to_hash) then + options.to_hash.symbolize_keys + else + fail "Cannot parser Zmq Server - server options" + end end def run diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index d0c1cace..5d76460f 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -122,11 +122,11 @@ def invoke_via_except?(rpc_method, filter) def invoke_via_if?(_rpc_method, filter) if_check = filter.fetch(:if) { ->(_service) { return true } } do_invoke = case - when if_check.nil? then - true - else - call_or_send(if_check) - end + when if_check.nil? then + true + else + call_or_send(if_check) + end do_invoke end @@ -152,11 +152,11 @@ def invoke_via_only?(rpc_method, filter) def invoke_via_unless?(_rpc_method, filter) unless_check = filter.fetch(:unless) { ->(_service) { return false } } skip_invoke = case - when unless_check.nil? then - false - else - call_or_send(unless_check) - end + when unless_check.nil? then + false + else + call_or_send(unless_check) + end !skip_invoke end @@ -254,13 +254,13 @@ def run_rescue_filters # def call_or_send(callable, *args, &block) return_value = case - when callable.respond_to?(:call) then - callable.call(self, *args, &block) - when respond_to?(callable, true) then - __send__(callable, *args, &block) - else - fail "Object #{callable} is not callable" - end + when callable.respond_to?(:call) then + callable.call(self, *args, &block) + when respond_to?(callable, true) then + __send__(callable, *args, &block) + else + fail "Object #{callable} is not callable" + end return_value end diff --git a/protobuf.gemspec b/protobuf.gemspec index e2b4b5df..055076f7 100644 --- a/protobuf.gemspec +++ b/protobuf.gemspec @@ -27,7 +27,7 @@ require "protobuf/version" s.add_development_dependency 'ffi-rzmq' s.add_development_dependency 'rake' s.add_development_dependency 'rspec', '>= 3.0' - s.add_development_dependency 'rubocop' + s.add_development_dependency 'rubocop', '0.34.2' s.add_development_dependency 'simplecov' s.add_development_dependency 'timecop' s.add_development_dependency 'yard' @@ -36,10 +36,10 @@ require "protobuf/version" if RUBY_ENGINE.to_sym == :ruby # we don't support MRI < 1.9.3 pry_debugger = if RUBY_VERSION < '2.0.0' - 'pry-debugger' - else - 'pry-byebug' - end + 'pry-debugger' + else + 'pry-byebug' + end s.add_development_dependency pry_debugger s.add_development_dependency 'pry-stack_explorer' From fb26609dd20ba47b897916c89f260a208e7daff1 Mon Sep 17 00:00:00 2001 From: Michael Ries Date: Mon, 28 Sep 2015 22:51:19 -0600 Subject: [PATCH 240/298] remove EndAlignment from the TODO list --- .rubocop_todo.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index bda0f0ee..880dd05c 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -6,12 +6,6 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 7 -# Cop supports --auto-correct. -# Configuration parameters: AlignWith, SupportedStyles, AutoCorrect. -Lint/EndAlignment: - Enabled: false - # Offense count: 31 Metrics/AbcSize: Max: 59 From 07b298656ef4a75278b9892c769b188337811538 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 1 Oct 2015 15:33:59 -0400 Subject: [PATCH 241/298] bump to 3.5.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c3f26808..e76a9845 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.4' + VERSION = '3.5.5' end From 3addd6071b0a3ee875e9a312ecaa471894d94074 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Tue, 27 Oct 2015 22:50:00 -0600 Subject: [PATCH 242/298] Deprecate gc_pause_request with a plan to remove this in 4.0 I think this was an MRI relic that was never removed. In a threaded environment, it doesn't make sense to start and stop the GC per request. It just doesn't work. --- lib/protobuf/cli.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/cli.rb b/lib/protobuf/cli.rb index df4d3bc8..31da71b4 100644 --- a/lib/protobuf/cli.rb +++ b/lib/protobuf/cli.rb @@ -39,7 +39,7 @@ class CLI < ::Thor option :broadcast_beacons, :type => :boolean, :desc => 'Broadcast beacons for dynamic discovery (Currently only available with ZeroMQ).' option :broadcast_busy, :type => :boolean, :default => false, :desc => 'Remove busy nodes from cluster when all workers are busy (Currently only available with ZeroMQ).' option :debug, :type => :boolean, :default => false, :aliases => %w(-d), :desc => 'Debug Mode. Override log level to DEBUG.' - option :gc_pause_request, :type => :boolean, :default => false, :desc => 'Enable/Disable GC pause during request.' + option :gc_pause_request, :type => :boolean, :default => false, :desc => 'DEPRECATED: Enable/Disable GC pause during request.' option :print_deprecation_warnings, :type => :boolean, :default => nil, :desc => 'Cause use of deprecated fields to be printed or ignored.' option :workers_only, :type => :boolean, :default => false, :desc => "Starts process with only workers (no broker/frontend is started) only relevant for Zmq Server" option :worker_port, :type => :numeric, :default => nil, :desc => "Port for 'backend' where workers connect (defaults to port + 1)" @@ -80,6 +80,8 @@ def configure_deprecation_warnings # If we pause during request we don't need to pause in serialization def configure_gc + say "DEPRECATED: The gc_pause_request option is deprecated and will be removed in 4.0." if options.gc_pause_request? + debug_say('Configuring gc') if defined?(JRUBY_VERSION) From e9f9a30b43328e8aa299f7ed2c074990a2c4a200 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sat, 16 Jan 2016 23:05:10 -0700 Subject: [PATCH 243/298] Ensure the ping port is timed out after a reasonable amount of time Should a server's ping port get jammed, overwhelmed, or access a port that is not open, then the ping port check will block until the TCPSocket default timeout rescues the blocked request. Instead, we can wrap Socket to add a reasonable timeout to ping port checks. By default, the timeout is set to 5 seconds, but you can customize this by setting the "PB_RPC_PING_PORT_TIMEOUT" environment variable. --- lib/protobuf/rpc/connectors/ping.rb | 87 +++++++++++++++++++ lib/protobuf/rpc/connectors/zmq.rb | 21 ++--- spec/lib/protobuf/rpc/connectors/ping_spec.rb | 69 +++++++++++++++ spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 17 ++-- 4 files changed, 166 insertions(+), 28 deletions(-) create mode 100644 lib/protobuf/rpc/connectors/ping.rb create mode 100644 spec/lib/protobuf/rpc/connectors/ping_spec.rb diff --git a/lib/protobuf/rpc/connectors/ping.rb b/lib/protobuf/rpc/connectors/ping.rb new file mode 100644 index 00000000..0b8e085d --- /dev/null +++ b/lib/protobuf/rpc/connectors/ping.rb @@ -0,0 +1,87 @@ +require "socket" + +module Protobuf + module Rpc + module Connectors + class Ping + attr_reader :host, :port + + def initialize(host, port) + @host = host + @port = port + end + + def online? + socket = tcp_socket + socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1, 0].pack('ii')) + + true + rescue + false + ensure + begin + socket && socket.close + rescue IOError + nil + end + end + + def timeout + @timeout ||= begin + if ::ENV.key?("PB_RPC_PING_PORT_TIMEOUT") + ::ENV["PB_RPC_PING_PORT_TIMEOUT"].to_i + else + 5 # 5 seconds + end + end + end + + private + + def tcp_socket + # Reference: http://stackoverflow.com/a/21014439/1457934 + socket = ::Socket.new(family, ::Socket::SOCK_STREAM, 0) + socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) + socket.connect_nonblock(sockaddr) + rescue ::IO::WaitWritable + # IO.select will block until the socket is writable or the timeout + # is exceeded - whichever comes first. + if ::IO.select(nil, [socket], nil, timeout) + begin + # Verify there is now a good connection + socket.connect_nonblock(sockaddr) + rescue ::Errno::EISCONN + # Socket is connected. + socket + rescue + # An unexpected exception was raised - the connection is no good. + socket.close + raise + end + else + # IO.select returns nil when the socket is not ready before timeout + # seconds have elapsed + socket.close + raise "Connection Timeout" + end + end + + def family + @family ||= ::Socket.const_get(addrinfo[0][0]) + end + + def addrinfo + @addrinfo ||= ::Socket.getaddrinfo(host, nil) + end + + def ip + @ip ||= addrinfo[0][3] + end + + def sockaddr + @sockaddr ||= ::Socket.pack_sockaddr_in(port, ip) + end + end + end + end +end diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index d34239e6..8605f488 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -1,6 +1,7 @@ -require 'thread_safe' -require 'protobuf/rpc/connectors/base' -require 'protobuf/rpc/service_directory' +require "thread_safe" +require "protobuf/rpc/connectors/base" +require "protobuf/rpc/connectors/ping" +require "protobuf/rpc/service_directory" module Protobuf module Rpc @@ -161,19 +162,7 @@ def lookup_server_uri end def ping_port_open?(host) - socket = TCPSocket.new(host, ping_port.to_i) - socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) - socket.setsockopt(::Socket::SOL_SOCKET, ::Socket::SO_LINGER, [1, 0].pack('ii')) - - true - rescue - false - ensure - begin - socket && socket.close - rescue IOError - nil - end + Ping.new(host, ping_port.to_i).online? end def rcv_timeout diff --git a/spec/lib/protobuf/rpc/connectors/ping_spec.rb b/spec/lib/protobuf/rpc/connectors/ping_spec.rb new file mode 100644 index 00000000..0f0473b3 --- /dev/null +++ b/spec/lib/protobuf/rpc/connectors/ping_spec.rb @@ -0,0 +1,69 @@ +require "spec_helper" +require "protobuf/zmq" + +::RSpec.describe ::Protobuf::Rpc::Connectors::Ping do + subject { described_class.new("google.com", 80) } + + let(:host) { "google.com" } + let(:port) { 80 } + + describe ".new" do + it "assigns host" do + expect(subject.host).to eq(host) + end + + it "assigns port" do + expect(subject.port).to eq(port) + end + end + + describe "#online?" do + it "closes the socket" do + socket = double(:close => nil, :setsockopt => nil) + allow(subject).to receive(:tcp_socket).and_return(socket) + expect(socket).to receive(:close) + expect(subject).to be_online + end + + context "when a socket can connect" do + let(:socket) { double(:close => nil, :setsockopt => nil) } + before { allow(subject).to receive(:tcp_socket).and_return(socket) } + + it "returns true" do + expect(subject).to be_online + end + end + + context "when a socket error is raised" do + before { allow(subject).to receive(:tcp_socket).and_raise(::Errno::ECONNREFUSED) } + + it "returns false" do + expect(subject).to_not be_online + end + end + + context "when a select timeout is fired" do + let(:wait_writable_class) { ::Class.new(StandardError) { include ::IO::WaitWritable } } + before { expect_any_instance_of(::Socket).to receive(:connect_nonblock).and_raise(wait_writable_class) } + + it "returns false" do + expect(::IO).to receive(:select).and_return(false) + expect(subject).to_not be_online + end + end + end + + describe "#timeout" do + it "uses the default value" do + expect(subject.timeout).to eq(5) + end + + context "when environment variable is set" do + before { ::ENV["PB_RPC_PING_PORT_TIMEOUT"] = "1" } + + it "uses the environmet variable" do + expect(subject.timeout).to eq(1) + end + end + end +end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index b15e94be..abf0a89f 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -93,24 +93,17 @@ context "when the PB_RPC_PING_PORT is set" do before do - ENV["PB_RPC_PING_PORT"] = "3307" + ::ENV["PB_RPC_PING_PORT"] = "3307" end it "returns true when the connection succeeds" do - expect(TCPSocket).to receive(:new).with("huzzah.com", 3307).and_return(double(:close => nil, :setsockopt => nil)) - expect(subject.send(:host_alive?, "huzzah.com")).to be true + allow_any_instance_of(::Protobuf::Rpc::Connectors::Ping).to receive(:online?).and_return(true) + expect(subject.send(:host_alive?, "huzzah1.com")).to eq(true) end it "returns false when the connection fails" do - expect(TCPSocket).to receive(:new).with("hayoob.com", 3307).and_raise(Errno::ECONNREFUSED) - expect(subject.send(:host_alive?, "hayoob.com")).to be false - end - - it "closes the socket" do - socket = double("TCPSocket", :setsockopt => nil) - expect(socket).to receive(:close) - expect(TCPSocket).to receive(:new).with("absorbalof.com", 3307).and_return(socket) - expect(subject.send(:host_alive?, "absorbalof.com")).to be true + allow_any_instance_of(::Protobuf::Rpc::Connectors::Ping).to receive(:online?).and_return(false) + expect(subject.send(:host_alive?, "huzzah2.com")).to eq(false) end end end From c332f1891d4587e13b698459f370be18f2351c2c Mon Sep 17 00:00:00 2001 From: RKushnir Date: Wed, 20 Jan 2016 17:33:32 +0100 Subject: [PATCH 244/298] Allow Message#each_field to return an enumerator --- lib/protobuf/message.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6aa70047..f98c33c5 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -73,6 +73,8 @@ def dup # Iterate over every field, invoking the given block # def each_field + return to_enum(:each_field) unless block_given? + self.class.all_fields.each do |field| value = __send__(field.getter) yield(field, value) From 63f46f4a800c5a31efa3861c6f9782171e9a32b6 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Wed, 20 Jan 2016 16:12:52 -0700 Subject: [PATCH 245/298] Ensure bundler is at the latest version to make travis pass --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e868f214..0f1c54b4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,7 @@ before_install: - sudo apt-get update -qq - sudo apt-get install -y libzmq3-dev - sudo -E ./install-protobuf.sh + - gem update bundler language: ruby rvm: - 1.9.3 From 49aa220e0d9424d24dd40189d382eb63f1bfec5e Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Thu, 21 Jan 2016 09:47:50 -0700 Subject: [PATCH 246/298] hostname can be different than ruby's gethostname --- spec/lib/protobuf_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 314909c6..0203f369 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -9,7 +9,7 @@ subject { ::Protobuf.client_host } context 'when client_host is not pre-configured' do - it { is_expected.to eq `hostname`.chomp } + it { is_expected.to eq ::Socket.gethostname } end context 'when client_host is pre-configured' do From deb67728503593dca8845b8ead9cc7e269116e7c Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Mon, 25 Jan 2016 16:55:32 -0800 Subject: [PATCH 247/298] fix raise_error rspec warnings --- spec/lib/protobuf/field_spec.rb | 2 +- spec/lib/protobuf/message_spec.rb | 8 ++++---- spec/lib/protobuf/rpc/connectors/zmq_spec.rb | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/lib/protobuf/field_spec.rb b/spec/lib/protobuf/field_spec.rb index a8efb781..c0eb24d8 100644 --- a/spec/lib/protobuf/field_spec.rb +++ b/spec/lib/protobuf/field_spec.rb @@ -182,7 +182,7 @@ it 'raises an ArgumentError' do expect do subject.field_class("boom") - end.to raise_error + end.to raise_error(ArgumentError) end end diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 79c3f331..cadf2528 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -44,12 +44,12 @@ end it 'rejects an unknown value when using the constructor' do - expect { older_message.new(:enum_field => :HOORAY) }.to raise_error + expect { older_message.new(:enum_field => :HOORAY) }.to raise_error(TypeError) end it 'rejects an unknown value when the setter' do older = older_message.new - expect { older.enum_field = :HOORAY }.to raise_error + expect { older.enum_field = :HOORAY }.to raise_error(TypeError) end end @@ -61,12 +61,12 @@ end it 'rejects an unknown value when using the constructor' do - expect { older_message.new(:enum_list => [:HOORAY]) }.to raise_error + expect { older_message.new(:enum_list => [:HOORAY]) }.to raise_error(TypeError) end it 'rejects an unknown value when the setter' do older = older_message.new - expect { older.enum_field = [:HOORAY] }.to raise_error + expect { older.enum_field = [:HOORAY] }.to raise_error(TypeError) end end end diff --git a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb index b15e94be..af6cba97 100644 --- a/spec/lib/protobuf/rpc/connectors/zmq_spec.rb +++ b/spec/lib/protobuf/rpc/connectors/zmq_spec.rb @@ -69,7 +69,7 @@ it "raises an error" do allow(service_directory).to receive(:all_listings_for).and_return(listings) allow(subject).to receive(:host_alive?).and_return(false) - expect { subject.send(:lookup_server_uri) }.to raise_error + expect { subject.send(:lookup_server_uri) }.to raise_error(RuntimeError) end end From a7016ab6f01c52ced6e3f270066aae3c7c939e74 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Wed, 27 Jan 2016 10:37:34 -0800 Subject: [PATCH 248/298] fix spec failure with PB_NO_TAG_WARNINGS=1 --- spec/lib/protobuf/generators/base_spec.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/lib/protobuf/generators/base_spec.rb b/spec/lib/protobuf/generators/base_spec.rb index f6bb027b..df29fd2a 100644 --- a/spec/lib/protobuf/generators/base_spec.rb +++ b/spec/lib/protobuf/generators/base_spec.rb @@ -74,6 +74,8 @@ def compile context 'when tags are missing in the range' do it 'prints a warning' do + allow(ENV).to receive(:key?).and_call_original + allow(ENV).to receive(:key?).with("PB_NO_TAG_WARNINGS").and_return(false) expect(::Protobuf::CodeGenerator).to receive(:print_tag_warning_suppress) expect(::Protobuf::CodeGenerator).to receive(:warn).with(/FooBar object should have 5 tags \(1\.\.5\), but found 4 tags/) described_class.validate_tags("FooBar", [1, 2, 4, 5]) From 39224bef4989b3762f03f7e4b2b579ec638ce452 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Wed, 27 Jan 2016 10:42:33 -0800 Subject: [PATCH 249/298] consolidate test protos to spec/support/protos - add SUPPORT_PATH, PROTOS_PATH helpers in specs - refresh unittest protos from upstream --- spec/benchmark/tasks.rb | 2 +- spec/data/data.bin | 3 - spec/data/types.bin | Bin 10999 -> 0 bytes spec/encoding/all_types_spec.rb | 55 +-- spec/encoding/extreme_values_spec.rb | Bin 1337 -> 1358 bytes spec/functional/class_inheritance_spec.rb | 2 +- spec/functional/socket_server_spec.rb | 2 +- spec/functional/zmq_server_spec.rb | 2 +- spec/lib/protobuf/message_spec.rb | 2 + spec/lib/protobuf/rpc/client_spec.rb | 2 +- .../rpc/servers/socket_server_spec.rb | 2 +- spec/lib/protobuf/rpc/service_spec.rb | 2 +- spec/spec_helper.rb | 10 +- .../{test => protos}/all_types.data.bin | Bin .../{test => protos}/all_types.data.txt | 0 spec/support/{test => protos}/enum.pb.rb | 2 +- spec/support/{test => protos}/enum.proto | 4 +- .../{test => protos}/extreme_values.data.bin | Bin spec/support/protos/google_unittest.bin | Bin 0 -> 87504 bytes .../{test => protos}/google_unittest.pb.rb | 395 ++++++++++++++---- .../{test => protos}/google_unittest.proto | 296 ++++++++++--- .../google_unittest_import.pb.rb | 19 +- .../google_unittest_import.proto | 29 +- .../google_unittest_import_public.pb.rb | 24 ++ .../google_unittest_import_public.proto | 13 +- .../multi_field_extensions.pb.rb | 0 .../multi_field_extensions.proto | 2 + spec/support/{test => protos}/resource.pb.rb | 0 spec/support/{test => protos}/resource.proto | 2 + spec/support/{test => }/resource_service.rb | 2 +- spec/support/server.rb | 2 +- spec/support/test/defaults.pb.rb | 27 -- spec/support/test/defaults.proto | 9 - spec/support/test/extended.pb.rb | 24 -- spec/support/test/extended.proto | 10 - .../test/google_unittest_import_public.pb.rb | 10 - 36 files changed, 664 insertions(+), 290 deletions(-) delete mode 100644 spec/data/data.bin delete mode 100644 spec/data/types.bin rename spec/support/{test => protos}/all_types.data.bin (100%) rename spec/support/{test => protos}/all_types.data.txt (100%) rename spec/support/{test => protos}/enum.pb.rb (97%) rename spec/support/{test => protos}/enum.proto (92%) rename spec/support/{test => protos}/extreme_values.data.bin (100%) create mode 100644 spec/support/protos/google_unittest.bin rename spec/support/{test => protos}/google_unittest.pb.rb (54%) rename spec/support/{test => protos}/google_unittest.proto (77%) rename spec/support/{test => protos}/google_unittest_import.pb.rb (67%) rename spec/support/{test => protos}/google_unittest_import.proto (80%) create mode 100644 spec/support/protos/google_unittest_import_public.pb.rb rename spec/support/{test => protos}/google_unittest_import_public.proto (88%) rename spec/support/{test => protos}/multi_field_extensions.pb.rb (100%) rename spec/support/{test => protos}/multi_field_extensions.proto (96%) rename spec/support/{test => protos}/resource.pb.rb (100%) rename spec/support/{test => protos}/resource.proto (98%) rename spec/support/{test => }/resource_service.rb (90%) delete mode 100644 spec/support/test/defaults.pb.rb delete mode 100644 spec/support/test/defaults.proto delete mode 100644 spec/support/test/extended.pb.rb delete mode 100644 spec/support/test/extended.proto delete mode 100644 spec/support/test/google_unittest_import_public.pb.rb diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index e6710d6c..aa184cd8 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,7 +1,7 @@ require 'benchmark' require 'protobuf/socket' require 'support/all' -require 'support/test/resource_service' +require SUPPORT_PATH.join('resource_service') case RUBY_ENGINE.to_sym when :ruby diff --git a/spec/data/data.bin b/spec/data/data.bin deleted file mode 100644 index 42632981..00000000 --- a/spec/data/data.bin +++ /dev/null @@ -1,3 +0,0 @@ - -John Doeา jdoe@example.com" -555-4321 \ No newline at end of file diff --git a/spec/data/types.bin b/spec/data/types.bin deleted file mode 100644 index 07e0f18d29188fb0fa5569b53b5226db90c8ec09..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 10999 zcmW++1w7pU8#gt^@Wa$h%!%oqI5~B?J5O`EyG?UU*EFYw>1Mjwbazfo8~^YA?)7yq z&fVwpeLm0ge%|l*1Jj4FN_xXPROHRr=%^6M3#wNPX6*Yf`Cf<;DB#f}A*p-~e}VMx z3yN!H4ud&RnZRIFu3nDjE;cP1k;;nFuV0b90$zR%k&#dZp3VMU80f%v$IWDQ;0e`I zOhF6@sU{xl(F6_n867GoErIm>@A0+0BnkKprlX9G3lb6*-oNWbB~7~<5)$J(h=iEB z=i*7W4orV8eJ{YHT<>8R>QvGc`9)&ryZKNGjH%(xNL)o6OJDl;sUakYV2C^g+2wSX zaUhi!iF^TvsK}o-`I46*5Hd({Nw(8+WcGaId%0ROxmiV7q8rKOXtNWaUqYA475Ky| z`B2r`pu14pj6Q_VgwV53$JKLo;#0|OVW7gCN%5sZ9%rCp%U3X(u9vF_GUXGP?O(_W>J9`wB--{hAG#SRkuczv`sjC7Z z6%5+sn(C5$uzKb8@|^yGC9B1{H%5N6!EB>FMs!A0qGr=IprqV54ncNF-gKR(8xPu? z`*EyWGN!UpTwjwH@P7-_BV$IoGWW@^p@!-EU+ICq`H-ibq`W6Fk_UG%1QMQz(ZQ*? zIi#r_D*U4Z2PesE&he!3&YrafE#z2}=r~B}-awp}##&g!F{D`kxcr?XPH*E2hO-g2 z*RrMg+S^5FtE*vj1sdOgwkUC-+gRnROb~pFy7Ybh(3~5#_mD{qzW-2^wZAg2f4 zT$j6LWL4x|211M*wC1NwtmVgbvL5ZfKg$urDJ**I>GI5@V=f1Cl<<)q(I7;MuIp#C zA<(5HJM%D;$o+0S#WmG$P(Ib*0N3biMVGsP+>NA0VYBZJB)!^pA{ClUFL5ch(=Btl z3y-jIu{r!*zRbI#su^~}xC(T6K$5H(GzXWhn!+EM3M)=y^ZCceKxts%L7(Rf92zZj z8Rj3_wnQ2lMfLT`G}3Y3JWdU>6zNafZzxteJG*Y{O&UZNhpIlcmigqp8#9&CBupqW z-+O42xWj#ykZ7M8DnSjW;p7~cZ}z`eG_c&ap>$CbWAyXSYRNu0ILK$zrOqgxnw}Q- z^AoD9tW;N5|7N$uyXv*~?*9J%cKgP%*=t82sL^Jj!9~z5ThGw}*SO3BT6;tV!MN40 z$oTw91```jY-X`3pGCHQpI(lg_3&l=j5`Xlb6&Lq{yRFO-{G4Mhr)4;=%tDh(K#qLU6$?xh1>2_S; z&R(T~gx%~i@)9I>TP6DU3)c7E-f+UmlxxkFmKHw8btGW#^78Tt6MLtg6eTkdDm>9S zw@|!Ngsg$VJGRb8PC@tM^~HKy{buK|oE!>tbaayA1JghKcuz{+)^F#BOxJwFhiA#S z4Se>$mg0__CP=723X3aRJVxRq)QMx>?o0$IfOY+kv6jM`EnZ(eM z9dQgX;avLE5g<3d=~i-o{J7;Rpk>f&QC9;*lI-nUugCL&X8*qesjLQ@yJMMuuCFBg%S%4DvQ2XaX=ta!qhMMsG9pyp0cSy^k zfMLL2x2MO6=Pddh&tL?Canynf=W|GSIJ$tKptX%n&*_aRXSz(0>VC`k@0C`5*L^(R zOgsMl#840E6+&n$`eVjz6# zba`mq!f%ZJ>0G)b%+wJL^qHfp&6|g*F#&p|oWh$%t+9=F5m6>2M{!uP1Z`DJa`;jCNI>4yXfwOIx=zl|4=x{*ySTXg zfT}#^la&>IqWD&d+ZzfIPng(==+CEu{QUK6YIauBkW{XFJ|fW0JkhC4fGcwh75N3X z0!``&l<<{I#OGa0AxBXVDl!UtAT+kEP*GFyDI_9C&PG15P}0;MtS@R7GvS|d6@_Gm zse@n2X@!ubODgK@%&oJW0HSv83Et7Db*_IbbEf|`@(Dj!nL&az_mhelVHuyW4kMh= z^DE-0yE0)qmNfXMe%9O0=6=spmgxml_4fDS#2oahxny*3kUFzQkCh!GbD4-@q1{eLlBj+=Cr{@#h{ zaO=ajM+@~X#IdolI~q=G&2z&#UO3dK;uy}&#gGYhC1?Pttv&VJ0ePD)3@-o z2%a}flkU7Ad8&M2_7F0qhiefQ0d4T{wo1tnF*HBBM{=uoYr9^w-I?!&)>JGRGS{{Kzi2n@Zm19gsHa?oI{5dyA5Z#xSp1uJTXqKQy+|kFX%Wfsb1i9_`=P^HZ zSb5;fb+gh76jhz(Fy^h)fqkJlIo|A@yS?1K_3n`G4GsB6_lUuJL+8$_8U#YSQj?ho zE8HYOu_RLBy+nZuw?eOda(q5qxv;?mN{heUb0-m9azgVR%bqUbz^S5f&1V-_#Y9{vJ3 z`_1iWmJ{xc8ZOUPm%#Swyu~>lNO^Fr*$@qN)`|g6$aL%2f`XuK8k{{>DUxF zK5{E@CY!msej%V&RMydf*x9iF7_s$Pnl_ebo)lE)REXei;W@r-2W4iz032B&y>yw(?veO7Jy9(WLsER0LW1L z+X*#9Y&=Iu4op!}Ru);3FL!Kp&rm^af&AbY>XkTvE7LsSg*AO^6| z61ad>0&Y(eWIv6euDR(r53&5^Y~7HbAAEP`1$^-A8&jYa1Banmo(%L6Mn*=AF!3X@ zI1>_JF#y_GSXkQb56jIRvlJ~Cib438*u7MlWBAzUm|^1kEs7dnUuk@BZsnc%Z;|}1 zs%#R_aLw`FD*T7p4?r166*IV-s+O5%gcHcXqkAExGHbGvlascKVWwMO;T*4B(w5fN z^qd?zqUcInZK7y2NtH>rY@iy5J~N_*ngXulKz&uWsQ7y^i+h7k5WQ~kkz2&2T+w|rKMl<@`6s58oBuR zJf-o;1A8~V78HaONXK7fpZdNmnHk!O7a9N9asC>}ZA$-J>Tcr%@w{)l2>_7;a=vNh zHz!_Eu3U(GpeK0zV5X$mdFR!+Cvv%w^h%;+A~xugR3b0iLDMI05t^i0O&v2igi9W_8s@Xs+}*kA^B7LjLPa7I}dBm!fUtvAAywV zwy2{X;Y2Fj&9afW&lk2Np0X2Jm;t=oeB^Z5 zim6)ZRY%&)M9vG$-RV?Zy_Z(jT>hQJt#dJjM7*x!vIG5P6@9eKf!ge1&vzy*B9C8S zj01C>PmIz}$1>?%no;9&i2SOmLEe854K!j;a9q`qx|Y`EPc@~f`S}P00)u+cqAs-8 z1PDw^m1*4qa6A7}3}DQYD=P}zWGo>TyqO1whtP=}p(g#R3+*tx?OJ|lBp(1~07nwe zl~y4HQ{ejC{4N5L1)xugxlaj74$JF*9EAH1d1?k`f~pt7O<-+@i+pV5+zixdxfvzT z_jq~D?1BOwXAT|b4)g6kH=GuOs_&{8UImE;0{K11+Ed-T!yCJZd1qr>@^wN77Q6-!KC6S&fHvAO(g(aS3bWlxWff7my!)f@WLZ|NdT0J?ov z{d`~jcx)-MHJr@E5ETr90BnpL=Ou8DJDF>bbVm2nsQ~Yj()eY*XW+#GN+2Xn(ixy_ z6-(6C)}~69t>nD+@61JciSre~_i77-i$leR0+_q%B6 z$4@r1U0YX^)6>pMjSa4sOfN=uob@~XvpfGTb?)4rZ~fSE0)&>Gon6`(05}$D85x^D z%hdky{g11jAr5{=dfyux*bJOXY! z+HO{TtTOs*Ob2ck=Q^Y`G&C0Ejt&ks#y+lXA1~BBZqti&?>L{YociB1v}>P_MhM0f zY?A{Wx_0516UPZs)Usj^^!jGsJ5G2RAyx?F;sI+vBj$ThY|z_QaXguxEIGZ;d{sNWc^LwCxgy zt^E%^pgq!s7@ebtS$EClO+krHXy*|fP6)jIYp3Pj9CLO{dL680nOW%oR(pPTOtc+U7}Qn$bd5QcZ} z-fcTKJNp$Bde3@OX?Ez!wpZ)_q8-|C?(>1us%wbB(Kw4t3wE7QBva5@4Azel9DkMl z$aexVUQ5WyLysd7#33X!*42d+CLRRDsljeZQ_-v9inMNFbUa(I41s{!+uLiPdkNX9 zr|fY4ay@94>-TeaPYDad%aH8XGaoQhNhpd{;2nNTWd7;}hMDAgrK74E!Pf*fM}QOo zG82$vw)lBkvLJjD3k!4&4Qp%bW+oCj`YND502qKD`2&GY>2**)hdHS#$SESC1dxO& z8A6B3FhnKMsJj>Z=9?4zzWv32eY9oFwXfflX%lE)2}8aZRb%j3t!hS>On0xZQ=N7^ zu>Sq~*Q{qP=X97!JPDSZw+%*Q>JITAyAgh`f;A%4rVsZIAS6@X(x)* zUe)10DS-@AVa3J8d@j4#D=RB$FnpF)OF_%H9kcfJ%lDIb`3o9O81njANf2jZXM z3+Xx(3v2yV^tu>71)};Ge}vbD{KgsFETk>4_77q;TKG|JwYct-`Z24oA>U zH7t$P4V}nivz{F!oA^In=5mRMOaSC^p~m#3d+WQTAy*%9b4;B?l{aYRzoM2-iUDHA z!662wFye`XqIrsA0F)CGJp|zIi1PB0-%d{BeYF#*{wbO&tf@3)vG~z%j(9IGFR@?0 z{>OP)^_#k2j^P>Mj5)%$Bug!1?0V**HRtt(t%t}u!4lw4Hw*tgEd@Nj=4urGS+Du+ znQ6)MXW;ls_TUbxG#ZvIx)j$oB+)V|NNPhg2Do*VcWSX4n95^KJtDu&Heqwo|?JNo+{$D zrlV~ICe;<5rSd`ijRg{7k$uZu%`^$_UgZhy8s(_64X+%*mZWidvNKHq<)5@TOPe3; zD8wFKWIG7tZf@)OSNZex%I_KOebqsm|&L8er34 z{|Z z^PCSZ6AD1j<0F`WfFLF|mII*FR@4A#2X z2(vCP&hL+_Q!P$lBRPwN;Qd`EH zTwew4ws`%45S7lL+olGNV=Eu0L><}t)8FAnv5wNL2eE#8b35}IbdHvBNXa~z=KLPU#+{mIeRIH&Wu+ee>|LxK}7sbc25 z01l^C=0RJj$hR3bU<0Aba1Pc6gVYHjI}4V%Tk|!h$1APGbqo6A-*+$XYNuF)c5KlS znPxa_Y1sgj8ZxUTxBSw^-OHYqn``Ooo7K@F?CtHne|k!jt&mrWED2ZPL2Dh6A0xtD z@|e504We75EbITxNzC*4yVJYY>Ez{rj-xUl*Rw~Rt_oCE9|x590-zCAd|^X{2@`J{ zN78QasO?)b0h=1&L}!2?{DSFHls|KFQw1%c}Flop)k$jZApi6ow0zldmwP(cQ3?=fw~`CMvRrZ_nIP$~R65 zog*Q@+0)P%Der;Se8~=X6);#m=>|+bR{_9i&~NjEhuxuZ*9DK|{gGWJe7Cq3|4-Pk9ul;>5B?kQ}*z@vq znTnKUa(1?VMoGk=%9J^KG}h)1bGGflo!n|V0%5*|Bbi}6G{TuV2JpGdX*o8yY*CZz z0Vh$b_`taLZt!Ky>v4F5d9#yKa8l>fm#Dzla3Z#hV#4}9OY-}B#&CQY#E%qSHj3OZ z@zpLh6Uj!a!9-V&SX!z~We%vAu&Tp`Yq95_DQRmfE5Jr!LFrErfUBtf+7LN_zza!z5A44`p|IVX(W5`U}RA6@QB)dKr*n_5j0}ETQnz7 z=5WsHou50FR^j7Ahxtug{STvHFm$qsV#S&yVT5c{p-4u;`IgZaFmt{%_An?|46U^5 zVO?6HZ7SySq|5K{HcGr#@i&-rv$3%`yK9qIR7{$X0lSr=wdzSBvj(_Er$>@>-reya z89pw$XDl+|q32pBS9BH|%JL^u>&rveLXc@N8Ma@6pb+O~WX05wsHi9rFWL&Nl-+X8 z-L{k{<`FXQA$-!4b6Z+1CBJ8a?Y46i`eZcVTPXaMiQ7Ogp_y;jMX>N8&+} zC_!BrqWoVE6*&$U7%b13{==r8H8bt1wA`nU+#}JaT`3WyuEC;(6@~{&f&kq+J=dt~ zH}}l^vE&R0yFm17|M=5hBRdy`iN*W=WA&`xN^~{aJj)bZ@h8;-8}~EI8)HXmsiK5b z|Alwk@=Lw6h?Jr!9MV`DlLZ{=leLYsjAR#v^=s{~UWOH+K+wn9OBJiZgo4sH5_6XPZ zj`J0s`0)d^^XaM@nAuQgj~h1xt-O^^(U-}e|86=BB5UBgtD9>i$cl40=^=zGXJA>{ ztE_G37q7;RoY3SxlOw%{;3xI+E4B;vEj>RlhWM%RW!qn$ECEv02SB}-fNTPEEHlj; z=IpLkG_SWCVJv6}Wri;^yhShnIhU>i5K!WBlXo=b^W5d*U85m%!0>fziA>J7MV=h+ zq^K)(EaHRylV`9Qc*JoHJmvT*G{`qs;pcF`ZMWLnjy>r6_m@L2u^#Vp9VY$U(kk_q z0J~441qEe$ubyH=3xUQFe4|m3D zKp=MRV-Sc@v|j9MbjSctn<2enC*}&2>V;-zICJk0tI&-Oyk=OCxY#=G{MkzwU)KHK zljf#8gQjSwsb$v;TVlHXc8DY$xisnW z_^-l->mTs#e(qgPEicQPn$iFg$AvO?YnyUn>w4JJx6&1CA+8y9V>|n%g7x-f?g^2VfldTpw=?!fAF^{59>@8l6qk zHOSZcw564qrKnTtwx0P z0DbHF=^2wVk|ZA|DN0Bh4JcrkfD)_6!$w^A%%}o=g!Hsbbi;PHyRyo%)B8;PQN>*u z30g1(F_6N*z)6F^-zYpC3RPC)A#C19t&pEvQzN?BWO?=&Vl8rSZPyQo9M~E;fDks8 z0nXs>??U|iW6BP}aKo?$_ctpUdYpNUMap>FmuNBKm@!v<5pVa+-`qH{ZDSSUd&LBY z{<6`L^6YqvcjIj!C8fFJ<85La)cu~irBoor$0aJ?xN&L7jMLnHZrBdpj(6#O^fbgu zcw*ZsTpkfX`2GTuQZv(2d_LM00GMY>!Ey zX~>MRkp@ti<^e`6b15?ipznCJ_>u65W;l{$vNDes>1o%_?D^f;{5!H~zq5dk+&FO1 zBsbdUPtqz9=?f~z=Iz~U{jrvqg0;898Qukj9kSc)f(w+ADhWHA-t4c?LRFTV*6iob zv~N zgl_TIRm=o4P6%VNcnWBghzp^r4hfRw^10FA;Gx*syd!O}ySeDuU;)>3k~PY;vbjI@ z@797Q6@o?UgF2^w?4Ke3^TjFRfxbpbf^n1h#;C~0=T;68#bm@ZrAtgCj%uUc@O|5f z51UZOxQ5|)d8gMxh3`zC8Hz)SLlDR{-a8u3fgFtAQBTP@m1ApQ_@=HYEdO1fs(Aq$+=J5nE`k|89qE?FTSq1uPH1 zkE!Lp$tYn`I-71X=3%&jW>$oooZwVV-y|~cAPsCeNl8iZIc=f>-u^8U3%H>*oJE0G z-3wAI%6fsrOjJZJ`1ix8r^agNSkrP2w$F{Vypjfo(3{;Kkpv7;vS12J04R4vohr4V z^*EiC4|B4q%ltf@gxF4V6JI<#i@tJYD-z&*CM6+RA5E|G{WAqjT{g-}-g+IT%N_!w zof)$QbBE`r5=P4%ktgGuaC%}|YR6{6Wmfw0()iU(Q*0cZe`5vlJY_GzcKnABe3g7( z;>KJH>KMt|tQz?h79rVcmZG?*H#;q@m7rdRX%$OL%k+#4C=?o8u2t=P`16Be7GF)1 zOLq6n1bDc7U~&E`;&pT%L%i#!c*pxSJJ}&+O{)K9npRmZR~@R)emh8|XUS|{HXrQo ze{FBi2E1dkw`Av9_fE|QeAzfK&9`((hKi;bCU}t&c=_|o%@rlv!bOGQz`W+bwMD)S zCrtdG{^H{s92~?@Q&WqHkLTjyk)%s1$(tHV#r@^HF89t=IDhNvO~M;fwWfAe?#mU0 z@{Lz{iHc=0aiM(YpBYMowby5qEF&bu=V3U2*e($Sq8$B^U_lNU~^2 zu>aX8oatQ^nPu3hR;Q)gLw@c#Pl@R*==8jqK_F5LYCBoMV8W5don0hnLA@Y6{O+&g zSN7d~SV_xGs{`xCL5>W7P%BhM(x^9X6a=()^jfhROes#PAlfLE9&m%TpQ3&xiy0mS zLsX0XmW?l*A)P)zO_$FKhD)nyj1pnlH%4ZVrH6+j0g`>Hc}C8~7Crvs zIH!nd64>)Y&fR#i9hLSfRDyZPP$nTlE(>h3Z=hE8FZsb@&Mm*ma> zCCjG9))fy~Wz;eY)!f^6FGx&6Em|bl9hG-0uxp}-ejx3IG1l?OvT2~+%$>J_@>JOes^;k9u3IwmY_7c?H^`z1NFN@5lu;N0OA#@dm9BQTe5%jA>)& zysem$AF6ut2~>>Di+99!iFqTpk>FNwzk#=21xQEsITt2+Ij4ii#uR;p-|2j~R>!~$ z9mL1{?D_onKgHafqEd}x=HH1cxEW8m&w-+a)JW)Jnox>usiHVds>;I3$r?OVzzOY zgK02bQcsnE{nOLw&Ggjo&Dly+hjyNRk*9e7;$l^d7m6kQDN=%LZOUVB9loom*?mY1 zJ%#tDBxssz#s*WR@(h|?c~BH1U?9_`B?n^stvK0yBamt*xY z^}if%L}E@3yTg<7m$I@=be`B)&1+%9?#l_S^CFZN$o>Si--YefoIYl6@={VU5TasX zk)or&=R4*Md&BgD9rdm)sCWpr04;$=GWuzE!Qxbi@o`#%CoFr+5_Qb(QfY}s&S$Ib zolbNk7L3DJR~e94Sa1vlbtm$O5mpW!n^*gUmkCl%LCdy@p`k0q>sN%;nes$UPBiko zdh784S-RIO1o#O?u5dSl-DZ?z@I%qR50GEn<-9z7HE5v%LGjNv$Yx#CJ=X6aqswf6 z?JLYiLKelvlbo-NXU2)nTGG!XZNqOKKo3Qa=~+j5jfJsR?H4*q1Q zy>JL(XykEj8o?8j-=2}JNG-SSZY}vH@_U(HR5k5zy#KdLY5cbjxLq*KZ@TIiVVm31 z1T2iLnyiQmA6lzGkkDS8%}DS9YY-tGm}X?b(%|^}BBEhS}rqSi$xL?wPVw#(6~x ziY{vBR@Uz8mj@WsGCwX!@|$eTA^Ek_qYXG(r1LLX5(nEl%7Uy|E!p|gx8o^C9e+Q9 zH)P^Oixhz^=_@MhnQlz6;>PO1(yn6DL!nTW1bL!CvsZ+gFsrW&_$w=bPdic2b~nP2 zUjr5={Pl||Kyw85NsT@>mRJ3%dns|^ns3!lQ-O;La5!!KG=gk*gWTKJm*kYa_U%o~o2m81lDdfbepH)&VBE@J9td>DXEL8a! zl=*Tn@%0c$r-$;}dUeAx>uT~00rXBwz;Cu$yQN1~v0L^7Mw>l>((x6?$GO4!9QO8h z6)*)swxB-W@!=;LGZ+O`Ih{0Y*TZ@xH)8X5nO>uS(>za(|1jX*lO#cQ;nLvw6SB%j-L^97j6FU7Hwl3JRz~6U~6__m>-X&7o(M=?f*#Fgr^)@ZY1<-s;+}Y7Q2z x9wyG_NJyTGSTdudOjDOGuT?O(X1Ul=k?0msWtXlE3V}aHf=DV#REZl0{|~LZcBcRU diff --git a/spec/encoding/all_types_spec.rb b/spec/encoding/all_types_spec.rb index 29122478..fbd38b46 100644 --- a/spec/encoding/all_types_spec.rb +++ b/spec/encoding/all_types_spec.rb @@ -1,8 +1,9 @@ require 'spec_helper' +require PROTOS_PATH.join('google_unittest.pb') RSpec.describe ::Protobuf do it "correctly encodes all types" do - message = GoogleUnittest::TestAllTypes.new( + message = Protobuf_unittest::TestAllTypes.new( :optional_int32 => 101, :optional_int64 => 102, :optional_uint32 => 103, @@ -18,16 +19,16 @@ :optional_bool => true, :optional_string => "115", :optional_bytes => "116", - :optional_nested_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 118), - :optional_foreign_message => GoogleUnittest::ForeignMessage.new(:c => 119), - :optional_import_message => GoogleUnittestImport::ImportMessage.new(:d => 120), - :optional_nested_enum => GoogleUnittest::TestAllTypes::NestedEnum::BAZ, - :optional_foreign_enum => GoogleUnittest::ForeignEnum::FOREIGN_BAZ, - :optional_import_enum => GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + :optional_nested_message => Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 118), + :optional_foreign_message => Protobuf_unittest::ForeignMessage.new(:c => 119), + :optional_import_message => Protobuf_unittest_import::ImportMessage.new(:d => 120), + :optional_nested_enum => Protobuf_unittest::TestAllTypes::NestedEnum::BAZ, + :optional_foreign_enum => Protobuf_unittest::ForeignEnum::FOREIGN_BAZ, + :optional_import_enum => Protobuf_unittest_import::ImportEnum::IMPORT_BAZ, :optional_string_piece => "124", :optional_cord => "125", - :optional_public_import_message => GoogleUnittestImport::PublicImportMessage.new(:e => 126), - :optional_lazy_message => GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 127), + :optional_public_import_message => Protobuf_unittest_import::PublicImportMessage.new(:e => 126), + :optional_lazy_message => Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 127), :repeated_int32 => [201, 301], :repeated_int64 => [202, 302], :repeated_uint32 => [203, 303], @@ -44,34 +45,34 @@ :repeated_string => ["215", "315"], :repeated_bytes => ["216", "316"], :repeated_nested_message => [ - ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 218), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 318), + ::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 218), + ::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 318), ], :repeated_foreign_message => [ - ::GoogleUnittest::ForeignMessage.new(:c => 219), - ::GoogleUnittest::ForeignMessage.new(:c => 319), + ::Protobuf_unittest::ForeignMessage.new(:c => 219), + ::Protobuf_unittest::ForeignMessage.new(:c => 319), ], :repeated_import_message => [ - ::GoogleUnittestImport::ImportMessage.new(:d => 220), - ::GoogleUnittestImport::ImportMessage.new(:d => 320), + ::Protobuf_unittest_import::ImportMessage.new(:d => 220), + ::Protobuf_unittest_import::ImportMessage.new(:d => 320), ], :repeated_nested_enum => [ - ::GoogleUnittest::TestAllTypes::NestedEnum::BAR, - ::GoogleUnittest::TestAllTypes::NestedEnum::BAZ, + ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR, + ::Protobuf_unittest::TestAllTypes::NestedEnum::BAZ, ], :repeated_foreign_enum => [ - ::GoogleUnittest::ForeignEnum::FOREIGN_BAR, - ::GoogleUnittest::ForeignEnum::FOREIGN_BAZ, + ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR, + ::Protobuf_unittest::ForeignEnum::FOREIGN_BAZ, ], :repeated_import_enum => [ - ::GoogleUnittestImport::ImportEnum::IMPORT_BAR, - ::GoogleUnittestImport::ImportEnum::IMPORT_BAZ, + ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR, + ::Protobuf_unittest_import::ImportEnum::IMPORT_BAZ, ], :repeated_string_piece => ["224", "324"], :repeated_cord => ["225", "325"], :repeated_lazy_message => [ - ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 227), - ::GoogleUnittest::TestAllTypes::NestedMessage.new(:bb => 327), + ::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 227), + ::Protobuf_unittest::TestAllTypes::NestedMessage.new(:bb => 327), ], :default_int32 => 401, :default_int64 => 402, @@ -88,14 +89,14 @@ :default_bool => false, :default_string => "415", :default_bytes => "416", - :default_nested_enum => ::GoogleUnittest::TestAllTypes::NestedEnum::FOO, - :default_foreign_enum => ::GoogleUnittest::ForeignEnum::FOREIGN_FOO, - :default_import_enum => ::GoogleUnittestImport::ImportEnum::IMPORT_FOO, + :default_nested_enum => ::Protobuf_unittest::TestAllTypes::NestedEnum::FOO, + :default_foreign_enum => ::Protobuf_unittest::ForeignEnum::FOREIGN_FOO, + :default_import_enum => ::Protobuf_unittest_import::ImportEnum::IMPORT_FOO, :default_string_piece => "424", :default_cord => "425", ) - data_file_path = File.expand_path('../../support/test/all_types.data.bin', __FILE__) + data_file_path = PROTOS_PATH.join('all_types.data.bin') data = File.open(data_file_path, 'rb', &:read) expect(data).to eq(message.serialize_to_string) end diff --git a/spec/encoding/extreme_values_spec.rb b/spec/encoding/extreme_values_spec.rb index a81a4c3d0706b131d0599e2f1e5798440995815f..477e695aa37676462eb7cbcd5cc355e2f7fc387d 100644 GIT binary patch delta 118 zcmdnVb&hL-m|jt8VQFSjszN}Je~5o@e1Kz!hhA2GW}b$6dVYR-PHKE&2YH^8P zL6W-WM9~PYfTH}8{G`&f_|lCf+$>s{8dEDuic)h^hvVQW8rN^^!94)F&Tf GDFy(ra4Hi3 delta 97 zcmX@dwUcXt*hJTGcK7`J^qkbtjmx-M+}$#BQuR_R3KH{D;tLW>GBnin^z?zKxU`@k zzoOl?JN2XuFbZ=~}ks_I54rvL#C`d6R8yt+v3HoR*9OAyHaV%Wja=idw>$ z>Qvos$w5-yAMd>% znTexQb?*0_T5i>;s?&A7C8J}h@l<-#kyPr)P@;EYBso5wNRQWus3vy(3>0{ zO^uEBj!yIqCHtkiUm5?D24&*_iO@$!5($XRE3FW{+S-wAU3=;Ot~L9)L;H54>Y3=Ss7(m{2w zSCnOKIv9wL$Ajd^cw(&oXnf>IA{b1K4adj5pd~eWd@On7=y(vVt=*;`2s%dkYl5I@ zXebbQ>0m68PK=$O7^v}rqvPYF>Bdc)1`_8dhEk&-Vmo2-CQ)t}Q4M>^h)tds#1aF^ z^!Qk^Z(=-|8VTYf1HnW(0dsx*!%{+x_odEH08!PL7mTFFll_T}$V{e#A(W92 z!i*?sra7pH{-JnsI5CEroZ1MGh3bNhKp6)nP*vIv&lvJg+2K(;5b8jxe_}W>GA^o^ znq(8|KZTsJ06ir!mW&UjO;w8qLZ%ml+g2B)=_jj=lSOf_+{4TiasYK~rZdQagKM9nFV&x?-WBtLrr=;xtf!;p(Eg@a zaPUy+A`-_ciU`pIJ~Z=sMil79;D!#SEI; zU}aPD{x+fl^;rOowYBt6fy`ems5}_Bf1?+4A8c#sz+b43HdI4X?5vFnw7czfhoFVb zptb2h)84l3VBM?L3L2*6P^|3$S&gdbKGfXZ)6sLNr!Cmq)zvC0ySpuRW=Bg~_l{tH z7gc|IaHzWthO{>IGzn^8pt_Kc0yH1$?hqB%(b>}$iyb=H)6vzr9<6*BHG`rz;n`ME z!(E+JTIwrpU9qzWmg+&Yz{cS4zBZ(zp*v-5HBp6hqjR+Mgw;TZzJi7}PKa$>#b z6?m5IJCy|i{Z-&Qt8(hRBF`=Od47%*ioIMCptLG~o>$`K35hZx&hhf4Xh~Tq=R;ah z>v^8-=J@U!n&3RoadV)xreHDQyE!%>*4hg_JVJs?lE+dmq@q%m@YvcipCt#<`~??Y zy~taMVPlGUUd_+1Hh)KE;007J^-3nq@&i1}4^-{+Jel1#GBNDWfpp*?dPQ%0S669% zNN#S5l@?^kXO|XM)p@1n>Gssvf%vFjU5I(H{h1H!nZ6Td~jj zU&}iE#RcSBtjgJEc~{R7zQwB7e2dq7i`n`(ulW|k$=7^~*L;iDe2eJQmUb@A!y+R! zlHpsNA(DbK<6{Hy^;j4+$I0u*S}}$7Cl-c7lNYxGiFEP^mP*H=-W?w~7psN6M-#*G zWAX8g!Rd*?!Jst}r==p+U}6=MCI`QX77bWU3?_%LG&q{Qo)K6D1Wwu`%_gAM1ExjhiU0FvUWTe#VSLrJ+PpP2cz-+^RTcN>klLd+9(z@ z{c&3R9>cOIAs05o@$(WvdV&_Gdi{DNF_IX=qH6$4A}mA)Qi(J%3?xRe45E7JOVHw0 zt=tqgt+UdgO<)z)fi)e>?!}6GsOBiq4WzI#nMl)PT2U8PIX}TJY3Ee?7AUv$^)}`# zF}@xN#@E}J>Fbdg_Vq|s%5cXvE?BG(t8|&NsmAmGaDn(?SrWGwAu_86~X<8A&ZmnoTakoaK#@P+UeK5)L-Bx(2k)1(LN^B^_ zN3csUF-)&T9NPz@8-wJy+&?)QPm6XROpc*F&W{gGU^gcn)QXyOa> zzw(}3?;q|#`eoup55Js|=`3a{U#|3usUu=Pujlw^BJHpC=EzPTAL_-XV0~1rNlG}i zgA%jVwlq}O*r0S`VYMv{{#tJ?Ki4}U;T-6d#5Bnvkvd5cfG!l>OvNljj96q~E)>g* zV)tZ3QUqci6#Yy^Ag=dHwT*+x3lal>%!g)vOxxZrlP9YJv;eAkS*k$Y;FW3AG{Y7` zcWzA6b*uC#lmYBPxiniD$l(?m97@HvktZSx3zuS-= z8B0x!R+K`^i&pCmZM`{O6YichU1C6v5ACIg45+~H6W&5Lx_1PfIx*0TX^-~MD}2Bg zy*hlScuH-&$L2FyMza3~uYxmru~(jeuc3M737!>G6a&j}(q!xf43U}c_lC+KeGiRY zF0j{5#^(JAx#njEZGA?ve~wqq)Lcn4GFHq7`kZLhWc17ikX1pu5;31~Oqw6_G_9^1 z0lz@NFPj2hRe*q;$B>~!|ICoZs!9apLIJsIGGu0bWZEh#gVOvhAzNji?j21g`V$ou z04{8{3+$M-NA~W6l#O@6yfFQ#v4M(3O5ZXsO$*ZfF>e`{M;!qv%XE`Q@Z^-;l8Z3K zc~ERIgHDl&cfd5jQ2fHsHSRP)rXpGj2F5N_5)63&}%*hkCXgRHBBrJ92`)U zaB2rn6P!S57}Wx(VVdAnsL4T{6L^|f0X<9;oNT5EP7#U#tb`(_2~H-(EJQU;tb`(_ z305@I1gG?>X<`)=F->qXDFPAG1gG@!c)l8%m?k(qG)-`lRE3#qpo(dN(}gNfF->q% zubw8>LKo8nXN0E-PE*PNUI%4N6PzKHfgEljIZdpGCZ-A2)YAkf^r~s13VN6(IN3}S zoFb=*4N${0!HGOgu-vPriH%UhG{MPcn&6aPIZaeU57Pvv>S=-#IoV@MRA5hk znqZts(*$R5C5b_|9_TZiCKxAkn&4DjHv+yvz`yD=!4GFm6P(OdA|N*l$Z1X!jF34^ zaH{IlYMR&rU^Pv!Le@0F$-QEl*sAm~O>l;oCNN~P+?z3EZ^r{O?TvECX1wr_jcIEj zF&Lj18doFsF3bqIjdnv_tXO4WG=^`VsfZ!wG$=YyjD{7(kT{1Cm2}T zxYv6bssP;sRTrua8LB|7GOB9iZh~rAqf_0mS?j9NI|Qo+?`G)wfZdXzDn{D5Y%CAo zEzr$}?$#I^$0PU#FH;%zwn8}%%G)xPfn4pCGO`}R+n_xc+S_9cq(||ZY;}OQL%kFw z++3TbFKU_VvR97dd!cMMx|{22HtPnFgZV~Nb!sf%2VJW%cQYb5YITjM5q+)4?JfuO z4(Jv%y5nOLiCB>;kr>rOuxe009jb+mxknR-rO>cyXs791KMCY zzV~|bxavlv!!BOg*Wrm74Kj^%iWMtUSfPRDjb1qu3@TS$FvJAItBf;^ML551>)6}b zOX$7=3XeH&Hui@-({6!2ts$q8PxitE2#r45O#x)xtHGxS6orjWysuw4s%%_%0ID+W zE5@Hg@{zh|Jsz=i6N@ourB{sIq7-71;O$@moPuu2zMNQ*NL4R!9FDk9QfV?~yGC7Hl;JiD(??PcJv z2+m)-!fQ#2vWi!f0SZx8amtQ`eF&MoNo7}V_q5(krsp@GWpSe`GT!s}drhnL%bG&v+sgo~o9CoghpCO;LE&-mND{L%Pv>;epk zU74cj@+lq<)5Tcd-yibpr2&qZgr;eLcHdga_{uh~oM>7Tqhr|I##*7B%AA%XCZ~nB znVRhii$*}s6BAP9GH*_n`-8^n=fm>;%39ASnwSbilO(6R1$L=}f9IB#;@`s3;+WGH zAESRR#OZsPDu3Gr2=$>DpLA70fmQl0{Ku|b>n+Ua9K8wF%Iqejn9)tL6?KPs!1Cr1 zqv|yb7v1f-<4E?W7%SN2G!|C;iuR=nF+@{o#lO)vdJ9J&VHu`|2V?5=Fn=vDWAi17 ze8V(l<)F8a%szmzGu!ktW@P$rr0Jz`1cg!bA5L||F@!8e<@5P+A2ODB%S3W4F(B*N z3T*K@`iMOkm>3>D9u*xrH>M=g>Z@?1R-e|Adxxympwl;ttwK)UtkbuMok33DqSLpE zeLzm%s?)cLO+QZGrqj1q&;}o;Z}%&_d|`E6t=P=Vjj?EQ>cr-q&Z#pwQL$a8bD}1v zUhL56oO+YfAU5T6PJ_wWEVkiv&SsOdMQpw4oGm72s~QfK)mu%@HnE?kpV?+|wpY*& zn9ebE5Us7C{VUFi*6L@Xbz<*H=a@Q(Mk{FBNavV3h}Kuo?vKtfbr5Y3+c!GL)IoH! z*r?GtrVgT8Drh4{=a@Q(Zmpnw6P;t~AiAw$NjS&UL3De?(r}KcgZkQvWucsUQwQ~R z70bgprVcO{2jQG3_4)pa6|&FwN8jY-!Sh8_@-&B#U(kDa>KTFGznDUep5x^XW66-5 zCj2k+#dLA12}i?A(8?#&u*m6ZnDg^iF zD)(~58;voCdW94!lX5mu#>;Wi@A2jgDvwhRtzy2KshbolQ6Lhv()UVfJZ>8v9p}Bc z$|`SJcG_V?w(3DVJhN@}7K`zmnsjt1p><*u`JJwE3#v*tROJ<%3`#$?qRK0H*SlOb zCGPMl=)qVbJ~VWEe|+pnq9=Z&b7HtJF~(yx)rb}M%Y>%|hv%K5j^J!nzCro{u|)sG zSQ_EDT%DWA=aTI@#eRjD0JEPV2D|}DH4#|J$}S0hU}AhCKBUxBBTfER?eP^wPlcZK zP;-o|9iI}g*`J2BS$IukZTP%KI@femhOJWG#+6Ra7vKm|4Yy8=3I}G&y4~S9gQ=7# zyBA%53a>5`p{6~RiqTW>Daip6U3c0KH%pIcEHV!fgTO%5%N7$}G7_PXnOOOH)kSga zGR6(v>J_CY`tLwzO^t#It@2-Ur3cx92$Z1~#O}z>P4OuH z8gI_Qu_S(}fgwR8E0=x_;_ySMe&7{Jzf>yG>r)sjlK!qp@^^ZLZ8*}A`7}1qiN4C( zK2}Kk0P^WJulRthRtZ2S&(o@bVpU2BgN+?&rZ^^&P;@pe_Xta+y(SOEDx|fyRHUOWk%iEI z^@`L782Ul~kXO!V85QeIw`-NNjp4`r)4U3XomA09R5q~{Qo+w=>!4b6Ax*^>s|T%^ zE{M*o{ID$tWzig6WAtN^kt1n;u~#^JoDVqY^t~`vFnnC{`SZOzWa70Hz1fN74j;!G z=r8i1qIU2Sc*Kt74t#U*8Op2OG`v<&|M7lpdip8kh`6J_t8`qtK%}4yV z4*%VHPHi3ju4_1F_S_MFOd>bGu*6|2YP=3uo~JVcHL?@7^nU()C` zM7K9=-?BBjeRHfxjk_4O<(w)o;P}uqX26IJ!Bc4HkOAoyPL&?a^p`{nlu0{g!Q; z8@6uUysb9$7)Z8z{+RHcdc$0F=$^r~jZX5&#p))DBxCdBM?p+0qp67}VSs*>S2Qs` zxQ+X)7;PGzA6@d9m`CZV>js{8VPY($dMT|G>_)3LR!E7mt1j~jv3sQyDD(vib+H1Z z$$aq0@(qf}6j~44jSlTp%Q}==*svK%9Ko;2&QJ6jI0|^N8|~`4SSjarG42L$4yP${ z5%kjNRugs!=SlcAp6nP(lfqu?#@uLPL+!ShC%TN(+vb%^WBGCQ00qF~iiEKm9i+qx@sHYG$2kUY(W$iFT%qSylVUOQIpZFm!6>yT>IEkSg0M&uN=;x9pVXoi zJFtkZ0RKphZC-Kz=x8s3dX9|6M~{lddtu}J-2whj{XhNBCj7TLRs_`^rHN5iO?AEW z`?_B0J7Te3*qDd&f*c$e%t?z_AzGxIja*>?JQm zOcZmbbh*giHIL&Z(omJly+XVmlEwEumwv}9kP2hs?@GMQv~M>_gPZ`VftXl8$k8^8 zP^|JnK?vCjbWkq=5IrcyC@xnRBvQ>>hY%B?AP|va!y1w07gF;S>qLOx?GLXv?NyJVuw@= z_c5!lIajP7E3dS@B^t3A(dhU&>_ECDH9U$j8Igki!mLWsRkCz)m4qu~&ul6rqdIyf zRmZkd_&%cfrZ8UD(9G+n^0)b(rzUqkuqV}aTFX{sF^=y-TVmzVto)ca7k18%&(}`CgF+ih| zvWounJ2P8Q?iOyC4wCB701J2T)=+zrzu-mJ{9~~8Df%};E=65sL`RSVP!yesX%riw zDmJ`_u*A#9zK9qB$W_Q~v^MXvVtGiTL13-tQLY*U$Th%3MnBu_+zYKj z=;o%gsWvW@wJ~`_l1C$Q_pVQzhZJH&inL{~M!@=(i3{|2?8NdQ5-S#6s9P)tl2}^N zCPi+nKqMd&2XWIokX0if{SWG_^5>S^y5;@ne|}0hl==S1DIt1_E}ucGUdSn5qsX@G zYC>fFm^v$Cw~4z>lg!62w)MmRBu>mq2 zH7jEMLuy!gya8%XmKv5A2pdvpDu&=3=#>aP^}JfBWhw&jjZk#66*CYixCbX8Z-Qc3 zSg~8Ahp0&rh`mtsvlW4ecp+sY#{j(JIPakyW z3SC90!+)}s0o)Je(#gs|UhQ$!OILjWnzqnXEhL?FQ=OkM*m1*=zeKIGesdcZM{6MH*PI>?g;pWNgo1x~B zy)#@dS^YCqFRF*4D{IU9=+`LRM{{DuoFRJY-jL#q`e_JA^wdBe_Z$=>p*|1`ADUHq z3&<%vq^C}yXDr307`7cua7e}1X~sw7xXjSXe!Dk^$`aE2 z57K=h>GXt zVi+tmd&FV=QZ@P;?QfE{oT=2*p!Fk-p05lHnS%|w5-#r`1xZzWhJ3tS#7oL{6g$0@ zd%d~pS*m_22O`XhTF>fiI?&M~E(f`~ESy4jdt8&1a(3ypWtBJD-b(7OdOuzC&{hu3 z!P#zi@5`x!3SFafOFwneA)iuShBXB^Zb>+nV z3TaO9`w^oj2cwsT;-p_YtS7HYwJmum;C@ADPWlB&<+qCDIp#s^-C)!IKmx8OcDT_u zqe~qBmw{n8T{>f(4B$IeL zenG-1{$cYwC%HXA8?;`u?i6obxT5~?@ALr7c1qxKH0m^gW8tVw^K%h_6ZxHM;_<`_ zlin+TEuR`gI6$6wvFgxVbinzl6{6JjgA{uC`w^OjfyT_R=pU>tYH~V@I*0`~M7fRAEQ`2G7M1SXY4PMB-#uhlG#zjuMhn;RJ38}y_OpmuiEeQ@ApLcxY!X; zaTALSA5{Dn^=4DixzaR>F`of4sHzGJevvQ3exgSa7p}sjX=3+RPNOSQ`%jC$h@mk# z5))f9eWvO5nIeV;6DCm+1BLBQ+RX15IXBTyw>+rX*k8vXE`^Pes!hSp>VR)7Oyjn| zA-c9PnXW-(Pi3*^VYiAF@t8>~5!fxH^eBRf6BMZhv1KR;4h5~!y6L)14vis@W(3(7 z5FtsBD(t7KcnX^DecY?Szeu3#yWDUBP4&5%31^q)Rh=QdTY8*MGY}gj4r~1a&jmys zt^mVdc($(8Hc{&`GpaMArFI0{0#zTdygB4Gm=g)?HWzf`Cc*Bu-lo#G;^>&A=F;1L z?!X+DTT1W0?_GH~9Os1A(m&{+_)v0N>1V$GcbQ>@z}sY7;kY z`mHiRY3URl)HG6L>ZlO3p{#I1LH+wvp_o>h5+&4Zjc*E#0>TwCPVqG3DCy)J@g4kv zbkLF*eOHF6XX9^am@z*27)}QMmIj0WW^WNQs|EFp325W1B&L6lFBjjZW|&10Xs_JO zWH?nBomKpXXbCPTOkeO^SjgW4pRF$Imq`7wQCf!a_o zrI^Gqi>8owU}SQH%Q4{T->mCjInTHtw1GS~raLBYU6_(gW|>7%08~;YPH@GGlysL5TKKXgkKBhwYaq z1T)5$H;ZWd<%xn}2)95V-6k?)0@^+(HZ35IP7FR~In6B{s|1g{(;U5N>F!N=mqu6k zH)qCfV~Zd(w%lNOEA$W`<1P8P**rZ>tLPAC#_{L+1`Byyn7v!l_%X|?)CQ_Z(pg(b zM@iG#FIvu&$~&55*45#9Q$NidR-v;qZOs|pyP|7M{)%&wX&<*j*Mg`fO~5^yaeL1E z#uhyao3mfj)h@L>U9A~E%Ac`e)4S_sNmd(@i)yU-NVt|%1J0_JW^zl6t{>TSnHHr& z)uRTsQMwOi#?@o4m(f)qhd6Q2YpUSQW*8Eu$}=W1_tNOGnvS3i!wJh<$E`5+4K*|7 zoYjpstJsJsZnQDhVk|TrG#m;rVlj17~Q=;*NS$!>ob ze-_@2ynQE(A9igpb!&Xu9j%YfxB&9n9(}*c6mEY8!z_wWiM=Jb{R~44rz*oN-Tswe zfZNXuQ@H({rEUzGaV^OkhB6q!Wq?br8D{JD%d3fWf1Jwg&*YdzQ^-4wGC9KKfJ3f1 z_!M%+b+s0)0k@xlrgZx`Q{Rd-V-|UfQWi_NEa7*1c5c7Ceo4Q3lihw@idnk-^4=!h ztEO=KHN&jjetF@O-ZPx!_G|Q6y8ZH|C~f}~Zog)jo!c+3n9?mUh1<^rvvd39VW}=bL-R^jMwg_LC#6DgG%(de%3T z=_;7gk;cl0Z*7{L8)~jLo3DVfT zTR6Vdo$6<^a!0z8UI(sOTp7r( z(Nvz%mGDK_w13JmiV54MK6)0Hf|C!FdD-A%MLeaGgrjd=XaCIBXt%Iyifh7@=T&3; zp^R$^xzbFw*#pC!*IZ}+l(&?1zaiJhlpa&RdE;i~FlAkg$S+-{({#4CAQieHamHR* z3YA?FlNTsv&*OLrmPv5+3e0xRG76FzAMq>})bb5DAkRold+K7(a-?|+EGksR&K_W1 zkGsl6mCkN>83S}Nt|upmtWo8VHxHLBB>31){Zz@H>J~$aArUciU3|SmMO4^aHhf%H zgS5P{%PY-*g{v}MO!XWJfr=dlRK|AesctOF4pY}Zps-@)5(>ECSdk2h zjOlyY6#T=BFhzLs#zdh?G0D@NHV6M;!-~z9SlRDLCdupy!awxLAep)(lYHH2m&E)? zNtGnq*)=7ZBWrMhXm#M19YV;0Tqn#KIE zDohhD%@J>rD$Nw`?zD?zew3y9>r@VJCeiE)WPZ?1UJN-Dz`}ACjqlmhJ8KdMZQwqHH#ujDO&RFHOic&UAL)sR^?7fu>!C>HmOD8IZXp zb;PUSA0ACQ)jQP{Y?FT~q{r!;*aC*j8mY60GP>RjhDom>k|W1127` zb7Bh_FMHI^rkZV`c;wEaI#sDAjovdT6_4K`s_YRwT&hW9_zb9c6wjgxm+Cw(!gb4^ z9SOZ;GvMN}JSV2R^Q6&y64`8oFJIWgU@Cy(rt>1JCv z9^EI=g-aKHnX^au85E7j_|VIoHOhzk;-qnY224EChx%gnSdR~<=oZV`+L!?mkM}vT z`HYr1;$MXLJI=}a`Jz7qp6L$zAv-b#{^q64C5J|m;|MSu7vERhXT8g^F0ri3E%8C@ zhi-Med_Q+p&Y$uYc(0Va_DO7fk`!MdeC?CiuYD4GAQ&7=4bw+!@de#*#FRf2bAL`ULo5$NrAJZJjM` z0kXRY=5R-M+xnm>)&bl05+;a)!%ZMP)I-G331F8e|L*7xy1UwY4mZWxHj4HPI@*J# z)-wSDtEKkAuI}y*X)GmmA8Oebv^E`R+S^v+MeqH8<0rA{4IUa2pVP&5xcES{_=E#~ z9j(6ry)LKHdynP01wYTnhmIjdjs)GQ;Y1)lTb=ChP0OEar2`rAxh}mvhz|^4>WEK_ zr-pI;7=DO8bR3_l?oK2cgW%}+_-Ny%O-E9j#0PGp)e5JYajMmBvsYOxAgTo#f3P_R zpU_>GA5q_l79S)gG5qCelH~`RbMT$$bxT*M??kW9S>-Jf1;IyoAxw#H0e^k|lJIw^ zNeq97nq-M@0e}7Sl?uNKH6`(Z0bxpf`UG&5wqJa3n#Ax2r%6^HoCbcCwts{EayF7l zkV*~^H|Q^CJM;-_5+x!;6qaPAOpoHr+4zJteYd(gf1~#^`GNCj!J^1_|3CDB^HYD{ ze5wzdSL*(}6(2GGiR{m=??8%t(~=*YmpynGwc@qDA>o&#%$?oZR_psI2)r#Iz?YclP1gVq@#O?Wu)jN_)h$Kox zh(IJ+DdVH*+m}^)=Xkc8nx`G~ZB*X}SFL?J4O$?x_68I4U=UC@{4k5iYx z$Hx0pBZFuQw9+yB4%b638A@TS!xzWLl5yO*7!ck-K!A82ondmX8BUBJO%0@L0(>R@ zD27N;D}%&1f;K;e39yTrKIr3X9;?Yry5})DlpM!MOD!P_i5}kU78@DO*j(Zp8MV?p zZ@!Vy`pp%KWDTOV+&24kRfD2-+w#k((cK(ZRA4(plL)AGH(x@Lj6Twi&co`+-WyV< z52)`Asnf8#H>3`6Ur61C`o54ljiURYzD^kfyF1*H%0&S-;PB?5`_r6*N|aX;bCtj@ z2S^AYrRpRP zAl(`SLsO3i$p=V}2B8tJM}y=8q(_6~1EfcT6!^{|4N?G*LmH$2Acu$tOdzH?ZEcmO%9K|FvQ)}74* z$YI^tJb)b5AVt3OdJR$pkk@OFB7nSJw@wj2UawoH2q3T5AjQ6OmIf&X$XObs7$9fO zKa(VeOUI&t=uNJ03+X{I{Je?BLy|%ICOwct2H2bCm8*dq zGKk-_aFH5>N_{78cPg83#{?vPYfHf!FRI`?z{G3!vILO$83zBL;u>_Dl4dVMwzkN_;`2gwHAU;6)i|RNJApKDqm zNoY&v0VJV8<^d#8G+#Y74b)}0(<$g? zl;nFwCW%;(7J87F8gOxmn9&yc&bf9}(Jq9!=W25o!rXJUxeEbwE^geG<}L)txs^N& zFNC@0uEs6#!rX<@+;i99qIqGiNPxNLuEE#Tg}E{X=2DV0S0xb((n1ds)5cnFt1!31 zcZcnfs>u4FH8GeRfj^tLnz+DWGaSgHtM23Zb}3pB`bfLx$KmILGh4HEdy zaSajxXwK~@0dLJd;s zJ8#t>l>m9G2B`$dTeY)N36QsHXQdJ#Z`B|xedlc&WF$~r=fKnnxnYFGE zJr;9GgfS`??!>z+SffOTM2)o0ci(N0)&U73Bdr6{yDij>d~_X<-ff|BlnA7E6Ve

ryA329Tc?_O$b zss<87MydwVr52nc`DiteF16qtDG^AQ8k=f-_d^D$21pPYsRl?Nvfv@fM{9ueAqy^& z5`pv~gS5$aFEgdv1SE)zvm=Dl3M@wwIZ9-?OoHViOAwGs`uTGTlQ&@3cZ&jw&?HauIv1Ce>Qfahw%vjsd?8=fuTx!Uk-0ngQjXA5|)HauH> z_Zq{q6+94`XDfKFF+5wrbB*EI3Z82W&sOkUV|ccL=NfA>x6d};z1Hw-0}n*z*#@3# z4bL|4Tx)o?f#+Jovkg4g8lG+7xz?0tyYGI&@N5SUMCREJo=;eCyJU~r4xUe#S$#Wr zK4EyagXa^5XFGU4VR#yS_d3JV2p)*c(+HmH3{N9?t}{H1;JME5G=k?k!_x?!>kQ8h z-@V@O>;Ml$=Gg(B>n%8MvOGJ$bG-#WQiTo+j`>WS%DQ z+-lmV2|Tx&_Gtpot%j!wJhvL2Ch**9c$$6pHp^z$su?^GnWq_Z-EGEuY6j13*1{@P zZ_VJj&8n$o5j?k9b?omogXcDD=WbP=7T>+y@U(yjBJ;F>=XT>;wSeb#YauTQTEKI= z;b{TS?S`iXJhxjr_bSi5)zAB+W#3_KQC78r2?@;93Z_pQ->Vf&cUXDsvbKWh4r>YR zNRlJp3Z^@(<(pXq(;Ze-gDO#*@7`(IT`IE;JP?_u4J~x1@o(C|bEkzb1xw&I@Z4#w z=K{8Y=T2*5r}7foq?d4~RlQqz2_gkv0+OQ2OOQ$M5=5Hx5>%Stf}->=M55rU-_7(W z$eq?ccIw-G_k?A0W;+T3kqgp}f}Ah~X$SZT%jX(u2k;46>d11nqaY`&RkUM6J96!^ zASbNV_%4TVF+~arf}|={5SfI6h%{Lcl_t2L7_t%_a>@5X_oP*{ zP;u=A^+_wTR6V-Scki{_YL&SU-3lT*;`{LEy{5VM;n91o^|WnCtR234pJD9)D@11P zz@zsW)($*+pJ6@Sckj1c3e=$fc{(12SjZwCz2EY9t#djaz2B->?CrrJwB_eLWaa!T zPNAbyod0T=ZHm~<6`UHeaI@HC=J)eX1nh`Y}xo!CoF-4 zP6JUE0wSv8VXJ5<=idI}E*IwzB?&~d$YZ=Q01=NqW|c`t8X`y@vsSI< zXYsZ?X06#O-WKG_x8*Tw?H1AFRSF7)q&o4oa1ttCq|w`=(*ze3>1|Pof-kzodjksP z_<2uQIiE)lIG}cgDVT%eJO;-TV?htz627FJf&hl&=OIpG0`ZQ};*fx`pg%qm97Qz3 zP=dlD>Od^>MWsN5%}-kM z3CYgI3;jha=gYDoa;Y}IXywwWlbee(XWxAaC+PGXNyvm)!Xm2eDXWxD5l9!APa9q8 zMG#pR84$HDq%Rp=dK4n-QXl)0)U|OGocC2L=j*DU;2m?nN-qd?8n@7Qzh)K5x5X`l zt&oaE86iP4ECN%ARCzAWIw8%GdrOeAM4^jZsVgLW-;p|_TS&Hk&GMz215xCP12Gun z`R>2dvQ<3j!5~Nq1}CGC@U=|p{JDPKGgi(wRH1Mh?LK1_(4m^+;-K1n*0NtR(*r#0T>zo31E>yZK}a&OhJwWLj(c@1xB^| zpA1H$$$v5!p8pPmQAKJn8di`a!4Qc60o#*g3|0Sktnz9p0PH&qhQGhdVAu~dU~7~&BisAA%g|6(uaf&zoq_ZSQj zP6iAi3X~(ksNuiIVALhP$6$z0fS|xI!hWB@^1@&URiGRRhDZenSo~3)Ay5HAIYnGS z0ND2#3{(3L7%V>whL8oykzj~efS|yr2mFA+5U&71S%#7JhYVH_21DoqFO4U?sl$QwA#ugCWF$awHfc93Uvm z5a0koS%&xq2+FcKzWXxq1_0QU>4Y@HMU_X}%7wHQA0!f-BiZ=;9zLkKhk=h6K2 zOWNnBu^SS&Aj&BMBG`UOd;BUFIKQMFekFqOm$bi6!(OTH{>HK?V!_GB*DuT~jGza~ zk>(@j0YcGgsRp>;SZgTu49@`UH`eL<1z4Hy{+70zDWfb5hTsRvkzj~@fPkHTp$4$u zT9KVn0N8J>-A$rueLwGami>E6_6I)w7PoqwSQ zxaTcb8j9!$2&?h^R}^%C@4jH!`-RqmFc<;$k}HAM?P|{Bcj?+#T1~2s8 z7r8PQh7Crj1m#GB5h(#d8H_*)2>37?8H_jy2peU+AWQ4APGv? zEDYut37J9$>ktWP5D)@ERw4kx z{j23l&jaxf5H?Zhj-9{A&-=S&zhp_@V^J6m!4NL;BphNPAgGrRp%Cs%mWywh0vnMK z5Z1^Jv#z888MX45t!4MWfIT8#} z5fBs@f+8R&FvLVaP+&`Z_dN`@Bn*b|2+EOQh>n1urVRu~Kv2^LVk00Zu%$R?Ww51T zFoa1^js!!L1Ox?!APEQx3^5WA6xcGHurk=PFc`umC`W=JS^|OsL$Cw{1%_A&2nuYu z?_R`U%fny@o1h#ChNuY$3JgIL5EK|TfL&}W zFDwAq#SFFr$G;4=A`FHw3d)gSh@ya?z*Ye4{S3AOVDD$JN}K>QSY;Rt;S`i3!4ORW zK{-y90K3FiUKnC2AgE%l#33+)tqg-9tb%eR7@{g5C@=(7Ku}Ul21B?71=7=kSzC@&1L77!HJS{yAi*xE1{MO`3Af~^JEWo+46 zfL+Fxtp(U+47Sd9Kg?k3!eA75fgA}&VHY3fI-{VA4|AQZ1K5WNj7CrdTwHG3SJ=`E zTOWp_*bC%IIEuWu+*V!~#a&!(D=&Oeau!~7{V+*ZYwWrLl}%AE|4R^DBj}Zw(`O#+T!E3^1?O%?Bllb!Z!MO zSK9Vfh_IpYePbAo!Y+^};V9_hN?Unh8v%Eft-P>}fV;|8UKqkHuCbLDRviYT$P461 zFp9gl##UY!MO|EDD=(}XVAt5n3q!=kwYKuYYQkU?e1RMZMxhti+R6)~z>8~b<%QJ% z>{?rSVVnHCPuTW#*p#G#ZVJOu1P1aX9K~OJ!d6}wMPFQJD=%yl;I6Zk7lz1-8*Jr; z)rP?+2m?71j6yJOu$5C&3$Pn(<%LoB#SOOd!fG+4-(V{*Ood+DU@I?-122#uy)Yei zAyQ~cH$fL7iJTgdBsi28hJcG3xiag*22<<>a-_i&d2u5fOmP=C+R6*71K5qW^1|w1 z@Qt?e!bFS&$;u0pffOP^dSNQELZy(wDn;PKRU?B%lHgEYSk%wE*|u*{&O$V7G6h{A zPnt|27dP`;69wcgwsM=IfV;(3Zc`K{-(oAbNd!lbtlTCUK_L>P+oVD&R0^4_QUtzo zn?#b}fZMbR;}ilcZnN!u{~*AE`d)pwC=_dfXJk?8QTw;?a7b|$xA8ztQ5Lt^h#V0B zD9UYigIw#>V=Lq~drz})wGm%&I}8w74PhDzwLp%fp+Jk%=Jd0C&#R;aN=!z3e zL$MVnm4T37}W18Jz8j7z#j-;XJiu>64q}Yo4?D8rxKMOEBq?`{#L z*@J^hrr8sw*#jEnNSZyMxt~k32Q>F{Y4(8Tex{+Yiu;*{f-3H}cgroGCg1%u(=>%? zD7peUl7?a{KFw{@1e#BC+cbgZ(@aBA6`y7rimCWC(U2?K?B_jT+Yj1u)1Wy_MBx?4 zlSC9;@c_F>%^-Tvc2|gMqri#>?Nw`}0HOzNoC(srKtUA`+R@E|sKw8F$hIFwpdw|p zgo!A=0(p{%qAMO^_laUF9%g@sA}byye@6g-=wW-^ZYhB1VY~h`L4=r!M{N61MD>wg zYnX__E08CND7fMgcC1=K^eC686-1A6i72e%QG4w!i3Xxa?I?x4*!gXK-oM%QXKnfo zt&`stCZhNXL^|VW-$hQSlQhgIGMHW(?v#m*nSGDK#sJZ zf+`+k`zfU2F&p1&rZQ7N#bdOJ5dtdeF}tQiSg(R99%L{ zj6x)l4a1Jzany zisA{_Dl$64U>yKMjs&CViYM4IimiBpEu+YaC)hH?RXl0iver)zgPjgA>Vv+CBf+tw2^_u4%ZhRRf%;-{8iBn1xDP=7po;=q@K?G& zg}Va=k^{j=YTVK+9{rl_)}ttg(lCpEu%8^1m!`zYR$Y=nTswf< z5OC8qB2UJtz#|lDfKsD;9)7JhfJ-Nko1mKxq;+(t8!8GN>w=MsLI=BFGer>x=QMPy zXHk@|*){YVJ{yPgdC%B6-%>3^hjY)^1yoAMEkp}FYun#M3mrfU6;ca5XS=&1yHyKO z)I%^ZK^Ib>NTEv<()1&{f#l#I%7A+?sDNqQ1d1yjj-|%VlVt!L%J3{V2Sk(s@UjdL zQHJNZ3=m=2bKD#dQHJNZIUu4rp0k6UqJ$999M9S7cX(rjK07#^ zK+wkd=ue5!_!wEOLVMDpzfnJ;D>cUG77yxM;u4B<=+=j|X?e^#@gxVwQc!|`&%YqVWIW{s11SI<$Aww|q6;K&r3CJQ=uE*TQL(rjWFR%N z7S%`Be{dhlxFf?0(+xq3Z>NxfDg(H2Vq$z07j&U_^~KZjCY~TUKvyKtO%-GYf2fg* zN;jX-B_wnW2lY34ap{=#`?k7T!=sI&AJ{6U1rpi~qHI-&Xty8G$UvP9A|CyLtzudr zqTPOAip6Ihb<~|D%Jjj)O z79z&$pV%cb2n8Z|equ*ta4kge{KQ@~s#B**Uz5=On>8zc(gfXGM`!tr~9M3e9D z4HB-OfT(L6fgJy1kSKZsA|p}!#{U>3nk4?mE|W8(XHyKv|JaMU?GVNB2ZKbR8xR?Z zf;awPkZ4@_gF&JIjz1VAgmC=PAW_@~L`I^>jXxSBirx65L89o5KN=*&Z~Vz1QP2iN zMxwBdKN%zn-1w70!j%*db?Fei@w`Ezhz*F0L@^uB8zhR_c-|mU+{W_;36UFrHb@k% z0g;g?VB^mQi9$C1Y>+5uCY8@`3ahgM^@ozZxWplz_-c^MLeMgGA91e>F(+fb>^`goug1 z86*mmfXGPYK>C|OqELyy86;dF0a5p-`8WkPNE9Ifk&)&D>F)*!mqX^o zlz7P?QFsJIMxp?TmkbhxNW5f_aFql^Z4*KmUN%S+w*ZlmD01OtgG8|lFB>F^UU=Cc z;qrx73=)MCKxCu}AiZLcD5T&OgG50EuNb67I97M`j6jhD5E*F^kly8JmxH1S-sR|e zqIiOLIl6Q>?SHpHqGNrCj6?_f?>0zuwEu2{M2GwDHb^+$e~&?;Gku7RM5p@iF-UZ- z{~m)xC;RU)NI2VnuR)>%eTa-iNBZwINOY+GUV}u(`tLPJIM{!mL88-qh>S$%`R_AG zbfW)0gG6Wg?=wg^)xXFf(NR7`Mxw*~iwqJS=U-%y=s^D>gM=gfiwzQ;<3nU5I?2D- zAkkU=#RiE^^Dj0?0S>(#nq=b#UHGWq^oBKkBS$U=db+)Y-bt+Y2j8{Jg82 zoU38wcEQ>$5b-9bDZjABuSB@nd@3GA*oB{n5OBol_t-PF$MvuXj{P`5X!< zzur+H<&dBWQHGR5M2EQEK}b0*;SsiZlaup*sNPI7{7p`Qh^2CA_P^P&WpMjk!o1lj znJelX5;VgiFoj4fK6>yL$Cg3+bICKl#Zl`TNK%wP@qvg3Z*k_!z<7G_R`VdTZZ!{5 z*MulTIp^lmqU}~^!6I)TN>Pemt2sG$p>-NVU2`lUF7m@h&k-z(<3|E+6}dF-L;iVs z8LeuSJd;m41%dZ=^vY7|m3KP!!bnQo^eB+9))`Hu(@DCd(STCdioPkjEvOFaa6Kok zrIf$;IEI}7anU4pJJ9v80Wf}aERhIky+f-h+`c%B8->Ikh|pCnOdTEccn!cWUjvA! zpF8N?@ra{UMiNDvu`md7Uy5;e*Rr%Y~NK^aIVoCS3K zlI@oHdG|Ou_o*I2{?xyTjDYIueSq-2G{Q(jzfhaA3h%!CEWrB!DA8-PB{Ru=^ z@_@5?ji|VJe%`}Q&cCXPBd73TCYeVhk8s670trM(0udySFbPCF`UqDXM36kf6*rG6 z?omhm?h6u-ATknF+@oA^$Q8Q=}`y2`?`jd zmU~qL$@IA?e49)SnEXD8p&nZW$uabN+=exB1S8+b0G9vQgTx{q!=1RC6z@o9SC4sp zu%#t$M%{tm7-Ey)NGf$?C?T)X>YEtEV~1%wGmZ=4F^U5gZ;!cGRqT7o=QqmH@fhu+ zC5CamDt09jV`HhY9qOiB0k7_g#a@|5yJ_N4(DdpXy+lflS6Kuzdk@CCdb;Z59v1oG zk30BH60T@=%c=1`hrXJrM{g{$Q2)r2^$!vC|2eLIh`{+Azp)Te|DWSGwwzk>2}j-Z z0SQPD8Hrl*34=r}`Giv@W2m4Eq$iw(@@GlqbbqZua)>poi{2$fx+w>`RGcTA#kF)C zB4xq6c%?}Y+^g1`1c6w!!6XR&noZ(mE~l~iNmCMXIUsUL$mMv_l!S`?q$vrx98a2( zh)k{%he{pRMM;DxOCo+v`J^d{{5>TSxFkpr+`1%45Qw@YND%xe$xgfy2uOd*$@vmq ziJG8kU;tZNbUEzQ+rISWY_$)n<`Psh-8&&C||0ab87G@)wU!JL}~&GAad)fTU{ii$_ipHXseZ zGvNmn7ZP#S#fgFsx6;rAu)xpzvXk>wHIC8p@5@dB`NFQdfC}{$$CjQLBoqpwEEGf( z>ML9*hOUL z|8VSYIF4ux$jJT=2RGtTCxl2<@{Hp)h<8KCs1zi~i>E{aI^i?q$f%TlTNFG>01k!U3eiC*Dep`xPM1RN0`EOL@E;(t?(2I#dt`4xZ zYxaC`v-t!a>_GRlAsMSk3}$i&ncv94PE3S^ZQ1Z z1|x{9OP=iajV`1gs0ziC^eDt!g-ZkE51fKRg$s**XmDwJ8zSR6(EXvoMMM3_=+Xu@ zMAoI>G5&~j8__cO`SnkooZq5lHfFYrXaM2MZp8VZI8;LSm#w23g6#dNlPiAU4_6zN z^fSj6K08UsgeW=-i6H%%QzCy)EK2%w#}=+6GO3avvMyE9&#CKEh1ygNzo1nMRX!x> zLS$W;i&c!&MJ4^x*g%y8k#(t(eraq#CH=~=#pDQFsw9Z4OO^C12WPbs7cb+l9b2qx zpi8S2h^&iBgove+)WvJ@8>34*^$=N?eyaH!(mjgt1;32>gOl?LD*tR*`Rb@p_Wl<1 z{GpaO*34?TNQa#4C7qv44aG73$PWwjr-p*&2|5k+aE=YHDn5p@>ha_7lcaA#dtZNW zaO?^b-3n@|Ke9Ur2{i#xm`Ir@>>qjRg@{N0=qPs(BC7b0j=Bb*f?DHGjxAkVNI-(f zNaT+E$w9m>%}B@<%D%j*03wk7L>{ZO2^I6aW6RZhh1h|B$Vhad!1Io}5DvLOdfr(m z*DVl%^t`i@u1lrTLHe_!E;)n*n;f$`)0_o3AWQ{VBj*0&4;L>b~ghyX+ z5Hc<8r(+_Bj6}yoFPPF%2YSKrxhm+G=mqlf)w7tmUU1g#5EEAg;uge6^@6jmQOu|+ z1$BTVIdO3k+DfF+Y^>7+7ZhnWR*8bIMqUL}LGIIwyfXv|mP2IA=~(JTV>xx_7ad=2 z{y-T>FFMPl{|^zCzvu)TmF2n8@)w;IbaO7TixgOnq&32i;3QZs(xl~5je3(v3_UCO z*3upJ)Ou*2zc}_rRc~|*29YhNW3a!NzDY0FUz{@O^59V*{l$TwCXsLq_E*QQQb=?R z29c5I80@d64(J%{ua3{%kB-6q>fmrvBB2WYW@?j;!5}gc;!GgwzDdVme{&Yf9lHvf zj=}!M`)n09j=}!Ut`H<3L1ZMvLqODhla9gu?nLBucTfh>-yLy-FVz!{!CrC@Z6*5` z9fLt+BsvCr$&`+c!CrFwDpm&4OHQ@C*#$@_-b)THY9yzMMA0{2a_U-C3yT!AFp{>Y z7M4k9VUZ?VSfvRrD9RQViGpuyi>gf=yS?n#^3tFRn~vQevgLH__Oh{@woYGmeCgvt z8AvZXh(VX7E`sGRJL^SUJS;DgmcQ)a-XO^?QeZifHYv+x5-b;K(sGq1xS$w%R`As} zc$d=t9)5cGJ~!v1t`&JZg?S7mvCX66H|Qf}IHeZzBo>+}xHsxT5A5k2ORU8P4{m%x zAVzrWkJi63kVvK`5r=aDJv@-WH6g>;)k72sKJ|fmdF(( zBs>UFZW2O7&0g&K<)U2|(V+Z(SH)UDf(a1W1ey!p@2Vpd&Yjg7mgU0_ZNq zR<+;szjflwz|Sq7XvL4Q#?d&XPV-#aMi*Dxxl)@RSOe{;@Jj@7^cfou5@#* zaV-($cn0?JUG>wgGtiT+bo1q}?$3a|$dQ4GXTa90=v_ir%|8R!SGkxrgaG8LT=mnf z{kU<`#il1^><@$O2N-fB*nWUrOGkf)E-|`7 z!~}Z1TSMP0!SGn%xxrm2&vB3oo*Ud6 zd242b-r*Zv{2-5pcu3%Z$UO88-)MNqs2g3)L;d1L!()TzMi;+@Q&8Z!(Zv^%HoAMyq72-;+8W%h_yESzG1GNv3ZZY*nE+0hZA(!tK z!$X7WEv_#w0>h)=xy4nt&O!vwEp8RpTP}ERaW`|l;qAKBMcB2hRC3TDG7mXuw;CRD z&~7z66M2y&Z;JMY^ywCd{MVUoxhNgF~) zDIgZR%Gj@_cr^fubOc)_0z_|uh4v`0TaoUMBl0&nE)MfNe27birHv+16sblhn+a_F zrEr`lquvBNPUq+wUg9{h4<8-_e$9HWDso6sJ}si=?l3)@9MU^XPauc%4p*IvplVQa zces^uWdc!DRrL<9NmLv%Pq=nXq+YBlW#B0}A47@iQIt0+4mZRXrjb}ZDmLr&%3d}r z`MAJf<0#bYgc(N2$35Ye$rVFH__!xrwPJuM_yc*s4H3qja5u;^>j-(kce(2H8xnXR zG7klU-DP;l1HQ{GlkwD0MkU5W#boyId|6AcE&ES9$*t@{jL!)dh8szypza z$UnZ@@Q{Cew_7H|M4=3xyWQn-c?l6bce^X(&K5-Q-0g0Z+t?8s-t0X*6+r?IMCKuH z_8!AS-t0YYne=9%44!*j<;_9_&pqz?t?JDx0?$2e!xr^=BgE{atGwojO(A9wnTJBm zP8uFMHb3dAH9M5SbJDHkx4jrVC*9R@lNq_-IqAa3T`oEg0?_Vr?P#P7q2=VT;(LI& z+Ytve%tbM2(9j~N?=#eNB7UE#N{UIl&s{G4(uiFG>igWvI#t9HP~YcP*Qz2SV(orc z-De%KDPj#G^U&$_{f385w(ob#+NfpZU`@QQ~5=O8i<1p|HA#O=J4tdDy(?K6oB>m&zRoT#^EwhuuIfS0RGuVRr+4 z*M`c2pu0z0bz%YuJP?_Og6V4v z0jnIoTQ+P6@P*JLWAV|WIFb%}_-~E|!BivXDDnLvQa7ItrP(YkqfjuT9p^{z6Bfje zc=|bd5AY>SOnF0bd6eiCymjwuc+ zUpZCorsGrjqZ&+?c(cYZ7h~-z`!@w5qLf-h{XK5_9UY22ZrnNwM10(|(|pw5U8lf)-)glg2bU+IrGe+k6q5A{(D{H}G6X7eGDf*2rBM06U9Y-!IX&hhQHwAH*vD~6c_mgVwx-b?+X0F>I-ho7hU-+3xLZ_mM^%Q zn#4wlN`cpoqz19c!bw<}h&0+{(P@GWinPh15(VRCb~h_fm@m3p_o%{P)8#4Gep(lX zLNk%Tg`v%Yr%YjJSL7)(GE!*fQ>HMu>{3!k2H@k2jp5MTL(Brc4;^hu=2 z!kBBHL}KV!!H6IH$=Y0m!aPldkv#yhpOVfGACX z2(VkZGaU4xF@=xk8 zM9|P82MOt~%W(lN1+8Z(;Pe@{K-?eeE+GS-byX-LBp3)$8VC_}^eopAL_GSe>&wj{ zh%oS37omuBB)t?jp}INWR<%H}sNci_N;Je$BKa1RKmrLwNdgfh-(nJoc=TIL0udzN zVv=Pz*>rRMOOa5R>UZ1%84b6LNWSYL#ErTFB#=OqBoIOJU7j)^;?eKAW%7nsh#>i{ z-0!g6<$m7x-JBmP5{h8`K3CWOUDufh{Z*a!{pIK1IS`0VMySTfHV6!QC4nRi7^h9^ zx=Ec*IwK(@v9DTQEfd>#jN3SW)ht?B>|i#V39Aqm$k5+DRh z!L=mB4i4aczRz;c4|n>{`_A*d_dL(%o_p{4J@?#m&pAp#c4iPPf?#?OOoHspAea>0 znL#iKvQt5(QC(w4)tCB1|IGRPvcHVtk?7=;c=;Fq`FH9mZtA~I^PEd~@5JaG8`GFe z1T$N)oz=0#dZ{0ubd43}?!?3b6VovzRp00jy%j-@WzRSIF(v!43i4*Z=N+I}1i|zmm;`yVe~5Rq zVp8@${#PnrA2jjHeVhb}J%jQNCLIyM=6j+{G=lJDwz)sNG0nmGQw ze($p49jn-Eey@MfA$DUPC#K&pX2k9pEFds_)^$ww{Y{^iT6YvC5Wne<_OpMS`hxz2 zpTF3s9w|&e95&k4Sey!zqW|J&0x0!4z29d>0QakRP?-LOAsZ?Bem>G*QuKX29oq3= z)erjp@01dS)pLZ9$m)IkfGhIQG4=9OUn2$LaJgEh#GDE9ivnc2F%NG@q*H6@_6E=|VNVqHs%g0zOw1>$var zhey?G%h2D)r7_ID*V5N$2Ry8X;k%{x*HL-cZ2oSEhGAG&&i6_*3|Iul^t%j`eZNVTccsXr08EcuZnVQTt`zAMb*cOnMLLJy26Bq z?pPPYb%om^Oft0V%BPOC*Q$8(y!pCv#OEy448;N*airzVDRHRmcBBo!>okjns8lmV zi+7Z-$S|zv-!Fad)xiQ4Gf{P|eZL&yJ$7uhoukJN6V&gQu|8H%ro93FemUC53WfqI zlE33m2~^XR6?dA&Vn;_cZx(OZpQVR&i(Su%kf{Il5)vBLM z_PwFRsvN_;!d-yrFC;N3dP6xh&w#qMZz%Bv_pt8d8%y6`c3`>bza^Lyy|F|OKPE+Q zEcCbPW*nv~y53a!Ka55m8w`X*R%h)^B^r6QQuwA4jr_3g{VZt^1ZLKzI*4y6@s!NI6uqS|_f70ny@6N7e(Jg;#Ygy=#zOCKk z>Vn41Q>!lM+gi(_F6i6JXwOfEtqc0La=7=bV)7JrTZzF@!|H-wS^C}uhJ|Cyyd%}; zys~udj{2NemQQ6Pr9S7C<Q{q1GUv2nZRkO`!tqE+gKOqk|%--b+>=yh+R#T%PdqF(IV z%Zc8LJ=~)gdsXTG=O9=Nq||M_sxU6WuNrk*uPR6XS+u9W@8qk>G2WMe zZz)_gNW($y5?76BP9B=YVn-)8(c&>;I^sdTs(e}N%&Q5YUwn0mMToE<$IPolz22)^ zo26dw)veCe>%F=h;V&vEi{sVhSRbY|+@sg~j^_9i+(?+&qN$tvj@F{7oBIykgN~?f z?mNn7)3Lg_?^+fPht>fy}H#*676GBd-XD5hUnn6@=qNKA_ULuO{o{V{-qkDHH#-HKH;t(_2%H|3hmC zL!oYwd>yQmi~&uJXs1~$L^YxzTD((yFvkR)hqaAdw-#oS>wK?m%k?SdCLnGHy%7#X+!8aQkd5pK-(8zPVHByqt*lHC-bMiLc+C;xYO|*C&ISuE= zMy}yJm`SeTJR1v(4fu7ghop^Vv_C>ku!p3Lja)r$?zx`epG`phu}qja*}GHZ}5i zl-ktD{TWF+b>#8b6q=KVX0bYQ6D?jx&a=|yMy}C2m`Scjr_GIAk4~E#xgMQ1H*$^M z+1$u~&+B}1BR7RQN6I>Pi8?pU$wRYP9l41XuOsJS?D0mf@j#eKu4l8y+b@xx%^q*R zM0z%Ryo{R=r$EnUk2i7~;Vz~74fTQWCM9`{jStPqL$g>Nxrr99Bj;&vOC#3^Bg`b% z!{3(Hw&>w+OKV&7@VBLr>)~%pBe%yjDIK{#)tQv!@t_x)lZR%pI&u>&UPsQ;-quF0 zF-w?9u7|&^B^HXF(9^@;)-u`$ePH5gYa`dg-_}NMk84soa(}8bDaqqOFEl3)&0=-r zCR)6XoTt5Qja);XFq8b_w3*vVeDN`%r-#37G`lMEUFdLs}++A;;Fm|F)8{~HrbdQ=2IosamJ)tpDHKVWWsXn z)%sLn5Tt(ULZMobPPX2Fl#BsQ)!Jzm3vr;V#XI$nf}9M5lo_YBpfB#)#uG$#)Ya>{0%n`rSma;)u*T!}1Zk}Hwj z-pG~6Zg1pDWVbhRC9>Naxuu>`I&#lYO-k}eT0?X4&@5I*ZlcBO$U)uF$d$-qCb<&X z9gSRx?2bmRM0Q6bS0cNkkz491r6czY)ubekq%|}r56xnAc~yBcpW*7@^g(`i7aN4 zE0KLJ)4_?>+y7h{?VXgEczUjpE0KM!kz491r6czY)ubekq%|}r4-In4=5=nO#p}pP zWS?*3N@OvUT#4-Sja-TB^Nn1I?DLIWiR|-@+)_^|9l2+yCM9_!t)V%2Xcns@H__sC zPV$d$-qCb<&XotX|!v_y7i8SU@VF!8jrkt>ni*~l&Rl+uxVhH6rhN75RalZOU5 zWwXvrw0IpkiR=rFT!}1Zk}HvYp^+<*eW8&nk$s_&E0KMnkz491r6czY)ubekq%|}r z56xnA&QuDUu@(`WHFOmiR_E5ZBZioVryHJ$iCRfmB_x>$Sw7h z(vf?HYEqI%(i)nRhi0)lauY3HM@}O9QX^L)i<#s~WM9fecA_P+FJ%gjiKmwuxf0oz z8o8yOQaW&M0R&0S0am<Mfs=i!?eia?k$Fuj#g&D;( zUhsJ8`;`*&*d4D=R9`7Ej~y0!V*2|NOtPO>O1CunuglPHaH$0nrZN<(^n9^{sqFRZ za-e;Fdf-&*h%Nqs-c(}k(fy=v@}}Z@Pl@$brb4@?#2Qjlshd6Jls{2_{ee?G7u{37 z@W<*7cAE$Y_WgedaGOHPnTq*mr>>O6_|hL6@HFOlPT*;Sz|#O`ivv#scy9tv!{Ocp zo`$o%2|Nwpy$L+cf%hh`*+f8aU>5*3MZlq${{S}0Vg&GMOeLMbrwsz11~6M3_%wj` z>AqJDpN7MIC6-e>4QKlj_%wj`CGcquyf1;xCIW&3y8y5$0uIIe2e3&NBY>wf1TTT7 z4+2jIm@N)G9pG0JcsdSWP2lM`do_Wl1N>?NPj}!~6WDAbAULoK0GlG`41n3GvSI27|Az$RIY0G`DN&jg+|2s{g5wm9%CfZs^qSvY(nfoI|D zjRc+r@EZv{%YolWV6%yU;J_{bY>I$GG5-NG zb8z-<0-po$y9s=b1HYTVW)lIyfn5OD6aj}~{sY(~ixI%*GUhsg&m9Cl7htwH@VTUi z?|xvY(5y_Y(MAfZt2ta~=4-1U8!p2oCH5z@`W|6!RazCRq%CH9mob zb>A;TA4WQO0{gyS4mwg`{S&Cx4>BD*LFwQJnGRyHC#I)^n2>zX(!uZ4q3>2t2hU^X z^%_g zz?UcR`8d2hfzQX;&tjV6%yU;J_{bY>I$GG5-N5*3MZlq${{S}0Vg&FUz7j~_IfKA+0A`B=&jEN@ z0?)zWvIL%kvtu3S;CT+bB7w~&0)hj(0I(?n4#oTj zut^ppfJc~gDuG7^fkyylivy1Ud{zE%jNtI9{NWhE*;SQwQT0nV0`OG{JmSDtC9v5< zKyY9e05(Oyp_u;wHpyZH@O;+1NZ|Q{!1DoSiv!OG`08vW=Hu|{Y$fL7?CJ!b5Af9q zJl}z@PGGZ%fZ)I`0BnkYLoxpWY?8$Y-~}wLk-!TEffoSG76)Dc@HI8k!38+Hrbfrd z0-RlwzzYDrCV>|?@HGi+HW3gU*ad)15pXExKY&fL7y-PH4{;KB;UMrrfZ5`}3rPpB zt&t8c#NoB|aBtQY;_TW4UI_5D3B1sOuT5aHiGbk1E&yzbfI~6=0c?`R0Qh0O=AJaF zUSEgqt_O_y(E+{&CiCljCD-npIr1&N*`D$r|B{s<7tQT-pFWjE7xW(67uI0zpE>_! zkp^BekHMuQHj5vVf{c7!ljK~g`3&TVWl5TovGd%m7LMSJ`D`r~qS>ICQy|80YAQgR zOeiOG9axfM5(jpDJ;*=vnxwJ9H`Lw_s(%iN&E^~Gf%-tO_A&L!{6^-CRubqoJ0Kj| z1gi7K$~Vwif*o!eETPxY2(5(13g0wX0{iB{5*p8l&`M~u?af}I-=Cxbv_Gu9zfNcy zK>NeWx1fgL188rlF@Toc?M**|51=)Hi~p7yAETK-$Xn`RWBssHg!6q%jl~QnsTyvr zF{vvS*CnR+V`Jj&)_RD4WQmEdTkByyWC{~cx7Kk!sp}*i+if)_Ai}~EW_r>T*|+H$ z*BcVH+RlgjJ1a~)-B!o@R7R6jDJyF%M}vhY%=DxY$t&w2{y_&@@wBpj`t#vfZ`N1V z7;Z92)~ed`QSn%K!c0$^&u&$XkMh}yr&V=~zr?|`vbNYNr$!K~YwzDj7`=JMOiz70 zt*(do=a=k@r`7dHpK}HiPpj*{(K^)fM4jGQVbBX;l@P*|vy`H7X-xnfYbmx6Jn+*@yQjx7aq0T+^>a z(`93Ov}&;yd(|v53v605O@YFKn=vN~2gHfti2TH0a$@eyn+lV|zc+6xOe*T$%G_0& zb!D=y?)y|3pC8-SR@S^Q%)sJPubtqtuxTO)R`8fN_G=@vH9=|@T=yX!GPp+6+*jjM zVBDMk!~6qnOoHF1;1eu3=lg!z24?A>wQz))*nG*{zqn-59Oj`=)#bc1lkFyD-wdOR z{Qh=~I*j|Vxiqz}{%SU2ed@-)_fDf%Ey(3nvG z+d@D852tQic1iCVGV);at{eBk=3O`LgLRxYOOtg>4`l;~g(uAPq#O64yxrJ}r-$lc zK6VWgPY=n{68*?d;X8>s^c+93-?mGM-!x{kWszwn#Oqe|<%D)i62}!i#g>EdAH%V; zzrj7hw0OCyD+9?Ev7ata{bDZqI?D%ZX%^-s%5{jD%jjz(tj9Dj29Zqx@@JJbGCu54 zeN*)F^G~(+c>UOzy}hwB;=2D+`+VX*jeMPnhM0#>)BZ4lE^%jnYpyMUY`@LE>adpF z(!CM)?NkLjfr*g5J$K|Au}UpJ?(u7GGhF1IJ$dY(Irq0H&UiW2P__kSa-LpW(COg+ zFBIv7u1N}N{tQ;W;c8Van3&1NAQclZuVivqZmVh1?dxm66My{ zLq9zz!Lz=8=9obVqV<(ecJny}Y##Kf6bPaD)W_(X2Yo6H+C1n}iO^>G zRB|>&cifiR^Us5^@Q3MbJSN_@)R?mZ6JJ~ErzZN{Ye&4LPV#Swr|1IT+C1ql!%R=Q z$F??4y2G|MPrARhHc#AL+nOicTbSudch1Ui5im{W8&+H%B+6oi;W-gW!Kl>-f)@e=bsCLDWodjR(r#QO>Bfb zR|u5&MLSmr#Q#Mdb5bh;!7u6;z8FWto%74ud#XDc-8Tq%G`eek*^Wl{%rD!~=#Kei zJDT1{eSJ*zIJh@#X8O_ebTm)4qroONLLLnQC7x_YgMh~;+tDCE@T87LN$?b4pRUXq zWS5~{wme-w?%$SAv6n5F{t+f77sS)`Uui1^S@!;!+IyB-u%cS_etYdt_KVV%y?>_u zp3g-z#g@Hi>+k1QAh!!rPi1TcaeIwLJ1_yj&*(SaL2v=iKFVyI`m>Z44lZGJ1dJ|euWG6L{;-Hp1Q_-aqPq?jEwjE{!&KK zGX=4xS)BXTOX8Ql&B{3MlDYgCe@!dg`=x*z=(5T%9y#Njaq_9Zz45Fmi*kEwwNHp;atim>gKg?5nH=}t zdXzoRW3unQR#azjUn{D!zpoY53EiinBK-m*EArUBK(W{JpigB4LvA>g4R65te*sYr Bcq{+_ literal 0 HcmV?d00001 diff --git a/spec/support/test/google_unittest.pb.rb b/spec/support/protos/google_unittest.pb.rb similarity index 54% rename from spec/support/test/google_unittest.pb.rb rename to spec/support/protos/google_unittest.pb.rb index c53c564b..d009abd5 100644 --- a/spec/support/test/google_unittest.pb.rb +++ b/spec/support/protos/google_unittest.pb.rb @@ -10,9 +10,9 @@ ## # Imports # -require 'test/google_unittest_import.pb' +require 'protos/google_unittest_import.pb' -module GoogleUnittest +module Protobuf_unittest ## # Enum Classes @@ -23,6 +23,16 @@ class ForeignEnum < ::Protobuf::Enum define :FOREIGN_BAZ, 6 end + class TestEnumWithDupValue < ::Protobuf::Enum + set_option :allow_alias + + define :FOO1, 1 + define :BAR1, 2 + define :BAZ, 3 + define :FOO2, 1 + define :BAR2, 2 + end + class TestSparseEnum < ::Protobuf::Enum define :SPARSE_A, 123 define :SPARSE_B, 62374 @@ -42,15 +52,22 @@ class NestedEnum < ::Protobuf::Enum define :FOO, 1 define :BAR, 2 define :BAZ, 3 + define :NEG, -1 end class NestedMessage < ::Protobuf::Message; end + class OptionalGroup < ::Protobuf::Message; end + class RepeatedGroup < ::Protobuf::Message; end end + class NestedTestAllTypes < ::Protobuf::Message; end class TestDeprecatedFields < ::Protobuf::Message; end class ForeignMessage < ::Protobuf::Message; end + class TestReservedFields < ::Protobuf::Message; end class TestAllExtensions < ::Protobuf::Message; end + class OptionalGroup_extension < ::Protobuf::Message; end + class RepeatedGroup_extension < ::Protobuf::Message; end class TestNestedExtension < ::Protobuf::Message; end class TestRequired < ::Protobuf::Message; end class TestRequiredForeign < ::Protobuf::Message; end @@ -62,7 +79,12 @@ class TestReallyLargeTagNumber < ::Protobuf::Message; end class TestRecursiveMessage < ::Protobuf::Message; end class TestMutualRecursionA < ::Protobuf::Message; end class TestMutualRecursionB < ::Protobuf::Message; end - class TestDupFieldNumber < ::Protobuf::Message; end + class TestDupFieldNumber < ::Protobuf::Message + class Foo < ::Protobuf::Message; end + class Bar < ::Protobuf::Message; end + + end + class TestEagerMessage < ::Protobuf::Message; end class TestLazyMessage < ::Protobuf::Message; end class TestNestedMessageHasBits < ::Protobuf::Message @@ -71,16 +93,53 @@ class NestedMessage < ::Protobuf::Message; end end class TestCamelCaseFieldNames < ::Protobuf::Message; end - class TestFieldOrderings < ::Protobuf::Message; end + class TestFieldOrderings < ::Protobuf::Message + class NestedMessage < ::Protobuf::Message; end + + end + class TestExtremeDefaultValues < ::Protobuf::Message; end class SparseEnumMessage < ::Protobuf::Message; end class OneString < ::Protobuf::Message; end class MoreString < ::Protobuf::Message; end class OneBytes < ::Protobuf::Message; end class MoreBytes < ::Protobuf::Message; end + class Int32Message < ::Protobuf::Message; end + class Uint32Message < ::Protobuf::Message; end + class Int64Message < ::Protobuf::Message; end + class Uint64Message < ::Protobuf::Message; end + class BoolMessage < ::Protobuf::Message; end + class TestOneof < ::Protobuf::Message + class FooGroup < ::Protobuf::Message; end + + end + + class TestOneofBackwardsCompatible < ::Protobuf::Message + class FooGroup < ::Protobuf::Message; end + + end + + class TestOneof2 < ::Protobuf::Message + class NestedEnum < ::Protobuf::Enum + define :FOO, 1 + define :BAR, 2 + define :BAZ, 3 + end + + class FooGroup < ::Protobuf::Message; end + class NestedMessage < ::Protobuf::Message; end + + end + + class TestRequiredOneof < ::Protobuf::Message + class NestedMessage < ::Protobuf::Message; end + + end + class TestPackedTypes < ::Protobuf::Message; end class TestUnpackedTypes < ::Protobuf::Message; end class TestPackedExtensions < ::Protobuf::Message; end + class TestUnpackedExtensions < ::Protobuf::Message; end class TestDynamicExtensions < ::Protobuf::Message class DynamicEnumType < ::Protobuf::Enum define :DYNAMIC_FOO, 2200 @@ -94,7 +153,14 @@ class DynamicMessageType < ::Protobuf::Message; end class TestRepeatedScalarDifferentTagSizes < ::Protobuf::Message; end class TestParsingMerge < ::Protobuf::Message - class RepeatedFieldsGenerator < ::Protobuf::Message; end + class RepeatedFieldsGenerator < ::Protobuf::Message + class Group1 < ::Protobuf::Message; end + class Group2 < ::Protobuf::Message; end + + end + + class OptionalGroup < ::Protobuf::Message; end + class RepeatedGroup < ::Protobuf::Message; end end @@ -115,6 +181,14 @@ class NestedMessage optional :int32, :bb, 1 end + class OptionalGroup + optional :int32, :a, 17 + end + + class RepeatedGroup + optional :int32, :a, 47 + end + optional :int32, :optional_int32, 1 optional :int64, :optional_int64, 2 optional :uint32, :optional_uint32, 3 @@ -130,16 +204,17 @@ class NestedMessage optional :bool, :optional_bool, 13 optional :string, :optional_string, 14 optional :bytes, :optional_bytes, 15 - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_nested_message, 18 - optional ::GoogleUnittest::ForeignMessage, :optional_foreign_message, 19 - optional ::GoogleUnittestImport::ImportMessage, :optional_import_message, 20 - optional ::GoogleUnittest::TestAllTypes::NestedEnum, :optional_nested_enum, 21 - optional ::GoogleUnittest::ForeignEnum, :optional_foreign_enum, 22 - optional ::GoogleUnittestImport::ImportEnum, :optional_import_enum, 23 + optional ::Protobuf_unittest::TestAllTypes::OptionalGroup, :optionalgroup, 16 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_nested_message, 18 + optional ::Protobuf_unittest::ForeignMessage, :optional_foreign_message, 19 + optional ::Protobuf_unittest_import::ImportMessage, :optional_import_message, 20 + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :optional_nested_enum, 21 + optional ::Protobuf_unittest::ForeignEnum, :optional_foreign_enum, 22 + optional ::Protobuf_unittest_import::ImportEnum, :optional_import_enum, 23 optional :string, :optional_string_piece, 24 optional :string, :optional_cord, 25 - optional ::GoogleUnittestImport::PublicImportMessage, :optional_public_import_message, 26 - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27 + optional ::Protobuf_unittest_import::PublicImportMessage, :optional_public_import_message, 26 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message, 27 repeated :int32, :repeated_int32, 31 repeated :int64, :repeated_int64, 32 repeated :uint32, :repeated_uint32, 33 @@ -155,15 +230,16 @@ class NestedMessage repeated :bool, :repeated_bool, 43 repeated :string, :repeated_string, 44 repeated :bytes, :repeated_bytes, 45 - repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_nested_message, 48 - repeated ::GoogleUnittest::ForeignMessage, :repeated_foreign_message, 49 - repeated ::GoogleUnittestImport::ImportMessage, :repeated_import_message, 50 - repeated ::GoogleUnittest::TestAllTypes::NestedEnum, :repeated_nested_enum, 51 - repeated ::GoogleUnittest::ForeignEnum, :repeated_foreign_enum, 52 - repeated ::GoogleUnittestImport::ImportEnum, :repeated_import_enum, 53 + repeated ::Protobuf_unittest::TestAllTypes::RepeatedGroup, :repeatedgroup, 46 + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_nested_message, 48 + repeated ::Protobuf_unittest::ForeignMessage, :repeated_foreign_message, 49 + repeated ::Protobuf_unittest_import::ImportMessage, :repeated_import_message, 50 + repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :repeated_nested_enum, 51 + repeated ::Protobuf_unittest::ForeignEnum, :repeated_foreign_enum, 52 + repeated ::Protobuf_unittest_import::ImportEnum, :repeated_import_enum, 53 repeated :string, :repeated_string_piece, 54 repeated :string, :repeated_cord, 55 - repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57 + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message, 57 optional :int32, :default_int32, 61, :default => 41 optional :int64, :default_int64, 62, :default => 42 optional :uint32, :default_uint32, 63, :default => 43 @@ -179,11 +255,21 @@ class NestedMessage optional :bool, :default_bool, 73, :default => true optional :string, :default_string, 74, :default => "hello" optional :bytes, :default_bytes, 75, :default => "world" - optional ::GoogleUnittest::TestAllTypes::NestedEnum, :default_nested_enum, 81, :default => ::GoogleUnittest::TestAllTypes::NestedEnum::BAR - optional ::GoogleUnittest::ForeignEnum, :default_foreign_enum, 82, :default => ::GoogleUnittest::ForeignEnum::FOREIGN_BAR - optional ::GoogleUnittestImport::ImportEnum, :default_import_enum, 83, :default => ::GoogleUnittestImport::ImportEnum::IMPORT_BAR + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :default_nested_enum, 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR + optional ::Protobuf_unittest::ForeignEnum, :default_foreign_enum, 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR + optional ::Protobuf_unittest_import::ImportEnum, :default_import_enum, 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR optional :string, :default_string_piece, 84, :default => "abc" optional :string, :default_cord, 85, :default => "123" + optional :uint32, :oneof_uint32, 111 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :oneof_nested_message, 112 + optional :string, :oneof_string, 113 + optional :bytes, :oneof_bytes, 114 + end + + class NestedTestAllTypes + optional ::Protobuf_unittest::NestedTestAllTypes, :child, 1 + optional ::Protobuf_unittest::TestAllTypes, :payload, 2 + repeated ::Protobuf_unittest::NestedTestAllTypes, :repeated_child, 3 end class TestDeprecatedFields @@ -212,16 +298,17 @@ class TestAllExtensions optional :bool, :optional_bool_extension, 13, :extension => true optional :string, :optional_string_extension, 14, :extension => true optional :bytes, :optional_bytes_extension, 15, :extension => true - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_nested_message_extension, 18, :extension => true - optional ::GoogleUnittest::ForeignMessage, :optional_foreign_message_extension, 19, :extension => true - optional ::GoogleUnittestImport::ImportMessage, :optional_import_message_extension, 20, :extension => true - optional ::GoogleUnittest::TestAllTypes::NestedEnum, :optional_nested_enum_extension, 21, :extension => true - optional ::GoogleUnittest::ForeignEnum, :optional_foreign_enum_extension, 22, :extension => true - optional ::GoogleUnittestImport::ImportEnum, :optional_import_enum_extension, 23, :extension => true + optional ::Protobuf_unittest::OptionalGroup_extension, :optionalgroup_extension, 16, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_nested_message_extension, 18, :extension => true + optional ::Protobuf_unittest::ForeignMessage, :optional_foreign_message_extension, 19, :extension => true + optional ::Protobuf_unittest_import::ImportMessage, :optional_import_message_extension, 20, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :optional_nested_enum_extension, 21, :extension => true + optional ::Protobuf_unittest::ForeignEnum, :optional_foreign_enum_extension, 22, :extension => true + optional ::Protobuf_unittest_import::ImportEnum, :optional_import_enum_extension, 23, :extension => true optional :string, :optional_string_piece_extension, 24, :extension => true optional :string, :optional_cord_extension, 25, :extension => true - optional ::GoogleUnittestImport::PublicImportMessage, :optional_public_import_message_extension, 26, :extension => true - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :optional_lazy_message_extension, 27, :extension => true + optional ::Protobuf_unittest_import::PublicImportMessage, :optional_public_import_message_extension, 26, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :optional_lazy_message_extension, 27, :extension => true repeated :int32, :repeated_int32_extension, 31, :extension => true repeated :int64, :repeated_int64_extension, 32, :extension => true repeated :uint32, :repeated_uint32_extension, 33, :extension => true @@ -237,15 +324,16 @@ class TestAllExtensions repeated :bool, :repeated_bool_extension, 43, :extension => true repeated :string, :repeated_string_extension, 44, :extension => true repeated :bytes, :repeated_bytes_extension, 45, :extension => true - repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_nested_message_extension, 48, :extension => true - repeated ::GoogleUnittest::ForeignMessage, :repeated_foreign_message_extension, 49, :extension => true - repeated ::GoogleUnittestImport::ImportMessage, :repeated_import_message_extension, 50, :extension => true - repeated ::GoogleUnittest::TestAllTypes::NestedEnum, :repeated_nested_enum_extension, 51, :extension => true - repeated ::GoogleUnittest::ForeignEnum, :repeated_foreign_enum_extension, 52, :extension => true - repeated ::GoogleUnittestImport::ImportEnum, :repeated_import_enum_extension, 53, :extension => true + repeated ::Protobuf_unittest::RepeatedGroup_extension, :repeatedgroup_extension, 46, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_nested_message_extension, 48, :extension => true + repeated ::Protobuf_unittest::ForeignMessage, :repeated_foreign_message_extension, 49, :extension => true + repeated ::Protobuf_unittest_import::ImportMessage, :repeated_import_message_extension, 50, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedEnum, :repeated_nested_enum_extension, 51, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :repeated_foreign_enum_extension, 52, :extension => true + repeated ::Protobuf_unittest_import::ImportEnum, :repeated_import_enum_extension, 53, :extension => true repeated :string, :repeated_string_piece_extension, 54, :extension => true repeated :string, :repeated_cord_extension, 55, :extension => true - repeated ::GoogleUnittest::TestAllTypes::NestedMessage, :repeated_lazy_message_extension, 57, :extension => true + repeated ::Protobuf_unittest::TestAllTypes::NestedMessage, :repeated_lazy_message_extension, 57, :extension => true optional :int32, :default_int32_extension, 61, :default => 41, :extension => true optional :int64, :default_int64_extension, 62, :default => 42, :extension => true optional :uint32, :default_uint32_extension, 63, :default => 43, :extension => true @@ -261,14 +349,27 @@ class TestAllExtensions optional :bool, :default_bool_extension, 73, :default => true, :extension => true optional :string, :default_string_extension, 74, :default => "hello", :extension => true optional :bytes, :default_bytes_extension, 75, :default => "world", :extension => true - optional ::GoogleUnittest::TestAllTypes::NestedEnum, :default_nested_enum_extension, 81, :default => ::GoogleUnittest::TestAllTypes::NestedEnum::BAR, :extension => true - optional ::GoogleUnittest::ForeignEnum, :default_foreign_enum_extension, 82, :default => ::GoogleUnittest::ForeignEnum::FOREIGN_BAR, :extension => true - optional ::GoogleUnittestImport::ImportEnum, :default_import_enum_extension, 83, :default => ::GoogleUnittestImport::ImportEnum::IMPORT_BAR, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedEnum, :default_nested_enum_extension, 81, :default => ::Protobuf_unittest::TestAllTypes::NestedEnum::BAR, :extension => true + optional ::Protobuf_unittest::ForeignEnum, :default_foreign_enum_extension, 82, :default => ::Protobuf_unittest::ForeignEnum::FOREIGN_BAR, :extension => true + optional ::Protobuf_unittest_import::ImportEnum, :default_import_enum_extension, 83, :default => ::Protobuf_unittest_import::ImportEnum::IMPORT_BAR, :extension => true optional :string, :default_string_piece_extension, 84, :default => "abc", :extension => true optional :string, :default_cord_extension, 85, :default => "123", :extension => true + optional :uint32, :oneof_uint32_extension, 111, :extension => true + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :oneof_nested_message_extension, 112, :extension => true + optional :string, :oneof_string_extension, 113, :extension => true + optional :bytes, :oneof_bytes_extension, 114, :extension => true optional :string, :test, 1002, :default => "test", :extension => true - optional ::GoogleUnittest::TestRequired, :single, 1000, :extension => true - repeated ::GoogleUnittest::TestRequired, :multi, 1001, :extension => true + optional :string, :nested_string_extension, 1003, :extension => true + optional ::Protobuf_unittest::TestRequired, :single, 1000, :extension => true + repeated ::Protobuf_unittest::TestRequired, :multi, 1001, :extension => true + end + + class OptionalGroup_extension + optional :int32, :a, 17 + end + + class RepeatedGroup_extension + optional :int32, :a, 47 end class TestRequired @@ -308,13 +409,13 @@ class TestRequired end class TestRequiredForeign - optional ::GoogleUnittest::TestRequired, :optional_message, 1 - repeated ::GoogleUnittest::TestRequired, :repeated_message, 2 + optional ::Protobuf_unittest::TestRequired, :optional_message, 1 + repeated ::Protobuf_unittest::TestRequired, :repeated_message, 2 optional :int32, :dummy, 3 end class TestForeignNested - optional ::GoogleUnittest::TestAllTypes::NestedMessage, :foreign_nested, 1 + optional ::Protobuf_unittest::TestAllTypes::NestedMessage, :foreign_nested, 1 end class TestReallyLargeTagNumber @@ -323,59 +424,75 @@ class TestReallyLargeTagNumber end class TestRecursiveMessage - optional ::GoogleUnittest::TestRecursiveMessage, :a, 1 + optional ::Protobuf_unittest::TestRecursiveMessage, :a, 1 optional :int32, :i, 2 end class TestMutualRecursionA - optional ::GoogleUnittest::TestMutualRecursionB, :bb, 1 + optional ::Protobuf_unittest::TestMutualRecursionB, :bb, 1 end class TestMutualRecursionB - optional ::GoogleUnittest::TestMutualRecursionA, :a, 1 + optional ::Protobuf_unittest::TestMutualRecursionA, :a, 1 optional :int32, :optional_int32, 2 end class TestDupFieldNumber + class Foo + optional :int32, :a, 1 + end + + class Bar + optional :int32, :a, 1 + end + optional :int32, :a, 1 + optional ::Protobuf_unittest::TestDupFieldNumber::Foo, :foo, 2 + optional ::Protobuf_unittest::TestDupFieldNumber::Bar, :bar, 3 end class TestEagerMessage - optional ::GoogleUnittest::TestAllTypes, :sub_message, 1 + optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1 end class TestLazyMessage - optional ::GoogleUnittest::TestAllTypes, :sub_message, 1 + optional ::Protobuf_unittest::TestAllTypes, :sub_message, 1 end class TestNestedMessageHasBits class NestedMessage repeated :int32, :nestedmessage_repeated_int32, 1 - repeated ::GoogleUnittest::ForeignMessage, :nestedmessage_repeated_foreignmessage, 2 + repeated ::Protobuf_unittest::ForeignMessage, :nestedmessage_repeated_foreignmessage, 2 end - optional ::GoogleUnittest::TestNestedMessageHasBits::NestedMessage, :optional_nested_message, 1 + optional ::Protobuf_unittest::TestNestedMessageHasBits::NestedMessage, :optional_nested_message, 1 end class TestCamelCaseFieldNames optional :int32, :PrimitiveField, 1 optional :string, :StringField, 2 - optional ::GoogleUnittest::ForeignEnum, :EnumField, 3 - optional ::GoogleUnittest::ForeignMessage, :MessageField, 4 + optional ::Protobuf_unittest::ForeignEnum, :EnumField, 3 + optional ::Protobuf_unittest::ForeignMessage, :MessageField, 4 optional :string, :StringPieceField, 5 optional :string, :CordField, 6 repeated :int32, :RepeatedPrimitiveField, 7 repeated :string, :RepeatedStringField, 8 - repeated ::GoogleUnittest::ForeignEnum, :RepeatedEnumField, 9 - repeated ::GoogleUnittest::ForeignMessage, :RepeatedMessageField, 10 + repeated ::Protobuf_unittest::ForeignEnum, :RepeatedEnumField, 9 + repeated ::Protobuf_unittest::ForeignMessage, :RepeatedMessageField, 10 repeated :string, :RepeatedStringPieceField, 11 repeated :string, :RepeatedCordField, 12 end class TestFieldOrderings + class NestedMessage + optional :int64, :oo, 2 + optional :int32, :bb, 1 + end + optional :string, :my_string, 11 optional :int64, :my_int, 1 optional :float, :my_float, 101 + optional ::Protobuf_unittest::TestFieldOrderings::NestedMessage, :optional_nested_message, 200 # Extension Fields extensions 2...11 extensions 12...101 @@ -410,10 +527,11 @@ class TestExtremeDefaultValues optional :bytes, :bytes_with_zero, 24, :default => "wor\000ld" optional :string, :string_piece_with_zero, 25, :default => "abc" optional :string, :cord_with_zero, 26, :default => "123" + optional :string, :replacement_string, 27, :default => "${unknown}" end class SparseEnumMessage - optional ::GoogleUnittest::TestSparseEnum, :sparse_enum, 1 + optional ::Protobuf_unittest::TestSparseEnum, :sparse_enum, 1 end class OneString @@ -432,6 +550,90 @@ class MoreBytes repeated :bytes, :data, 1 end + class Int32Message + optional :int32, :data, 1 + end + + class Uint32Message + optional :uint32, :data, 1 + end + + class Int64Message + optional :int64, :data, 1 + end + + class Uint64Message + optional :uint64, :data, 1 + end + + class BoolMessage + optional :bool, :data, 1 + end + + class TestOneof + class FooGroup + optional :int32, :a, 5 + optional :string, :b, 6 + end + + optional :int32, :foo_int, 1 + optional :string, :foo_string, 2 + optional ::Protobuf_unittest::TestAllTypes, :foo_message, 3 + optional ::Protobuf_unittest::TestOneof::FooGroup, :foogroup, 4 + end + + class TestOneofBackwardsCompatible + class FooGroup + optional :int32, :a, 5 + optional :string, :b, 6 + end + + optional :int32, :foo_int, 1 + optional :string, :foo_string, 2 + optional ::Protobuf_unittest::TestAllTypes, :foo_message, 3 + optional ::Protobuf_unittest::TestOneofBackwardsCompatible::FooGroup, :foogroup, 4 + end + + class TestOneof2 + class FooGroup + optional :int32, :a, 9 + optional :string, :b, 10 + end + + class NestedMessage + optional :int64, :qux_int, 1 + repeated :int32, :corge_int, 2 + end + + optional :int32, :foo_int, 1 + optional :string, :foo_string, 2 + optional :string, :foo_cord, 3 + optional :string, :foo_string_piece, 4 + optional :bytes, :foo_bytes, 5 + optional ::Protobuf_unittest::TestOneof2::NestedEnum, :foo_enum, 6 + optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_message, 7 + optional ::Protobuf_unittest::TestOneof2::FooGroup, :foogroup, 8 + optional ::Protobuf_unittest::TestOneof2::NestedMessage, :foo_lazy_message, 11 + optional :int32, :bar_int, 12, :default => 5 + optional :string, :bar_string, 13, :default => "STRING" + optional :string, :bar_cord, 14, :default => "CORD" + optional :string, :bar_string_piece, 15, :default => "SPIECE" + optional :bytes, :bar_bytes, 16, :default => "BYTES" + optional ::Protobuf_unittest::TestOneof2::NestedEnum, :bar_enum, 17, :default => ::Protobuf_unittest::TestOneof2::NestedEnum::BAR + optional :int32, :baz_int, 18 + optional :string, :baz_string, 19, :default => "BAZ" + end + + class TestRequiredOneof + class NestedMessage + required :double, :required_double, 1 + end + + optional :int32, :foo_int, 1 + optional :string, :foo_string, 2 + optional ::Protobuf_unittest::TestRequiredOneof::NestedMessage, :foo_message, 3 + end + class TestPackedTypes repeated :int32, :packed_int32, 90, :packed => true repeated :int64, :packed_int64, 91, :packed => true @@ -446,7 +648,7 @@ class TestPackedTypes repeated :float, :packed_float, 100, :packed => true repeated :double, :packed_double, 101, :packed => true repeated :bool, :packed_bool, 102, :packed => true - repeated ::GoogleUnittest::ForeignEnum, :packed_enum, 103, :packed => true + repeated ::Protobuf_unittest::ForeignEnum, :packed_enum, 103, :packed => true end class TestUnpackedTypes @@ -463,7 +665,7 @@ class TestUnpackedTypes repeated :float, :unpacked_float, 100 repeated :double, :unpacked_double, 101 repeated :bool, :unpacked_bool, 102 - repeated ::GoogleUnittest::ForeignEnum, :unpacked_enum, 103 + repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum, 103 end class TestPackedExtensions @@ -482,7 +684,26 @@ class TestPackedExtensions repeated :float, :packed_float_extension, 100, :packed => true, :extension => true repeated :double, :packed_double_extension, 101, :packed => true, :extension => true repeated :bool, :packed_bool_extension, 102, :packed => true, :extension => true - repeated ::GoogleUnittest::ForeignEnum, :packed_enum_extension, 103, :packed => true, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :packed_enum_extension, 103, :packed => true, :extension => true + end + + class TestUnpackedExtensions + # Extension Fields + extensions 1...536870912 + repeated :int32, :unpacked_int32_extension, 90, :extension => true + repeated :int64, :unpacked_int64_extension, 91, :extension => true + repeated :uint32, :unpacked_uint32_extension, 92, :extension => true + repeated :uint64, :unpacked_uint64_extension, 93, :extension => true + repeated :sint32, :unpacked_sint32_extension, 94, :extension => true + repeated :sint64, :unpacked_sint64_extension, 95, :extension => true + repeated :fixed32, :unpacked_fixed32_extension, 96, :extension => true + repeated :fixed64, :unpacked_fixed64_extension, 97, :extension => true + repeated :sfixed32, :unpacked_sfixed32_extension, 98, :extension => true + repeated :sfixed64, :unpacked_sfixed64_extension, 99, :extension => true + repeated :float, :unpacked_float_extension, 100, :extension => true + repeated :double, :unpacked_double_extension, 101, :extension => true + repeated :bool, :unpacked_bool_extension, 102, :extension => true + repeated ::Protobuf_unittest::ForeignEnum, :unpacked_enum_extension, 103, :extension => true end class TestDynamicExtensions @@ -491,10 +712,10 @@ class DynamicMessageType end optional :fixed32, :scalar_extension, 2000 - optional ::GoogleUnittest::ForeignEnum, :enum_extension, 2001 - optional ::GoogleUnittest::TestDynamicExtensions::DynamicEnumType, :dynamic_enum_extension, 2002 - optional ::GoogleUnittest::ForeignMessage, :message_extension, 2003 - optional ::GoogleUnittest::TestDynamicExtensions::DynamicMessageType, :dynamic_message_extension, 2004 + optional ::Protobuf_unittest::ForeignEnum, :enum_extension, 2001 + optional ::Protobuf_unittest::TestDynamicExtensions::DynamicEnumType, :dynamic_enum_extension, 2002 + optional ::Protobuf_unittest::ForeignMessage, :message_extension, 2003 + optional ::Protobuf_unittest::TestDynamicExtensions::DynamicMessageType, :dynamic_message_extension, 2004 repeated :string, :repeated_extension, 2005 repeated :sint32, :packed_extension, 2006, :packed => true end @@ -510,20 +731,40 @@ class TestRepeatedScalarDifferentTagSizes class TestParsingMerge class RepeatedFieldsGenerator - repeated ::GoogleUnittest::TestAllTypes, :field1, 1 - repeated ::GoogleUnittest::TestAllTypes, :field2, 2 - repeated ::GoogleUnittest::TestAllTypes, :field3, 3 - repeated ::GoogleUnittest::TestAllTypes, :ext1, 1000 - repeated ::GoogleUnittest::TestAllTypes, :ext2, 1001 + class Group1 + optional ::Protobuf_unittest::TestAllTypes, :field1, 11 + end + + class Group2 + optional ::Protobuf_unittest::TestAllTypes, :field1, 21 + end + + repeated ::Protobuf_unittest::TestAllTypes, :field1, 1 + repeated ::Protobuf_unittest::TestAllTypes, :field2, 2 + repeated ::Protobuf_unittest::TestAllTypes, :field3, 3 + repeated ::Protobuf_unittest::TestParsingMerge::RepeatedFieldsGenerator::Group1, :group1, 10 + repeated ::Protobuf_unittest::TestParsingMerge::RepeatedFieldsGenerator::Group2, :group2, 20 + repeated ::Protobuf_unittest::TestAllTypes, :ext1, 1000 + repeated ::Protobuf_unittest::TestAllTypes, :ext2, 1001 + end + + class OptionalGroup + optional ::Protobuf_unittest::TestAllTypes, :optional_group_all_types, 11 + end + + class RepeatedGroup + optional ::Protobuf_unittest::TestAllTypes, :repeated_group_all_types, 21 end - required ::GoogleUnittest::TestAllTypes, :required_all_types, 1 - optional ::GoogleUnittest::TestAllTypes, :optional_all_types, 2 - repeated ::GoogleUnittest::TestAllTypes, :repeated_all_types, 3 + required ::Protobuf_unittest::TestAllTypes, :required_all_types, 1 + optional ::Protobuf_unittest::TestAllTypes, :optional_all_types, 2 + repeated ::Protobuf_unittest::TestAllTypes, :repeated_all_types, 3 + optional ::Protobuf_unittest::TestParsingMerge::OptionalGroup, :optionalgroup, 10 + repeated ::Protobuf_unittest::TestParsingMerge::RepeatedGroup, :repeatedgroup, 20 # Extension Fields extensions 1000...536870912 - optional ::GoogleUnittest::TestAllTypes, :optional_ext, 1000, :extension => true - repeated ::GoogleUnittest::TestAllTypes, :repeated_ext, 1001, :extension => true + optional ::Protobuf_unittest::TestAllTypes, :optional_ext, 1000, :extension => true + repeated ::Protobuf_unittest::TestAllTypes, :repeated_ext, 1001, :extension => true end class TestCommentInjectionMessage @@ -535,8 +776,8 @@ class TestCommentInjectionMessage # Service Classes # class TestService < ::Protobuf::Rpc::Service - rpc :foo, ::GoogleUnittest::FooRequest, ::GoogleUnittest::FooResponse - rpc :bar, ::GoogleUnittest::BarRequest, ::GoogleUnittest::BarResponse + rpc :foo, ::Protobuf_unittest::FooRequest, ::Protobuf_unittest::FooResponse + rpc :bar, ::Protobuf_unittest::BarRequest, ::Protobuf_unittest::BarResponse end end diff --git a/spec/support/test/google_unittest.proto b/spec/support/protos/google_unittest.proto similarity index 77% rename from spec/support/test/google_unittest.proto rename to spec/support/protos/google_unittest.proto index f97e882c..002f70dc 100644 --- a/spec/support/test/google_unittest.proto +++ b/spec/support/protos/google_unittest.proto @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -34,12 +34,28 @@ // // A proto file we will use for unit testing. -import "test/google_unittest_import.proto"; +syntax = "proto2"; + +// Some generic_services option(s) added automatically. +// See: http://go/proto2-generic-services-default +option cc_generic_services = true; // auto-added +option java_generic_services = true; // auto-added +option py_generic_services = true; // auto-added +option cc_enable_arenas = true; + +import "protos/google_unittest_import.proto"; // We don't put this in a package within proto2 because we need to make sure // that the generated code doesn't depend on being in the proto2 namespace. -// In test_util.h we do "using namespace unittest = google_unittest". -package googleUnittest; +// In test_util.h we do "using namespace unittest = protobuf_unittest". +package protobuf_unittest; + +// Protos optimized for SPEED use a strict superset of the generated code +// of equivalent ones optimized for CODE_SIZE, so we should optimize all our +// tests for speed unless explicitly testing code size optimization. +option optimize_for = SPEED; + +option java_outer_classname = "UnittestProto"; // This proto includes every type of field in both singular and repeated // forms. @@ -55,6 +71,7 @@ message TestAllTypes { FOO = 1; BAR = 2; BAZ = 3; + NEG = -1; // Intentionally negative. } // Singular @@ -74,27 +91,26 @@ message TestAllTypes { optional string optional_string = 14; optional bytes optional_bytes = 15; - // TODO: Support groups - //optional group OptionalGroup = 16 { - // optional int32 a = 17; - //} + optional group OptionalGroup = 16 { + optional int32 a = 17; + } optional NestedMessage optional_nested_message = 18; optional ForeignMessage optional_foreign_message = 19; - optional googleUnittestImport.ImportMessage optional_import_message = 20; + optional protobuf_unittest_import.ImportMessage optional_import_message = 20; optional NestedEnum optional_nested_enum = 21; optional ForeignEnum optional_foreign_enum = 22; - optional googleUnittestImport.ImportEnum optional_import_enum = 23; + optional protobuf_unittest_import.ImportEnum optional_import_enum = 23; optional string optional_string_piece = 24 [ctype=STRING_PIECE]; optional string optional_cord = 25 [ctype=CORD]; // Defined in unittest_import_public.proto - optional googleUnittestImport.PublicImportMessage + optional protobuf_unittest_import.PublicImportMessage optional_public_import_message = 26; - optional NestedMessage optional_lazy_message = 27; // [lazy=true]; + optional NestedMessage optional_lazy_message = 27 [lazy=true]; // Repeated repeated int32 repeated_int32 = 31; @@ -113,23 +129,22 @@ message TestAllTypes { repeated string repeated_string = 44; repeated bytes repeated_bytes = 45; - // TODO: Support groups - //repeated group RepeatedGroup = 46 { - // optional int32 a = 47; - //} + repeated group RepeatedGroup = 46 { + optional int32 a = 47; + } repeated NestedMessage repeated_nested_message = 48; repeated ForeignMessage repeated_foreign_message = 49; - repeated googleUnittestImport.ImportMessage repeated_import_message = 50; + repeated protobuf_unittest_import.ImportMessage repeated_import_message = 50; repeated NestedEnum repeated_nested_enum = 51; repeated ForeignEnum repeated_foreign_enum = 52; - repeated googleUnittestImport.ImportEnum repeated_import_enum = 53; + repeated protobuf_unittest_import.ImportEnum repeated_import_enum = 53; repeated string repeated_string_piece = 54 [ctype=STRING_PIECE]; repeated string repeated_cord = 55 [ctype=CORD]; - repeated NestedMessage repeated_lazy_message = 57; // [lazy=true]; + repeated NestedMessage repeated_lazy_message = 57 [lazy=true]; // Singular with defaults optional int32 default_int32 = 61 [default = 41 ]; @@ -150,11 +165,26 @@ message TestAllTypes { optional NestedEnum default_nested_enum = 81 [default = BAR ]; optional ForeignEnum default_foreign_enum = 82 [default = FOREIGN_BAR]; - optional googleUnittestImport.ImportEnum + optional protobuf_unittest_import.ImportEnum default_import_enum = 83 [default = IMPORT_BAR]; optional string default_string_piece = 84 [ctype=STRING_PIECE,default="abc"]; optional string default_cord = 85 [ctype=CORD,default="123"]; + + // For oneof test + oneof oneof_field { + uint32 oneof_uint32 = 111; + NestedMessage oneof_nested_message = 112; + string oneof_string = 113; + bytes oneof_bytes = 114; + } +} + +// This proto includes a recusively nested message. +message NestedTestAllTypes { + optional NestedTestAllTypes child = 1; + optional TestAllTypes payload = 2; + repeated NestedTestAllTypes repeated_child = 3; } message TestDeprecatedFields { @@ -173,6 +203,11 @@ enum ForeignEnum { FOREIGN_BAZ = 6; } +message TestReservedFields { + reserved 2, 15, 9 to 11; + reserved "bar", "baz"; +} + message TestAllExtensions { extensions 1 to max; } @@ -195,29 +230,28 @@ extend TestAllExtensions { optional string optional_string_extension = 14; optional bytes optional_bytes_extension = 15; - // TODO: Support groups - //optional group OptionalGroup_extension = 16 { - // optional int32 a = 17; - //} + optional group OptionalGroup_extension = 16 { + optional int32 a = 17; + } optional TestAllTypes.NestedMessage optional_nested_message_extension = 18; optional ForeignMessage optional_foreign_message_extension = 19; - optional googleUnittestImport.ImportMessage + optional protobuf_unittest_import.ImportMessage optional_import_message_extension = 20; optional TestAllTypes.NestedEnum optional_nested_enum_extension = 21; optional ForeignEnum optional_foreign_enum_extension = 22; - optional googleUnittestImport.ImportEnum + optional protobuf_unittest_import.ImportEnum optional_import_enum_extension = 23; optional string optional_string_piece_extension = 24 [ctype=STRING_PIECE]; optional string optional_cord_extension = 25 [ctype=CORD]; - optional googleUnittestImport.PublicImportMessage + optional protobuf_unittest_import.PublicImportMessage optional_public_import_message_extension = 26; optional TestAllTypes.NestedMessage - optional_lazy_message_extension = 27; // [lazy=true]; + optional_lazy_message_extension = 27 [lazy=true]; // Repeated repeated int32 repeated_int32_extension = 31; @@ -236,26 +270,25 @@ extend TestAllExtensions { repeated string repeated_string_extension = 44; repeated bytes repeated_bytes_extension = 45; - // TODO: Support groups - //repeated group RepeatedGroup_extension = 46 { - // optional int32 a = 47; - //} + repeated group RepeatedGroup_extension = 46 { + optional int32 a = 47; + } repeated TestAllTypes.NestedMessage repeated_nested_message_extension = 48; repeated ForeignMessage repeated_foreign_message_extension = 49; - repeated googleUnittestImport.ImportMessage + repeated protobuf_unittest_import.ImportMessage repeated_import_message_extension = 50; repeated TestAllTypes.NestedEnum repeated_nested_enum_extension = 51; repeated ForeignEnum repeated_foreign_enum_extension = 52; - repeated googleUnittestImport.ImportEnum + repeated protobuf_unittest_import.ImportEnum repeated_import_enum_extension = 53; repeated string repeated_string_piece_extension = 54 [ctype=STRING_PIECE]; repeated string repeated_cord_extension = 55 [ctype=CORD]; repeated TestAllTypes.NestedMessage - repeated_lazy_message_extension = 57; // [lazy=true]; + repeated_lazy_message_extension = 57 [lazy=true]; // Singular with defaults optional int32 default_int32_extension = 61 [default = 41 ]; @@ -278,12 +311,18 @@ extend TestAllExtensions { default_nested_enum_extension = 81 [default = BAR]; optional ForeignEnum default_foreign_enum_extension = 82 [default = FOREIGN_BAR]; - optional googleUnittestImport.ImportEnum + optional protobuf_unittest_import.ImportEnum default_import_enum_extension = 83 [default = IMPORT_BAR]; optional string default_string_piece_extension = 84 [ctype=STRING_PIECE, default="abc"]; optional string default_cord_extension = 85 [ctype=CORD, default="123"]; + + // For oneof test + optional uint32 oneof_uint32_extension = 111; + optional TestAllTypes.NestedMessage oneof_nested_message_extension = 112; + optional string oneof_string_extension = 113; + optional bytes oneof_bytes_extension = 114; } message TestNestedExtension { @@ -291,6 +330,9 @@ message TestNestedExtension { // Check for bug where string extensions declared in tested scope did not // compile. optional string test = 1002 [default="test"]; + // Used to test if generated extension name is correct when there are + // underscores. + optional string nested_string_extension = 1003; } } @@ -395,22 +437,21 @@ message TestMutualRecursionB { } // Test that groups have disjoint field numbers from their siblings and -// parents. This is NOT possible in proto1; only proto2. When attempting +// parents. This is NOT possible in proto1; only google.protobuf. When attempting // to compile with proto1, this will emit an error; so we only include it -// in google_unittest_proto. +// in protobuf_unittest_proto. message TestDupFieldNumber { // NO_PROTO1 optional int32 a = 1; // NO_PROTO1 - // TODO: Support groups - //optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 - //optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 + optional group Foo = 2 { optional int32 a = 1; } // NO_PROTO1 + optional group Bar = 3 { optional int32 a = 1; } // NO_PROTO1 } // NO_PROTO1 // Additional messages for testing lazy fields. message TestEagerMessage { - optional TestAllTypes sub_message = 1; // [lazy=false]; + optional TestAllTypes sub_message = 1 [lazy=false]; } message TestLazyMessage { - optional TestAllTypes sub_message = 1; // [lazy=true]; + optional TestAllTypes sub_message = 1 [lazy=true]; } // Needed for a Python test. @@ -424,15 +465,15 @@ message TestNestedMessageHasBits { // Test an enum that has multiple values with the same number. -// TODO: update and test this when the new compiler is released -// enum TestEnumWithDupValue { -// option allow_alias = true; -// FOO1 = 1; -// BAR1 = 2; -// BAZ = 3; -// FOO2 = 1; -// BAR2 = 2; -// } +enum TestEnumWithDupValue { + option allow_alias = true; + + FOO1 = 1; + BAR1 = 2; + BAZ = 3; + FOO2 = 1; + BAR2 = 2; +} // Test an enum with large, unordered values. enum TestSparseEnum { @@ -472,6 +513,15 @@ message TestFieldOrderings { optional int64 my_int = 1; extensions 12 to 100; optional float my_float = 101; + message NestedMessage { + optional int64 oo = 2; + // The field name "b" fails to compile in proto1 because it conflicts with + // a local variable named "b" in one of the generated methods. Doh. + // This file needs to compile in proto1 to test backwards-compatibility. + optional int32 bb = 1; + } + + optional NestedMessage optional_nested_message = 200; } @@ -527,6 +577,7 @@ message TestExtremeDefaultValues { default="ab\000c"]; optional string cord_with_zero = 26 [ctype=CORD, default="12\0003"]; + optional string replacement_string = 27 [default="${unknown}"]; } message SparseEnumMessage { @@ -550,6 +601,100 @@ message MoreBytes { repeated bytes data = 1; } +// Test int32, uint32, int64, uint64, and bool are all compatible +message Int32Message { + optional int32 data = 1; +} + +message Uint32Message { + optional uint32 data = 1; +} + +message Int64Message { + optional int64 data = 1; +} + +message Uint64Message { + optional uint64 data = 1; +} + +message BoolMessage { + optional bool data = 1; +} + +// Test oneofs. +message TestOneof { + oneof foo { + int32 foo_int = 1; + string foo_string = 2; + TestAllTypes foo_message = 3; + group FooGroup = 4 { + optional int32 a = 5; + optional string b = 6; + } + } +} + +message TestOneofBackwardsCompatible { + optional int32 foo_int = 1; + optional string foo_string = 2; + optional TestAllTypes foo_message = 3; + optional group FooGroup = 4 { + optional int32 a = 5; + optional string b = 6; + } +} + +message TestOneof2 { + oneof foo { + int32 foo_int = 1; + string foo_string = 2; + string foo_cord = 3 [ctype=CORD]; + string foo_string_piece = 4 [ctype=STRING_PIECE]; + bytes foo_bytes = 5; + NestedEnum foo_enum = 6; + NestedMessage foo_message = 7; + group FooGroup = 8 { + optional int32 a = 9; + optional string b = 10; + } + NestedMessage foo_lazy_message = 11 [lazy=true]; + } + + oneof bar { + int32 bar_int = 12 [default = 5]; + string bar_string = 13 [default = "STRING"]; + string bar_cord = 14 [ctype=CORD, default = "CORD"]; + string bar_string_piece = 15 [ctype=STRING_PIECE, default = "SPIECE"]; + bytes bar_bytes = 16 [default = "BYTES"]; + NestedEnum bar_enum = 17 [default = BAR]; + } + + optional int32 baz_int = 18; + optional string baz_string = 19 [default = "BAZ"]; + + message NestedMessage { + optional int64 qux_int = 1; + repeated int32 corge_int = 2; + } + + enum NestedEnum { + FOO = 1; + BAR = 2; + BAZ = 3; + } +} + +message TestRequiredOneof { + oneof foo { + int32 foo_int = 1; + string foo_string = 2; + NestedMessage foo_message = 3; + } + message NestedMessage { + required double required_double = 1; + } +} // Test messages for packed fields @@ -610,6 +755,27 @@ extend TestPackedExtensions { repeated ForeignEnum packed_enum_extension = 103 [packed = true]; } +message TestUnpackedExtensions { + extensions 1 to max; +} + +extend TestUnpackedExtensions { + repeated int32 unpacked_int32_extension = 90 [packed = false]; + repeated int64 unpacked_int64_extension = 91 [packed = false]; + repeated uint32 unpacked_uint32_extension = 92 [packed = false]; + repeated uint64 unpacked_uint64_extension = 93 [packed = false]; + repeated sint32 unpacked_sint32_extension = 94 [packed = false]; + repeated sint64 unpacked_sint64_extension = 95 [packed = false]; + repeated fixed32 unpacked_fixed32_extension = 96 [packed = false]; + repeated fixed64 unpacked_fixed64_extension = 97 [packed = false]; + repeated sfixed32 unpacked_sfixed32_extension = 98 [packed = false]; + repeated sfixed64 unpacked_sfixed64_extension = 99 [packed = false]; + repeated float unpacked_float_extension = 100 [packed = false]; + repeated double unpacked_double_extension = 101 [packed = false]; + repeated bool unpacked_bool_extension = 102 [packed = false]; + repeated ForeignEnum unpacked_enum_extension = 103 [packed = false]; +} + // Used by ExtensionSetTest/DynamicExtensions. The test actually builds // a set of extensions to TestAllExtensions dynamically, based on the fields // of this message type. @@ -663,26 +829,24 @@ message TestParsingMerge { repeated TestAllTypes field1 = 1; repeated TestAllTypes field2 = 2; repeated TestAllTypes field3 = 3; - // TODO: Support groups - //repeated group Group1 = 10 { - // optional TestAllTypes field1 = 11; - //} - //repeated group Group2 = 20 { - // optional TestAllTypes field1 = 21; - //} + repeated group Group1 = 10 { + optional TestAllTypes field1 = 11; + } + repeated group Group2 = 20 { + optional TestAllTypes field1 = 21; + } repeated TestAllTypes ext1 = 1000; repeated TestAllTypes ext2 = 1001; } required TestAllTypes required_all_types = 1; optional TestAllTypes optional_all_types = 2; repeated TestAllTypes repeated_all_types = 3; - // TODO: Support groups - //optional group OptionalGroup = 10 { - // optional TestAllTypes optional_group_all_types = 11; - //} - //repeated group RepeatedGroup = 20 { - // optional TestAllTypes repeated_group_all_types = 21; - //} + optional group OptionalGroup = 10 { + optional TestAllTypes optional_group_all_types = 11; + } + repeated group RepeatedGroup = 20 { + optional TestAllTypes repeated_group_all_types = 21; + } extensions 1000 to max; extend TestParsingMerge { optional TestAllTypes optional_ext = 1000; diff --git a/spec/support/test/google_unittest_import.pb.rb b/spec/support/protos/google_unittest_import.pb.rb similarity index 67% rename from spec/support/test/google_unittest_import.pb.rb rename to spec/support/protos/google_unittest_import.pb.rb index 1e49a5c3..b81b3f7b 100644 --- a/spec/support/test/google_unittest_import.pb.rb +++ b/spec/support/protos/google_unittest_import.pb.rb @@ -5,7 +5,13 @@ # require 'protobuf/message' -module GoogleUnittestImport + +## +# Imports +# +require 'protos/google_unittest_import_public.pb' + +module Protobuf_unittest_import ## # Enum Classes @@ -16,21 +22,22 @@ class ImportEnum < ::Protobuf::Enum define :IMPORT_BAZ, 9 end + class ImportEnumForMap < ::Protobuf::Enum + define :UNKNOWN, 0 + define :FOO, 1 + define :BAR, 2 + end + ## # Message Classes # - class PublicImportMessage < ::Protobuf::Message; end class ImportMessage < ::Protobuf::Message; end ## # Message Fields # - class PublicImportMessage - optional :int32, :e, 1 - end - class ImportMessage optional :int32, :d, 1 end diff --git a/spec/support/test/google_unittest_import.proto b/spec/support/protos/google_unittest_import.proto similarity index 80% rename from spec/support/test/google_unittest_import.proto rename to spec/support/protos/google_unittest_import.proto index 2814e46f..b64f9cdb 100644 --- a/spec/support/test/google_unittest_import.proto +++ b/spec/support/protos/google_unittest_import.proto @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -34,23 +34,25 @@ // // A proto file which is imported by unittest.proto to test importing. +syntax = "proto2"; // We don't put this in a package within proto2 because we need to make sure // that the generated code doesn't depend on being in the proto2 namespace. // In test_util.h we do // "using namespace unittest_import = protobuf_unittest_import". -package googleUnittestImport; +package protobuf_unittest_import; -//############################## Test public import -// TODO: This will be supported in the next release of the -// compiler -// import public "test/google_unittest_import_public.proto"; +option optimize_for = SPEED; +option cc_enable_arenas = true; -message PublicImportMessage { - optional int32 e = 1; -} +// Exercise the java_package option. +option java_package = "com.google.protobuf.test"; + +// Do not set a java_outer_classname here to verify that Proto2 works without +// one. -//############################### +// Test public import +import public "protos/google_unittest_import_public.proto"; message ImportMessage { optional int32 d = 1; @@ -62,3 +64,10 @@ enum ImportEnum { IMPORT_BAZ = 9; } + +// To use an enum in a map, it must has the first value as 0. +enum ImportEnumForMap { + UNKNOWN = 0; + FOO = 1; + BAR = 2; +} diff --git a/spec/support/protos/google_unittest_import_public.pb.rb b/spec/support/protos/google_unittest_import_public.pb.rb new file mode 100644 index 00000000..8453bfbb --- /dev/null +++ b/spec/support/protos/google_unittest_import_public.pb.rb @@ -0,0 +1,24 @@ +# encoding: utf-8 + +## +# This file is auto-generated. DO NOT EDIT! +# +require 'protobuf/message' + +module Protobuf_unittest_import + + ## + # Message Classes + # + class PublicImportMessage < ::Protobuf::Message; end + + + ## + # Message Fields + # + class PublicImportMessage + optional :int32, :e, 1 + end + +end + diff --git a/spec/support/test/google_unittest_import_public.proto b/spec/support/protos/google_unittest_import_public.proto similarity index 88% rename from spec/support/test/google_unittest_import_public.proto rename to spec/support/protos/google_unittest_import_public.proto index 9a57a4f5..ffaf7736 100644 --- a/spec/support/test/google_unittest_import_public.proto +++ b/spec/support/protos/google_unittest_import_public.proto @@ -1,6 +1,6 @@ // Protocol Buffers - Google's data interchange format // Copyright 2008 Google Inc. All rights reserved. -// http://code.google.com/p/protobuf/ +// https://developers.google.com/protocol-buffers/ // // Redistribution and use in source and binary forms, with or without // modification, are permitted provided that the following conditions are @@ -30,9 +30,12 @@ // Author: liujisi@google.com (Pherl Liu) +syntax = "proto2"; -package googleUnittestImport; +package protobuf_unittest_import; -//message PublicImportMessage { -// optional int32 e = 1; -//} +option java_package = "com.google.protobuf.test"; + +message PublicImportMessage { + optional int32 e = 1; +} diff --git a/spec/support/test/multi_field_extensions.pb.rb b/spec/support/protos/multi_field_extensions.pb.rb similarity index 100% rename from spec/support/test/multi_field_extensions.pb.rb rename to spec/support/protos/multi_field_extensions.pb.rb diff --git a/spec/support/test/multi_field_extensions.proto b/spec/support/protos/multi_field_extensions.proto similarity index 96% rename from spec/support/test/multi_field_extensions.proto rename to spec/support/protos/multi_field_extensions.proto index 200d74f3..3a9a834d 100644 --- a/spec/support/test/multi_field_extensions.proto +++ b/spec/support/protos/multi_field_extensions.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package test; message Header { diff --git a/spec/support/test/resource.pb.rb b/spec/support/protos/resource.pb.rb similarity index 100% rename from spec/support/test/resource.pb.rb rename to spec/support/protos/resource.pb.rb diff --git a/spec/support/test/resource.proto b/spec/support/protos/resource.proto similarity index 98% rename from spec/support/test/resource.proto rename to spec/support/protos/resource.proto index bf89859f..9cfe79cf 100644 --- a/spec/support/test/resource.proto +++ b/spec/support/protos/resource.proto @@ -1,3 +1,5 @@ +syntax = "proto2"; + package test; enum StatusType { diff --git a/spec/support/test/resource_service.rb b/spec/support/resource_service.rb similarity index 90% rename from spec/support/test/resource_service.rb rename to spec/support/resource_service.rb index d8642381..8f246b30 100644 --- a/spec/support/test/resource_service.rb +++ b/spec/support/resource_service.rb @@ -1,4 +1,4 @@ -require ::File.expand_path('../resource.pb', __FILE__) +require PROTOS_PATH.join('resource.pb') Test::ResourceService.class_eval do # request -> Test::ResourceFindRequest diff --git a/spec/support/server.rb b/spec/support/server.rb index d4f30c7d..79881cd4 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -8,7 +8,7 @@ require 'protobuf/rpc/servers/socket_runner' require 'protobuf/rpc/servers/zmq/server' require 'protobuf/rpc/servers/zmq_runner' -require 'spec/support/test/resource_service' +require SUPPORT_PATH.join('resource_service') # Want to abort if server dies? Thread.abort_on_exception = true diff --git a/spec/support/test/defaults.pb.rb b/spec/support/test/defaults.pb.rb deleted file mode 100644 index 24c6c4bf..00000000 --- a/spec/support/test/defaults.pb.rb +++ /dev/null @@ -1,27 +0,0 @@ -# encoding: utf-8 - -## -# This file is auto-generated. DO NOT EDIT! -# -require 'protobuf/message' - -module Test - - ## - # Message Classes - # - class Defaults < ::Protobuf::Message; end - - - ## - # Message Fields - # - class Defaults - optional :bytes, :escaped_bytes, 1, :default => "\000\001\007\010\014\n\r\t\013\\\\'\"\376" - optional :double, :infinity_default, 2, :default => ::Float::INFINITY - optional :float, :neg_infinity_default, 3, :default => -::Float::INFINITY - optional :double, :nan_default, 4, :default => ::Float::NAN - end - -end - diff --git a/spec/support/test/defaults.proto b/spec/support/test/defaults.proto deleted file mode 100644 index 1a657e92..00000000 --- a/spec/support/test/defaults.proto +++ /dev/null @@ -1,9 +0,0 @@ -package test; - -message Defaults { - optional bytes escaped_bytes = 1 [default = "\0\001\a\b\f\n\r\t\v\\\'\"\xfe"]; - optional double infinity_default = 2 [default = inf]; - optional float neg_infinity_default = 3 [default = -inf]; - optional double nan_default = 4 [default = nan]; -} - diff --git a/spec/support/test/extended.pb.rb b/spec/support/test/extended.pb.rb deleted file mode 100644 index a9edae82..00000000 --- a/spec/support/test/extended.pb.rb +++ /dev/null @@ -1,24 +0,0 @@ -# encoding: utf-8 - -## -# This file is auto-generated. DO NOT EDIT! -# -require 'protobuf/message' - - -## -# Imports -# -require 'test/resource.pb' - -module Test - - ## - # Extended Message Fields - # - class ::Test::Resource < ::Protobuf::Message - optional :int64, :deleted_at, 300, :extension => true - end - -end - diff --git a/spec/support/test/extended.proto b/spec/support/test/extended.proto deleted file mode 100644 index f12e60cb..00000000 --- a/spec/support/test/extended.proto +++ /dev/null @@ -1,10 +0,0 @@ -package test; -import 'test/resource.proto'; - -// Test that we will re-open a class and add -// extension fields to it even if there are no -// message or enum definitions in this FileDescriptor. - -extend test.Resource { - optional int64 deleted_at = 300; -} diff --git a/spec/support/test/google_unittest_import_public.pb.rb b/spec/support/test/google_unittest_import_public.pb.rb deleted file mode 100644 index 18434960..00000000 --- a/spec/support/test/google_unittest_import_public.pb.rb +++ /dev/null @@ -1,10 +0,0 @@ -# encoding: utf-8 - -## -# This file is auto-generated. DO NOT EDIT! -# -require 'protobuf/message' - -module GoogleUnittestImport -end - From 008dd9a85891f2e04a29852e580a629c92354be2 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Wed, 27 Jan 2016 10:49:12 -0800 Subject: [PATCH 250/298] add missing deprecation require --- lib/protobuf/enum.rb | 1 + lib/protobuf/field/base_field.rb | 1 + lib/protobuf/message.rb | 1 + 3 files changed, 3 insertions(+) diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index fdf0725d..4496aaf3 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -1,4 +1,5 @@ require 'delegate' +require 'protobuf/deprecation' require 'protobuf/optionable' ## diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 440bbd72..0388917f 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -1,3 +1,4 @@ +require 'protobuf/deprecation' require 'protobuf/field/field_array' require 'protobuf/logging' require 'protobuf/wire_type' diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6aa70047..af53238e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -1,4 +1,5 @@ require 'protobuf/field' +require 'protobuf/deprecation' require 'protobuf/enum' require 'protobuf/exceptions' require 'protobuf/message/fields' From 7830b4e2c04e4b9a2835ab4cff7cf304bb43d725 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 31 Jan 2016 19:33:09 -0700 Subject: [PATCH 251/298] only fetch value once on serialization and cache the varint encoding for most common cases (< 1024) --- lib/protobuf/field/varint_field.rb | 17 ++++++++++++++++- lib/protobuf/message.rb | 10 +++------- lib/protobuf/message/serialization.rb | 4 ---- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index affaf393..4f8736fe 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -8,6 +8,7 @@ class VarintField < BaseField # Constants # + CACHE_LIMIT = 1024 INT32_MAX = 2**31 - 1 INT32_MIN = -2**31 INT64_MAX = 2**63 - 1 @@ -23,7 +24,16 @@ def self.default 0 end - def self.encode(value) + # Because all tags and enums are calculated as VarInt it is "most common" to have + # values < CACHE_LIMIT (low numbers) which is defaulting to 1024 + def self.cached_varint(value) + @_varint_cache ||= {} + (@_varint_cache[value] ||= encode(value, false)).dup + end + + def self.encode(value, use_cache = true) + return cached_varint(value) if use_cache && value >= 0 && value <= CACHE_LIMIT + bytes = [] until value < 128 bytes << (0x80 | (value & 0x7f)) @@ -32,6 +42,11 @@ def self.encode(value) (bytes << value).pack('C*') end + # Load the cache of VarInts on load of file + (0..CACHE_LIMIT).to_a.each do |cached_value| + cached_varint(cached_value) + end + ## # Public Instance Methods # diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 6aa70047..d1b22f6f 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -81,15 +81,11 @@ def each_field def each_field_for_serialization self.class.all_fields.each do |field| - next unless field_must_be_serialized?(field) - value = @values[field.getter] + fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if value.nil? && field.required? + next if value.nil? - if value.nil? - fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." - else - yield(field, value) - end + yield(field, value) end end diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 5528c10a..6526a95c 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -75,10 +75,6 @@ def encode_to(stream) private - def field_must_be_serialized?(field) - field.required? || ! @values[field.name].nil? - end - def set_field_bytes(tag, bytes) field = self.class.get_field(tag, true) field.set(self, bytes) if field From b4ff74ba3bebbb4bd8dd23e32ab22179278cde1e Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Sun, 31 Jan 2016 20:07:21 -0700 Subject: [PATCH 252/298] Update changelog for last few releases --- CHANGES.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/CHANGES.md b/CHANGES.md index aba3d531..918fba91 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,21 @@ # Stable (3.x) +3.5.5 +-------- +- Add native Varint for MRI. + +3.5.4 +-------- +- Ensures ActiveSupport::Deprecation does not get a stack trace when deprecations are disabled. + +3.5.3 +-------- +- Optimized get_extension_field and get_field calls. + +3.5.2 +-------- +- Optimized valid_tag?, enums_for_tag and enums_for_tags + 3.5.1 -------- - Adds compatibility for Rails 4.2+ as CLI options were broken From a28ca82ed1a69a69eca36a3aeed62960842d1b5f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 31 Jan 2016 22:37:39 -0700 Subject: [PATCH 253/298] clean up ordered require of SUPPORT_PATH --- spec/benchmark/tasks.rb | 1 + spec/spec_helper.rb | 2 -- spec/support/server.rb | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index aa184cd8..0f7603e1 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -1,6 +1,7 @@ require 'benchmark' require 'protobuf/socket' require 'support/all' +require 'spec_helper' require SUPPORT_PATH.join('resource_service') case RUBY_ENGINE.to_sym diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 2d4fb4f1..bb6c43d1 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -28,8 +28,6 @@ # Get rid of the deprecation env var if present (messes with specs). ENV.delete("PB_IGNORE_DEPRECATIONS") -RSpec.configure(&:disable_monkey_patching!) - ::Protobuf::Rpc::Client.class_eval do def ==(other) connector.options == other.options && \ diff --git a/spec/support/server.rb b/spec/support/server.rb index 79881cd4..8a0203b6 100644 --- a/spec/support/server.rb +++ b/spec/support/server.rb @@ -2,6 +2,7 @@ require 'active_support/core_ext/hash/reverse_merge' +require 'spec_helper' require 'protobuf/logging' require 'protobuf/rpc/server' require 'protobuf/rpc/servers/socket/server' From b1ea86d0dd9585ce1dc1a9efd26744e296e15328 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 31 Jan 2016 22:43:37 -0700 Subject: [PATCH 254/298] bump to 3.6.0 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index e76a9845..889460e6 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.5.5' + VERSION = '3.6.0' end From e72d098730b4fc7ccde3514ae75cf26d27762a5b Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Mon, 1 Feb 2016 09:37:04 -0800 Subject: [PATCH 255/298] rubocop: exclude generated proto code --- .rubocop.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.rubocop.yml b/.rubocop.yml index 9f5f9e92..1f6c8f57 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -19,6 +19,10 @@ Style/ClassAndModuleChildren: Exclude: - '**/*.pb.rb' +Style/ClassAndModuleCamelCase: + Exclude: + - '**/*.pb.rb' + Style/EmptyLineBetweenDefs: AllowAdjacentOneLineDefs: true From 3b7bf97a2caffbcbfcf6b34d40019771ab173539 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 1 Feb 2016 11:22:12 -0700 Subject: [PATCH 256/298] Fix for new ping port check Always return the socket instance after a successful nonblock connect. --- lib/protobuf/rpc/connectors/ping.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/protobuf/rpc/connectors/ping.rb b/lib/protobuf/rpc/connectors/ping.rb index 0b8e085d..66456bd3 100644 --- a/lib/protobuf/rpc/connectors/ping.rb +++ b/lib/protobuf/rpc/connectors/ping.rb @@ -43,6 +43,7 @@ def tcp_socket socket = ::Socket.new(family, ::Socket::SOCK_STREAM, 0) socket.setsockopt(::Socket::IPPROTO_TCP, ::Socket::TCP_NODELAY, 1) socket.connect_nonblock(sockaddr) + socket rescue ::IO::WaitWritable # IO.select will block until the socket is writable or the timeout # is exceeded - whichever comes first. @@ -50,6 +51,7 @@ def tcp_socket begin # Verify there is now a good connection socket.connect_nonblock(sockaddr) + socket rescue ::Errno::EISCONN # Socket is connected. socket From d34849edef1efb39dc820107cadcc4e2d197c81f Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Mon, 1 Feb 2016 11:26:01 -0700 Subject: [PATCH 257/298] bump to 3.6.1 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 889460e6..c5924004 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.0' + VERSION = '3.6.1' end From 7ee47ad1966f7483b9c843f782a46ff6b24310c8 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Mon, 1 Feb 2016 09:38:25 -0800 Subject: [PATCH 258/298] update README links localshred => ruby-protobuf --- README.md | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 5308e37f..45d6a762 100644 --- a/README.md +++ b/README.md @@ -1,8 +1,8 @@ # protobuf [![Gem Version](https://badge.fury.io/rb/protobuf.svg)](http://badge.fury.io/rb/protobuf) -[![Build Status](https://secure.travis-ci.org/ruby-protobuf/protobuf.svg?branch=master)](https://travis-ci.org/localshred/protobuf) -[![Gitter chat](https://badges.gitter.im/localshred/protobuf.svg)](https://gitter.im/localshred/protobuf) +[![Build Status](https://secure.travis-ci.org/ruby-protobuf/protobuf.svg?branch=master)](https://travis-ci.org/ruby-protobuf/protobuf) +[![Gitter chat](https://badges.gitter.im/ruby-protobuf/protobuf.svg)](https://gitter.im/ruby-protobuf/protobuf) [![protobuf API Documentation](https://www.omniref.com/ruby/gems/protobuf.png)](https://www.omniref.com/ruby/gems/protobuf) Protobuf is an implementation of [Google's protocol buffers][google-pb] in ruby, version 2.5.0 is currently supported. @@ -22,12 +22,12 @@ an [API roadmap][]. See recent changes in the [release notes][] or the [changelog][]. [google-pb]: http://code.google.com/p/protobuf "Google Protocol Buffers" - [wiki]: https://github.com/localshred/protobuf/wiki "Wiki home page" - [Installation Guide]: https://github.com/localshred/protobuf/wiki/Installation "Installation guide" - [compiling definitions]: https://github.com/localshred/protobuf/wiki/Compiling-Definitions "Compiling guide" - [object APIs]: https://github.com/localshred/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs guide" - [services]: https://github.com/localshred/protobuf/wiki/Services "Services object API guide" - [clients]: https://github.com/localshred/protobuf/wiki/Clients "Client object API guide" - [API roadmap]: https://github.com/localshred/protobuf/wiki/API-Roadmap "API Roadmap guide" - [release notes]: https://github.com/localshred/protobuf/releases "Release notes" - [changelog]: https://github.com/localshred/protobuf/blob/master/CHANGES.md "CHANGES.md" + [wiki]: https://github.com/ruby-protobuf/protobuf/wiki "Wiki home page" + [Installation Guide]: https://github.com/ruby-protobuf/protobuf/wiki/Installation "Installation guide" + [compiling definitions]: https://github.com/ruby-protobuf/protobuf/wiki/Compiling-Definitions "Compiling guide" + [object APIs]: https://github.com/ruby-protobuf/protobuf/wiki/Messages-&-Enums "Message & Enum object APIs guide" + [services]: https://github.com/ruby-protobuf/protobuf/wiki/Services "Services object API guide" + [clients]: https://github.com/ruby-protobuf/protobuf/wiki/Clients "Client object API guide" + [API roadmap]: https://github.com/ruby-protobuf/protobuf/wiki/API-Roadmap "API Roadmap guide" + [release notes]: https://github.com/ruby-protobuf/protobuf/releases "Release notes" + [changelog]: https://github.com/ruby-protobuf/protobuf/blob/master/CHANGES.md "CHANGES.md" From 6209f04817ad8742d52753da96931571a3ef2291 Mon Sep 17 00:00:00 2001 From: Andrew Lazarus Date: Tue, 2 Feb 2016 17:51:46 -0800 Subject: [PATCH 259/298] fix test failures when running with --order random --- lib/protobuf.rb | 8 ++++---- lib/protobuf/enum.rb | 3 +++ lib/protobuf/message/fields.rb | 3 +++ spec/lib/protobuf/code_generator_spec.rb | 1 - spec/lib/protobuf/enum_spec.rb | 1 + spec/lib/protobuf/message_spec.rb | 15 ++++++++++++--- spec/lib/protobuf_spec.rb | 22 ++++++++++++++++------ 7 files changed, 39 insertions(+), 14 deletions(-) diff --git a/lib/protobuf.rb b/lib/protobuf.rb index 18564148..04a95890 100644 --- a/lib/protobuf.rb +++ b/lib/protobuf.rb @@ -19,18 +19,18 @@ module Protobuf # Default is Socket as it has no external dependencies. DEFAULT_CONNECTOR = :socket - module_function - class << self # Client Host # # Default: `hostname` of the system # # The name or address of the host to use during client RPC calls. - attr_accessor :client_host + attr_writer :client_host end - self.client_host = Socket.gethostname + def self.client_host + @client_host ||= Socket.gethostname + end # Connector Type # diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 4496aaf3..e42fed90 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -56,6 +56,9 @@ def self.define(name, tag) enum = new(self, name, tag) @enums ||= [] @enums << enum + # defining a new field for the enum will cause cached @values and @mapped_enums + # to be incorrect; reset them + @mapped_enums = @values = nil const_set(name, enum) end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index bc0309a4..d5fda5e6 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -99,6 +99,9 @@ def define_field(rule, type_class, field_name, tag, options) field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) field_store[field_name] = field field_store[tag] = field + # defining a new field for the message will cause cached @all_fields, @extension_fields, + # and @fields to be incorrect; reset them + @all_fields = @extension_fields = @fields = nil str_field_store[field_name.to_s] = field diff --git a/spec/lib/protobuf/code_generator_spec.rb b/spec/lib/protobuf/code_generator_spec.rb index 48115829..33038006 100644 --- a/spec/lib/protobuf/code_generator_spec.rb +++ b/spec/lib/protobuf/code_generator_spec.rb @@ -56,5 +56,4 @@ end end end - end diff --git a/spec/lib/protobuf/enum_spec.rb b/spec/lib/protobuf/enum_spec.rb index 399bd814..94d75cbb 100644 --- a/spec/lib/protobuf/enum_spec.rb +++ b/spec/lib/protobuf/enum_spec.rb @@ -1,4 +1,5 @@ require 'spec_helper' +require PROTOS_PATH.join('enum.pb') RSpec.describe Protobuf::Enum do diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 525f79b3..f4b345c8 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -183,7 +183,12 @@ end context 'ignoring unknown fields' do - before { ::Protobuf.ignore_unknown_fields = true } + around do |example| + orig = ::Protobuf.ignore_unknown_fields? + ::Protobuf.ignore_unknown_fields = true + example.call + ::Protobuf.ignore_unknown_fields = orig + end context 'with valid fields' do let(:values) { { :name => "Jim" } } @@ -203,8 +208,12 @@ end context 'not ignoring unknown fields' do - before { ::Protobuf.ignore_unknown_fields = false } - after { ::Protobuf.ignore_unknown_fields = true } + around do |example| + orig = ::Protobuf.ignore_unknown_fields? + ::Protobuf.ignore_unknown_fields = false + example.call + ::Protobuf.ignore_unknown_fields = orig + end context 'with valid fields' do let(:values) { { :name => "Jim" } } diff --git a/spec/lib/protobuf_spec.rb b/spec/lib/protobuf_spec.rb index 0203f369..a330d9e5 100644 --- a/spec/lib/protobuf_spec.rb +++ b/spec/lib/protobuf_spec.rb @@ -56,9 +56,15 @@ end describe '.print_deprecation_warnings?' do - before { described_class.instance_variable_set(:@print_deprecation_warnings, nil) } + around do |example| + orig = described_class.print_deprecation_warnings? + example.call + described_class.print_deprecation_warnings = orig + end it 'defaults to a true value' do + allow(ENV).to receive(:key?).with('PB_IGNORE_DEPRECATIONS').and_return(false) + described_class.instance_variable_set('@field_deprecator', nil) expect(described_class.print_deprecation_warnings?).to be true end @@ -69,20 +75,24 @@ context 'when ENV["PB_IGNORE_DEPRECATIONS"] present' do it 'defaults to a false value' do - ENV['PB_IGNORE_DEPRECATIONS'] = '1' + allow(ENV).to receive(:key?).with('PB_IGNORE_DEPRECATIONS').and_return(true) + described_class.instance_variable_set('@field_deprecator', nil) expect(described_class.print_deprecation_warnings?).to be false end end end describe '.ignore_unknown_fields?' do - before do - if described_class.instance_variable_defined?(:@_ignore_unknown_fields) - described_class.send(:remove_instance_variable, :@_ignore_unknown_fields) - end + around do |example| + orig = described_class.ignore_unknown_fields? + example.call + described_class.ignore_unknown_fields = orig end it 'defaults to a true value' do + if described_class.instance_variable_defined?('@ignore_unknown_fields') + described_class.send(:remove_instance_variable, '@ignore_unknown_fields') + end expect(described_class.ignore_unknown_fields?).to be true end From b49836113d609c6e459d2ea5265c842d20640888 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Tue, 2 Feb 2016 19:40:57 -0700 Subject: [PATCH 260/298] bump to 3.6.2 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index c5924004..de0faa90 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.1' + VERSION = '3.6.2' end From c5727c03fa0823b1f22877bf6457ac55e7443c37 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:17:39 -0700 Subject: [PATCH 261/298] reduce encoder to class method as object instantiation here (#new) was problem of creating new and collecting objects for a small function --- lib/protobuf/encoder.rb | 76 ++++++++++------------------------------- 1 file changed, 18 insertions(+), 58 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index d9d19a26..30581116 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -1,67 +1,27 @@ module Protobuf class Encoder - - def self.encode(stream, message) - new(stream, message).encode - end - - private - - attr_writer :message, :stream - - public - - attr_reader :message, :stream - - def initialize(message, stream) - unless message.respond_to?(:each_field_for_serialization) - fail ArgumentError, "Message instance must respond to :each_field_for_serialization" - end - - self.message = message - self.stream = stream - end - - def encode + def self.encode(message, stream) message.each_field_for_serialization do |field, value| - encode_field(field, value) + if field.repeated? + if field.packed? + key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED + packed_value = value.map { |val| field.encode(val) }.join + stream << ::Protobuf::Field::VarintField.encode(key) + stream << ::Protobuf::Field::VarintField.encode(packed_value.size) + stream << packed_value + else + value.each do |val| + key = (field.tag << 3) | field.wire_type + stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(value)}" + end + end + else + key = (field.tag << 3) | field.wire_type + stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(value)}" + end end stream end - - private - - def encode_field(field, value) - if field.repeated? - encode_repeated_field(field, value) - else - write_pair(field, value) - end - end - - def encode_packed_field(field, value) - key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED - packed_value = value.map { |val| field.encode(val) }.join - stream << ::Protobuf::Field::VarintField.encode(key) - stream << ::Protobuf::Field::VarintField.encode(packed_value.size) - stream << packed_value - end - - def encode_repeated_field(field, value) - if field.packed? - encode_packed_field(field, value) - else - value.each { |val| write_pair(field, val) } - end - end - - # Encode key and value, and write to +stream+. - def write_pair(field, value) - key = (field.tag << 3) | field.wire_type - stream << ::Protobuf::Field::VarintField.encode(key) - stream << field.encode(value) - end - end end From 05aa7756e489e792c7bb0785ef2979931a4879a6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:19:34 -0700 Subject: [PATCH 262/298] create strings as combination of key size and serialized data as << is not necessary when we have both elements already; also fix RubyProf outputter for MRI; check nil? in String serialization after checking is_a?(String) as assigning String is probably most common case --- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/field/bool_field.rb | 11 +++++++---- lib/protobuf/field/bytes_field.rb | 11 ++++++----- lib/protobuf/field/message_field.rb | 6 +----- lib/protobuf/field/string_field.rb | 3 +-- lib/protobuf/field/varint_field.rb | 14 +++----------- lib/protobuf/message.rb | 2 +- lib/protobuf/message/fields.rb | 18 +++++++++--------- spec/benchmark/tasks.rb | 4 +++- 9 files changed, 32 insertions(+), 39 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 0388917f..b1055b65 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -223,7 +223,7 @@ def define_getter message_class.class_eval do define_method(method_name) do - @values.fetch(field.name, field.default_value) + @values[field.name] || field.default_value end end diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index d1b9efc8..ff5e4885 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -21,10 +21,13 @@ def acceptable?(val) end def coerce!(val) - if val == 'true' - true - elsif val == 'false' - false + case val + when String then + if val == 'true' + true + elsif val == 'false' + false + end else val end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 851daee1..f7755f5e 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -23,7 +23,7 @@ def self.default # def acceptable?(val) - val.nil? || val.is_a?(String) || val.is_a?(Symbol) || val.is_a?(::Protobuf::Message) + val.is_a?(String) || val.nil? || val.is_a?(Symbol) || val.is_a?(::Protobuf::Message) end def decode(bytes) @@ -58,11 +58,12 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| begin - val = "#{val}" if val.is_a?(Symbol) - - if val.nil? + case val + when String, Symbol then + @values[field.name] = "#{val}" + when NilClass then @values.delete(field.name) - elsif field.acceptable?(val) + when ::Protobuf::Message then @values[field.name] = val.dup else fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 2d9f3c92..ec0d0f1e 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -9,11 +9,7 @@ class MessageField < BaseField # def acceptable?(val) - unless val.is_a?(type_class) || val.respond_to?(:to_hash) - fail TypeError, "Expected value of type '#{type_class}' for field #{name}, but got '#{val.class}'" - end - - true + val.is_a?(type_class) || val.respond_to?(:to_hash) end def decode(bytes) diff --git a/lib/protobuf/field/string_field.rb b/lib/protobuf/field/string_field.rb index d1045a03..ac36ea70 100644 --- a/lib/protobuf/field/string_field.rb +++ b/lib/protobuf/field/string_field.rb @@ -25,8 +25,7 @@ def encode(value) value_to_encode.encode!(::Protobuf::Field::StringField::ENCODING, :invalid => :replace, :undef => :replace, :replace => "") value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) - string_size << value_to_encode + "#{::Protobuf::Field::VarintField.encode(value_to_encode.size)}#{value_to_encode}" end end diff --git a/lib/protobuf/field/varint_field.rb b/lib/protobuf/field/varint_field.rb index 4f8736fe..59fabdcb 100644 --- a/lib/protobuf/field/varint_field.rb +++ b/lib/protobuf/field/varint_field.rb @@ -8,7 +8,7 @@ class VarintField < BaseField # Constants # - CACHE_LIMIT = 1024 + CACHE_LIMIT = 2048 INT32_MAX = 2**31 - 1 INT32_MIN = -2**31 INT64_MAX = 2**63 - 1 @@ -43,7 +43,7 @@ def self.encode(value, use_cache = true) end # Load the cache of VarInts on load of file - (0..CACHE_LIMIT).to_a.each do |cached_value| + (0..CACHE_LIMIT).each do |cached_value| cached_varint(cached_value) end @@ -68,15 +68,7 @@ def decode(value) end def encode(value) - return [value].pack('C') if value < 128 - - bytes = [] - until value == 0 - bytes << (0x80 | (value & 0x7f)) - value >>= 7 - end - bytes[-1] &= 0x7f - bytes.pack('C*') + ::Protobuf::Field::VarintField.encode(value) end def wire_type diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index b20cd4b0..1e3bdd32 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -40,7 +40,7 @@ def self.to_json def initialize(fields = {}) @values = {} - fields.to_hash.each_pair do |name, value| + fields.to_hash.each do |name, value| self[name] = value end diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index d5fda5e6..635b7039 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -78,12 +78,12 @@ def field_tag?(tag, allow_extension = false) end def get_extension_field(name_or_tag) - field = field_store[name_or_tag] || str_field_store[name_or_tag] + field = field_store[name_or_tag] field if field.try(:extension?) { false } end def get_field(name_or_tag, allow_extension = false) - field = field_store[name_or_tag] || str_field_store[name_or_tag] + field = field_store[name_or_tag] if field && (allow_extension || !field.extension?) field @@ -97,19 +97,23 @@ def define_field(rule, type_class, field_name, tag, options) raise_if_name_collision(field_name) field = ::Protobuf::Field.build(self, rule, type_class, field_name, tag, options) - field_store[field_name] = field field_store[tag] = field + field_store[field_name] = field + field_store[field_name.to_s] = field # defining a new field for the message will cause cached @all_fields, @extension_fields, # and @fields to be incorrect; reset them @all_fields = @extension_fields = @fields = nil - str_field_store[field_name.to_s] = field - define_method("#{field_name}!") do @values[field_name] end end + def field_name_store + @field_name_store ||= {} + end + private :field_name_store + def raise_if_tag_collision(tag, field_name) if get_field(tag, true) fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) @@ -129,10 +133,6 @@ def inherit_fields!(subclass) end private :inherit_fields! - def str_field_store - @str_field_store ||= {} - end - private :str_field_store end end end diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index 0f7603e1..a939d668 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -107,7 +107,9 @@ def profile_code(output, &block) case RUBY_ENGINE.to_sym when :ruby profile_data = RubyProf.profile(&block) - RubyProf::FlatPrinter.new(profile_data).print(:path => output) + ::File.open(output, "w") do |output_file| + RubyProf::FlatPrinter.new(profile_data).print(output_file) + end when :rbx profiler = Rubinius::Profiler::Instrumenter.new profiler.profile(false, &block) From 7425971e91b308e9311508e89b2023c52d5c1e5d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:31:06 -0700 Subject: [PATCH 263/298] unused field_name_store --- lib/protobuf/message/fields.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/lib/protobuf/message/fields.rb b/lib/protobuf/message/fields.rb index 635b7039..bb41a2ed 100644 --- a/lib/protobuf/message/fields.rb +++ b/lib/protobuf/message/fields.rb @@ -109,11 +109,6 @@ def define_field(rule, type_class, field_name, tag, options) end end - def field_name_store - @field_name_store ||= {} - end - private :field_name_store - def raise_if_tag_collision(tag, field_name) if get_field(tag, true) fail TagCollisionError, %(Field number #{tag} has already been used in "#{name}" by field "#{field_name}".) From 036967c7f81a26b7b41b806da841ad9f8aefa29b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:36:45 -0700 Subject: [PATCH 264/298] copy type; should encode val for repeated fields --- lib/protobuf/encoder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 30581116..97cc2443 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -12,7 +12,7 @@ def self.encode(message, stream) else value.each do |val| key = (field.tag << 3) | field.wire_type - stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(value)}" + stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(val)}" end end else From 7b9ab5e9484186eeb7f68bca460b2ce9b0a7d463 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 11:47:52 -0700 Subject: [PATCH 265/298] move boolean strings to constants and not checking 2nd case --- lib/protobuf/field/bool_field.rb | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index ff5e4885..71dd5dc4 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -3,6 +3,8 @@ module Protobuf module Field class BoolField < VarintField + FALSE_STRING = "false".freeze + TRUE_STRING = "true".freeze ## # Class Methods @@ -23,9 +25,9 @@ def acceptable?(val) def coerce!(val) case val when String then - if val == 'true' + if val == TRUE_STRING true - elsif val == 'false' + else # acceptable? is called before coerce, so we don't need to check for now false end else From b8188c6a546d735a4229b7c8729467e13b5c3591 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Wed, 3 Feb 2016 13:19:39 -0700 Subject: [PATCH 266/298] remove some stylistic "then" and do not need to explicitly return false --- lib/protobuf/decoder.rb | 12 ++++++------ lib/protobuf/enum.rb | 13 ++++++------- lib/protobuf/field/bool_field.rb | 8 ++------ lib/protobuf/field/bytes_field.rb | 6 +++--- lib/protobuf/field/message_field.rb | 8 ++++---- lib/protobuf/generators/field_generator.rb | 6 +++--- lib/protobuf/rpc/service_filters.rb | 8 ++++---- spec/benchmark/tasks.rb | 2 +- 8 files changed, 29 insertions(+), 34 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index ce1255d2..aa1f30bf 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -15,17 +15,17 @@ def self.decode_each_field(stream, &block) def self.read_field(stream) tag, wire_type = read_key(stream) bytes = case wire_type - when ::Protobuf::WireType::VARINT then + when ::Protobuf::WireType::VARINT Varint.decode(stream) - when ::Protobuf::WireType::FIXED64 then + when ::Protobuf::WireType::FIXED64 read_fixed64(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED then + when ::Protobuf::WireType::LENGTH_DELIMITED read_length_delimited(stream) - when ::Protobuf::WireType::FIXED32 then + when ::Protobuf::WireType::FIXED32 read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP then + when ::Protobuf::WireType::START_GROUP fail NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP then + when ::Protobuf::WireType::END_GROUP fail NotImplementedError, 'Group is deprecated.' else fail InvalidWireType, wire_type diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index e42fed90..781a4c0e 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -131,8 +131,7 @@ def self.enum_for_name(name) # Enums, the first enum defined will be returned. # def self.enum_for_tag(tag) - value = mapped_enums[tag.to_i] - value ? value.first : nil + (mapped_enums[tag.to_i] || []).first end # Public: Get an Enum by a variety of type-checking mechanisms. @@ -157,11 +156,11 @@ def self.enum_for_tag(tag) # def self.fetch(candidate) case candidate - when self then + when self candidate - when ::Numeric then + when ::Numeric enum_for_tag(candidate.to_i) - when ::String, ::Symbol then + when ::String, ::Symbol enum_for_name(candidate) else nil @@ -280,9 +279,9 @@ def to_int def to_s(format = :tag) case format - when :tag then + when :tag to_i.to_s - when :name then + when :name name.to_s else to_i.to_s diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 71dd5dc4..8b4ee651 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -24,12 +24,8 @@ def acceptable?(val) def coerce!(val) case val - when String then - if val == TRUE_STRING - true - else # acceptable? is called before coerce, so we don't need to check for now - false - end + when String + val == TRUE_STRING else val end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index f7755f5e..518282c8 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -59,11 +59,11 @@ def define_setter define_method(method_name) do |val| begin case val - when String, Symbol then + when String, Symbol @values[field.name] = "#{val}" - when NilClass then + when NilClass @values.delete(field.name) - when ::Protobuf::Message then + when ::Protobuf::Message @values[field.name] = val.dup else fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index ec0d0f1e..6e62cdf4 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -41,13 +41,13 @@ def define_setter message_class.class_eval do define_method("#{field.name}=") do |val| case - when val.nil? then + when val.nil? @values.delete(field.name) - when val.is_a?(field.type_class) then + when val.is_a?(field.type_class) @values[field.name] = val - when val.respond_to?(:to_proto) then + when val.respond_to?(:to_proto) @values[field.name] = val.to_proto - when val.respond_to?(:to_hash) then + when val.respond_to?(:to_hash) @values[field.name] = field.type_class.new(val.to_hash) else fail TypeError, "Expected value of type '#{field.type_class}' for field #{field.name}, but got '#{val.class}'" diff --git a/lib/protobuf/generators/field_generator.rb b/lib/protobuf/generators/field_generator.rb index 0c92bc4c..3cd6c553 100644 --- a/lib/protobuf/generators/field_generator.rb +++ b/lib/protobuf/generators/field_generator.rb @@ -27,11 +27,11 @@ def default_value @default_value ||= begin if defaulted? case descriptor.type.name - when :TYPE_ENUM then + when :TYPE_ENUM enum_default_value - when :TYPE_STRING, :TYPE_BYTES then + when :TYPE_STRING, :TYPE_BYTES string_default_value - when :TYPE_FLOAT, :TYPE_DOUBLE then + when :TYPE_FLOAT, :TYPE_DOUBLE float_double_default_value else verbatim_default_value diff --git a/lib/protobuf/rpc/service_filters.rb b/lib/protobuf/rpc/service_filters.rb index 5d76460f..19593eae 100644 --- a/lib/protobuf/rpc/service_filters.rb +++ b/lib/protobuf/rpc/service_filters.rb @@ -122,7 +122,7 @@ def invoke_via_except?(rpc_method, filter) def invoke_via_if?(_rpc_method, filter) if_check = filter.fetch(:if) { ->(_service) { return true } } do_invoke = case - when if_check.nil? then + when if_check.nil? true else call_or_send(if_check) @@ -152,7 +152,7 @@ def invoke_via_only?(rpc_method, filter) def invoke_via_unless?(_rpc_method, filter) unless_check = filter.fetch(:unless) { ->(_service) { return false } } skip_invoke = case - when unless_check.nil? then + when unless_check.nil? false else call_or_send(unless_check) @@ -254,9 +254,9 @@ def run_rescue_filters # def call_or_send(callable, *args, &block) return_value = case - when callable.respond_to?(:call) then + when callable.respond_to?(:call) callable.call(self, *args, &block) - when respond_to?(callable, true) then + when respond_to?(callable, true) __send__(callable, *args, &block) else fail "Object #{callable} is not callable" diff --git a/spec/benchmark/tasks.rb b/spec/benchmark/tasks.rb index a939d668..631439d6 100644 --- a/spec/benchmark/tasks.rb +++ b/spec/benchmark/tasks.rb @@ -97,7 +97,7 @@ def zmq_client_zmq_server(number_tests, test_length, global_bench = nil) args.with_defaults(:number => 1000, :profile_output => "/tmp/profiler_new_#{Time.now.to_i}") create_params = { :name => "The name that we set", :date_created => Time.now.to_i, :status => 2 } profile_code(args[:profile_output]) do - Integer(args[:number]).times { Test::Resource.new(create_params).serialize } + Integer(args[:number]).times { Test::Resource.decode(Test::Resource.new(create_params).serialize) } end puts args[:profile_output] From 6c9c8e34d7080b60691db95d89fa83a0f5f6984d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Thu, 4 Feb 2016 08:45:56 -0700 Subject: [PATCH 267/298] bump to 3.6.3 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index de0faa90..e89859d3 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.2' + VERSION = '3.6.3' end From cf5dcfcf725852bdc2c921119943da9026482fca Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:31:31 -0700 Subject: [PATCH 268/298] Add memoization to Serialization#encode --- lib/protobuf/message/serialization.rb | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 6526a95c..6fdabf73 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -48,10 +48,12 @@ def decode_from(stream) # Encode this message # def encode - stream = ::StringIO.new - stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream) - stream.string + @memoized_encoded ||= begin + stream = ::StringIO.new + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + stream.string + end end # Encode this message to the given stream. From 35557891c17a149baa799e3c8299d3e3ea06c79d Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:32:17 -0700 Subject: [PATCH 269/298] Add @memoized_encoded to setter in message_field.rb --- lib/protobuf/field/message_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 6e62cdf4..ecdd851a 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -40,6 +40,7 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |val| + @memoized_encoded = nil case when val.nil? @values.delete(field.name) From f4c2fd649c1e457b7a878367ab4a8724dd98e38c Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:32:29 -0700 Subject: [PATCH 270/298] Add @memoized_encoded to setter in enum_field.rb --- lib/protobuf/field/enum_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index ac26ea0e..76f4ea60 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -42,6 +42,7 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |value| + @memoized_encoded = nil orig_value = value if value.nil? @values.delete(field.name) From 7b53903ff3d1cecba9b9d7f37d47bbaa5e8e97af Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:33:16 -0700 Subject: [PATCH 271/298] Set @memoized_encoded to eq nil in setter in base_field.rb --- lib/protobuf/field/base_field.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index b1055b65..d83c4d7d 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -21,7 +21,6 @@ class BaseField ## # Attributes # - attr_reader :message_class, :name, :options, :rule, :tag, :type_class ## @@ -195,6 +194,7 @@ def define_array_setter message_class.class_eval do define_method(method_name) do |val| + @memoized_encoded = nil if val.is_a?(Array) val = val.dup val.compact! @@ -236,6 +236,7 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| + @memoized_encoded = nil if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) From 80864b922a3a401a834277aae68a1f5eb02b768a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:33:29 -0700 Subject: [PATCH 272/298] Set @memoized_encoded to eq nil in setter in bytes_field.rb --- lib/protobuf/field/bytes_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 518282c8..69bb89f4 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -57,6 +57,7 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| + @memoized_encoded = nil begin case val when String, Symbol From 20acff780b41456ded9a12a60de2f9150798a36a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 12:50:07 -0700 Subject: [PATCH 273/298] Add attr_accessor for memoized_encoded --- lib/protobuf/field/base_field.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d83c4d7d..e973b613 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -21,6 +21,7 @@ class BaseField ## # Attributes # + attr_accessor :memoized_encoded attr_reader :message_class, :name, :options, :rule, :tag, :type_class ## From 09f67ebdb28bb8dd747a5c91fa1d8e4a4fc6a15a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 15:46:38 -0700 Subject: [PATCH 274/298] Add memoized_encoded attr_accessor to Message.rb --- lib/protobuf/message.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 1e3bdd32..74d335ef 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -26,6 +26,11 @@ class Message extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization + ## + # Attributes + # + attr_accessor :memoized_encoded + ## # Class Methods # From 0602cbf617206f879117fbf0443943dacc935c2b Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 15:48:10 -0700 Subject: [PATCH 275/298] Add specs for Message memoization --- spec/lib/protobuf/message_spec.rb | 58 +++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index f4b345c8..3e36519c 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -268,6 +268,64 @@ end end + describe 'memoization' do + it "should memoize enum message" do + test_enum = Test::EnumTestMessage.new + test_enum.encode + expect(test_enum.instance_variable_get(:@memoized_encoded)).to eq("") + test_enum.non_default_enum = 2 + expect(test_enum.instance_variable_get(:@memoized_encoded)).to be_nil + end + + context "boolean fields" do + let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } + let(:test_resource) { ::Test::Resource.new(values) } + + it "should memoize after bool values change " do + test_resource.encode + expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + test_resource.ext_is_searchable = false + expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + end + end + + context "string" do + let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } + let(:test_resource) { ::Test::Resource.new(values) } + + it "should memoize after bool values change " do + test_resource.encode + expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + test_resource.name = "MVP" + expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + end + end + + context "string" do + let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } + let(:test_resource) { ::Test::Resource.new(values) } + + it "should memoize after string values change " do + test_resource.encode + expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + test_resource.name = "MVP" + expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + end + end + + context "Int64" do + let(:values) { { :name => "STEPH CURRY", :date_created => 1454712125 } } + let(:test_resource) { ::Test::Resource.new(values) } + + it "should memoize after Int64 values change " do + test_resource.encode + expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + test_resource.date_created = 5554712127 + expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + end + end + end + context "when there's no value for a required field" do let(:message) { ::Test::ResourceWithRequiredField.new } From 384071af7980c5632032447c45c8eb9ce7e26243 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 15:52:30 -0700 Subject: [PATCH 276/298] Yield to block instead of calling block.call in #decode_each_field --- lib/protobuf/decoder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index aa1f30bf..9166b3d1 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -5,10 +5,10 @@ module Protobuf class Decoder # Read bytes from +stream+ and pass to +message+ object. - def self.decode_each_field(stream, &block) + def self.decode_each_field(stream) until stream.eof? tag, bytes = read_field(stream) - block.call(tag, bytes) + yield(tag, bytes) end end From 7ac9207a191dc9434682628e9adea033cbc86870 Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 16:00:47 -0700 Subject: [PATCH 277/298] Replace @memoized_encoded with @encode --- lib/protobuf/field/bytes_field.rb | 2 +- lib/protobuf/field/enum_field.rb | 2 +- lib/protobuf/field/message_field.rb | 2 +- lib/protobuf/message/serialization.rb | 2 +- spec/lib/protobuf/message_spec.rb | 20 ++++++++++---------- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 69bb89f4..30ae4351 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -57,7 +57,7 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| - @memoized_encoded = nil + @encode = nil begin case val when String, Symbol diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 76f4ea60..71632cde 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -42,7 +42,7 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |value| - @memoized_encoded = nil + @encode = nil orig_value = value if value.nil? @values.delete(field.name) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index ecdd851a..8cb37bd7 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -40,7 +40,7 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |val| - @memoized_encoded = nil + @encode = nil case when val.nil? @values.delete(field.name) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 6fdabf73..668b6cea 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -48,7 +48,7 @@ def decode_from(stream) # Encode this message # def encode - @memoized_encoded ||= begin + @encode ||= begin stream = ::StringIO.new stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) encode_to(stream) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 3e36519c..cc60357c 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -272,9 +272,9 @@ it "should memoize enum message" do test_enum = Test::EnumTestMessage.new test_enum.encode - expect(test_enum.instance_variable_get(:@memoized_encoded)).to eq("") + expect(test_enum.instance_variable_get(:@encode)).to eq("") test_enum.non_default_enum = 2 - expect(test_enum.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_enum.instance_variable_get(:@encode)).to be_nil end context "boolean fields" do @@ -283,9 +283,9 @@ it "should memoize after bool values change " do test_resource.encode - expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) test_resource.ext_is_searchable = false - expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_resource.instance_variable_get(:@encode)).to be_nil end end @@ -295,9 +295,9 @@ it "should memoize after bool values change " do test_resource.encode - expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) test_resource.name = "MVP" - expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_resource.instance_variable_get(:@encode)).to be_nil end end @@ -307,9 +307,9 @@ it "should memoize after string values change " do test_resource.encode - expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) test_resource.name = "MVP" - expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_resource.instance_variable_get(:@encode)).to be_nil end end @@ -319,9 +319,9 @@ it "should memoize after Int64 values change " do test_resource.encode - expect(test_resource.instance_variable_get(:@memoized_encoded)).to eq(test_resource.encode) + expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) test_resource.date_created = 5554712127 - expect(test_resource.instance_variable_get(:@memoized_encoded)).to be_nil + expect(test_resource.instance_variable_get(:@encode)).to be_nil end end end From 50cf59912c2746302f1f7ce9144337ff825a9e4a Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 16:31:34 -0700 Subject: [PATCH 278/298] Remove attr_accessor for memoized_encoded --- lib/protobuf/field/base_field.rb | 1 - lib/protobuf/message.rb | 5 ----- 2 files changed, 6 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index e973b613..d83c4d7d 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -21,7 +21,6 @@ class BaseField ## # Attributes # - attr_accessor :memoized_encoded attr_reader :message_class, :name, :options, :rule, :tag, :type_class ## diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 74d335ef..1e3bdd32 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -26,11 +26,6 @@ class Message extend ::Protobuf::Message::Fields include ::Protobuf::Message::Serialization - ## - # Attributes - # - attr_accessor :memoized_encoded - ## # Class Methods # From 2f8b1fe4ad235ea8e0d84a821038c63074dca9ef Mon Sep 17 00:00:00 2001 From: Dan Jones Date: Fri, 5 Feb 2016 16:31:51 -0700 Subject: [PATCH 279/298] Change @memoized_encoded to @encode --- lib/protobuf/field/base_field.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index d83c4d7d..bed83794 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -194,7 +194,7 @@ def define_array_setter message_class.class_eval do define_method(method_name) do |val| - @memoized_encoded = nil + @encode = nil if val.is_a?(Array) val = val.dup val.compact! @@ -236,7 +236,7 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| - @memoized_encoded = nil + @encode = nil if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) From 86cec14a7a5939c6288e2b45d2bd7b09193a65ef Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 13:28:17 -0700 Subject: [PATCH 280/298] fix rubocop --- spec/lib/protobuf/message_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index cc60357c..1ac3bff0 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -320,7 +320,7 @@ it "should memoize after Int64 values change " do test_resource.encode expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.date_created = 5554712127 + test_resource.date_created = 5554712127 expect(test_resource.instance_variable_get(:@encode)).to be_nil end end From c13c5fab7eed3f3860456fb5ed72e1130166cba4 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 13:56:50 -0700 Subject: [PATCH 281/298] already loading field on define and should not need to calcualte the tag encoding at runtime --- lib/protobuf/encoder.rb | 11 +++-------- lib/protobuf/field/base_field.rb | 12 ++++++++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/lib/protobuf/encoder.rb b/lib/protobuf/encoder.rb index 97cc2443..8038ae1f 100644 --- a/lib/protobuf/encoder.rb +++ b/lib/protobuf/encoder.rb @@ -4,20 +4,15 @@ def self.encode(message, stream) message.each_field_for_serialization do |field, value| if field.repeated? if field.packed? - key = (field.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED packed_value = value.map { |val| field.encode(val) }.join - stream << ::Protobuf::Field::VarintField.encode(key) - stream << ::Protobuf::Field::VarintField.encode(packed_value.size) - stream << packed_value + stream << "#{field.tag_encoded}#{::Protobuf::Field::VarintField.encode(packed_value.size)}#{packed_value}" else value.each do |val| - key = (field.tag << 3) | field.wire_type - stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(val)}" + stream << "#{field.tag_encoded}#{field.encode(val)}" end end else - key = (field.tag << 3) | field.wire_type - stream << "#{::Protobuf::Field::VarintField.encode(key)}#{field.encode(value)}" + stream << "#{field.tag_encoded}#{field.encode(value)}" end end diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index bed83794..51a39b8c 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -45,6 +45,7 @@ def initialize(message_class, rule, type_class, name, tag, options) validate_packed_field if packed? define_accessor + tag_encoded end ## @@ -148,6 +149,17 @@ def setter @setter ||= "#{name}=" end + def tag_encoded + @tag_encoded ||= begin + case + when repeated? && packed? + ::Protobuf::Field::VarintField.encode((self.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED) + else + ::Protobuf::Field::VarintField.encode((self.tag << 3) | self.wire_type) + end + end + end + # FIXME: add packed, deprecated, extension options to to_s output def to_s "#{rule} #{type_class} #{name} = #{tag} #{default ? "[default=#{default.inspect}]" : ''}" From 08eeded0f26d527badbf406006cc6852dedbca2b Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 14:54:15 -0700 Subject: [PATCH 282/298] order case calls on probability string > fixed --- lib/protobuf/decoder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 9166b3d1..89d76989 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -17,10 +17,10 @@ def self.read_field(stream) bytes = case wire_type when ::Protobuf::WireType::VARINT Varint.decode(stream) - when ::Protobuf::WireType::FIXED64 - read_fixed64(stream) when ::Protobuf::WireType::LENGTH_DELIMITED read_length_delimited(stream) + when ::Protobuf::WireType::FIXED64 + read_fixed64(stream) when ::Protobuf::WireType::FIXED32 read_fixed32(stream) when ::Protobuf::WireType::START_GROUP From 49af35245b07a44bf839aebb33a961c740f25ef6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 14:55:30 -0700 Subject: [PATCH 283/298] keepin the cops happy --- lib/protobuf/field/base_field.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 51a39b8c..c3b949a8 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -153,9 +153,9 @@ def tag_encoded @tag_encoded ||= begin case when repeated? && packed? - ::Protobuf::Field::VarintField.encode((self.tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED) + ::Protobuf::Field::VarintField.encode((tag << 3) | ::Protobuf::WireType::LENGTH_DELIMITED) else - ::Protobuf::Field::VarintField.encode((self.tag << 3) | self.wire_type) + ::Protobuf::Field::VarintField.encode((tag << 3) | wire_type) end end end From 26898aeaf5076762b6da03cf6e986f1bcb7eec5d Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 15:02:38 -0700 Subject: [PATCH 284/298] a few fasterer recommendations --- lib/protobuf/field/bytes_field.rb | 24 +++++++++--------------- lib/protobuf/lifecycle.rb | 4 ++-- lib/protobuf/message.rb | 4 ++-- 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index 30ae4351..b12e1286 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -58,21 +58,15 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| @encode = nil - begin - case val - when String, Symbol - @values[field.name] = "#{val}" - when NilClass - @values.delete(field.name) - when ::Protobuf::Message - @values[field.name] = val.dup - else - fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" - end - rescue NoMethodError => ex - logger.error { ex.message } - logger.error { ex.backtrace.join("\n") } - raise TypeError, "Got NoMethodError attempting to set #{val} for field #{field.name} of type #{field.type_class}: #{ex.message}" + case val + when String, Symbol + @values[field.name] = "#{val}" + when NilClass + @values.delete(field.name) + when ::Protobuf::Message + @values[field.name] = val.dup + else + fail TypeError, "Unacceptable value #{val} for field #{field.name} of type #{field.type_class}" end end end diff --git a/lib/protobuf/lifecycle.rb b/lib/protobuf/lifecycle.rb index 5e96b444..230b99ea 100644 --- a/lib/protobuf/lifecycle.rb +++ b/lib/protobuf/lifecycle.rb @@ -1,12 +1,12 @@ module Protobuf class Lifecycle class << self - def register(event_name, &blk) + def register(event_name) fail "Lifecycle register must have a block" unless block_given? event_name = normalized_event_name(event_name) ::ActiveSupport::Notifications.subscribe(event_name) do |_name, _start, _finish, _id, args| - blk.call(*args) + yield(*args) end end alias_method :on, :register diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index 1e3bdd32..a240f54b 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -118,10 +118,10 @@ def respond_to_has_and_present?(key) def to_hash result = {} - @values.keys.each do |field_name| + @values.each_key do |field_name| value = __send__(field_name) hashed_value = value.respond_to?(:to_hash_value) ? value.to_hash_value : value - result.merge!(field_name => hashed_value) + result[field_name] = hashed_value end result From fe00c64885792a91f02a77815a5dac4eb3a44257 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sat, 6 Feb 2016 15:43:10 -0700 Subject: [PATCH 285/298] bump to 3.6.4 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index e89859d3..eda6ed49 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.3' + VERSION = '3.6.4' end From 39fd8ed60e77f5b6457cec38c611ef65166df2b9 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 7 Feb 2016 14:25:30 -0700 Subject: [PATCH 286/298] compress decoder to single method; only check nil? once on serialization during required? check; add decoding optimization for enum values in "fetch" --- lib/protobuf/decoder.rb | 69 ++++++++----------------------- lib/protobuf/enum.rb | 2 + lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/field/bytes_field.rb | 13 ++++-- lib/protobuf/message.rb | 6 ++- 5 files changed, 33 insertions(+), 59 deletions(-) diff --git a/lib/protobuf/decoder.rb b/lib/protobuf/decoder.rb index 89d76989..20538595 100644 --- a/lib/protobuf/decoder.rb +++ b/lib/protobuf/decoder.rb @@ -7,60 +7,25 @@ class Decoder # Read bytes from +stream+ and pass to +message+ object. def self.decode_each_field(stream) until stream.eof? - tag, bytes = read_field(stream) + bits = Varint.decode(stream) + wire_type = bits & 0x07 + tag = bits >> 3 + + bytes = if wire_type == ::Protobuf::WireType::VARINT + Varint.decode(stream) + elsif wire_type == ::Protobuf::WireType::LENGTH_DELIMITED + value_length = Varint.decode(stream) + stream.read(value_length) + elsif wire_type == ::Protobuf::WireType::FIXED64 + stream.read(8) + elsif wire_type == ::Protobuf::WireType::FIXED32 + stream.read(4) + else + fail InvalidWireType, wire_type + end + yield(tag, bytes) end end - - def self.read_field(stream) - tag, wire_type = read_key(stream) - bytes = case wire_type - when ::Protobuf::WireType::VARINT - Varint.decode(stream) - when ::Protobuf::WireType::LENGTH_DELIMITED - read_length_delimited(stream) - when ::Protobuf::WireType::FIXED64 - read_fixed64(stream) - when ::Protobuf::WireType::FIXED32 - read_fixed32(stream) - when ::Protobuf::WireType::START_GROUP - fail NotImplementedError, 'Group is deprecated.' - when ::Protobuf::WireType::END_GROUP - fail NotImplementedError, 'Group is deprecated.' - else - fail InvalidWireType, wire_type - end - - [tag, bytes] - end - - # Read 32-bit string value from +stream+. - def self.read_fixed32(stream) - stream.read(4) - end - - # Read 64-bit string value from +stream+. - def self.read_fixed64(stream) - stream.read(8) - end - - # Read key pair (tag and wire-type) from +stream+. - def self.read_key(stream) - bits = read_varint(stream) - wire_type = bits & 0x07 - tag = bits >> 3 - [tag, wire_type] - end - - # Read length-delimited string value from +stream+. - def self.read_length_delimited(stream) - value_length = read_varint(stream) - stream.read(value_length) - end - - # Read varint integer value from +stream+. - def self.read_varint(stream) - Varint.decode(stream) - end end end diff --git a/lib/protobuf/enum.rb b/lib/protobuf/enum.rb index 781a4c0e..961cc1b2 100644 --- a/lib/protobuf/enum.rb +++ b/lib/protobuf/enum.rb @@ -155,6 +155,8 @@ def self.enum_for_tag(tag) # Returns an Enum object or nil. # def self.fetch(candidate) + return enum_for_tag(candidate) if candidate.is_a?(::Integer) + case candidate when self candidate diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index c3b949a8..90efcb76 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -70,9 +70,9 @@ def default def default_value @default_value ||= case + when optional? then typed_default_value when repeated? then ::Protobuf::Field::FieldArray.new(self).freeze when required? then nil - when optional? then typed_default_value end end diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index b12e1286..d7f4aee4 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -33,12 +33,17 @@ def decode(bytes) end def encode(value) - value_to_encode = value.dup - value_to_encode = value.encode if value.is_a?(::Protobuf::Message) - value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + value_to_encode = "" + if value.is_a?(::Protobuf::Message) + value_to_encode = value.encode + else + value_to_encode = value.dup + end + value_to_encode.force_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) string_size = ::Protobuf::Field::VarintField.encode(value_to_encode.size) - string_size << value_to_encode + + "#{string_size}#{value_to_encode}" end def wire_type diff --git a/lib/protobuf/message.rb b/lib/protobuf/message.rb index a240f54b..9ac1332e 100644 --- a/lib/protobuf/message.rb +++ b/lib/protobuf/message.rb @@ -85,8 +85,10 @@ def each_field def each_field_for_serialization self.class.all_fields.each do |field| value = @values[field.getter] - fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if value.nil? && field.required? - next if value.nil? + if value.nil? + fail ::Protobuf::SerializationError, "Required field #{self.class.name}##{field.name} does not have a value." if field.required? + next + end yield(field, value) end From 3d4ed9b0768e7bf035bfdcccef1aa4ffac0be403 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 7 Feb 2016 15:33:16 -0700 Subject: [PATCH 287/298] remove __send__ of method to decoder and optimize to optional fields --- lib/protobuf/field/base_field.rb | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 90efcb76..3ae505a4 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -122,26 +122,18 @@ def required? # FIXME: need to cleanup (rename) this warthog of a method. def set(message_instance, bytes) - if packed? - array = message_instance.__send__(getter) - method = \ - case wire_type - when ::Protobuf::WireType::FIXED32 then :read_fixed32 - when ::Protobuf::WireType::FIXED64 then :read_fixed64 - when ::Protobuf::WireType::VARINT then :read_varint - end - stream = StringIO.new(bytes) - - until stream.eof? - array << decode(::Protobuf::Decoder.__send__(method, stream)) - end - else - value = decode(bytes) - if repeated? - message_instance.__send__(getter) << value - else - message_instance.__send__(setter, value) - end + return message_instance.__send__(setter, decode(bytes)) unless repeated? + return message_instance.__send__(getter) << decode(bytes) unless packed? + + array = message_instance.__send__(getter) + stream = StringIO.new(bytes) + + if wire_type == ::Protobuf::WireType::VARINT + array << Varint.decode(stream) until stream.eof? + elsif wire_type == ::Protobuf::WireType::FIXED64 + array << stream.read(8) until stream.eof? + elsif wire_type == ::Protobuf::WireType::FIXED32 + array << stream.read(4) until stream.eof? end end From a91da395bb2a647698c4cf2db42ec6f8563743f6 Mon Sep 17 00:00:00 2001 From: Brandon Dewitt Date: Sun, 7 Feb 2016 16:03:44 -0700 Subject: [PATCH 288/298] bump to 3.6.5 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index eda6ed49..0f3c9517 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.4' + VERSION = '3.6.5' end From dad7b00c71040c26a2730e3421c8dfd7c549ca60 Mon Sep 17 00:00:00 2001 From: akihiro17 Date: Mon, 8 Feb 2016 17:29:43 +0900 Subject: [PATCH 289/298] Fix #define_getter method If a required bool field is set to `false`, #define_getter returns its default value(=nil) wrongly because of the following code. https://github.com/ruby-protobuf/protobuf/blob/master/lib/protobuf/field/base_field.rb#L230 ```ruby def define_getter --- @values[field.name] || field.default_value ``` This behavor was introduced by [this commit](https://github.com/ruby-protobuf/protobuf/commit/05aa7756e489e792c7bb0785ef2979931a4879a6) This commit fixes the above issue --- lib/protobuf/field/base_field.rb | 2 +- spec/lib/protobuf/field/bool_field_spec.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 3ae505a4..674bff4a 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -227,7 +227,7 @@ def define_getter message_class.class_eval do define_method(method_name) do - @values[field.name] || field.default_value + @values.fetch(field.name, field.default_value) end end diff --git a/spec/lib/protobuf/field/bool_field_spec.rb b/spec/lib/protobuf/field/bool_field_spec.rb index af254716..aeb27b55 100644 --- a/spec/lib/protobuf/field/bool_field_spec.rb +++ b/spec/lib/protobuf/field/bool_field_spec.rb @@ -4,6 +4,7 @@ class SomeBoolMessage < ::Protobuf::Message optional :bool, :some_bool, 1 + required :bool, :required_bool, 2 end let(:instance) { SomeBoolMessage.new } @@ -48,4 +49,13 @@ class SomeBoolMessage < ::Protobuf::Message end end + describe '#define_getter' do + context 'when required bool field is set to false' do + subject { instance.required_bool = false; instance.required_bool } + + it 'returns false' do + expect(subject).to eq(false) + end + end + end end From 79fd4852b577e199f2201452140940e8226e8307 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 8 Feb 2016 08:58:17 -0700 Subject: [PATCH 290/298] Pull bool getter edge case into BoolField class This is a small change, but let's us keep the optimization in base field. --- lib/protobuf/field/base_field.rb | 2 +- lib/protobuf/field/bool_field.rb | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 674bff4a..3ae505a4 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -227,7 +227,7 @@ def define_getter message_class.class_eval do define_method(method_name) do - @values.fetch(field.name, field.default_value) + @values[field.name] || field.default_value end end diff --git a/lib/protobuf/field/bool_field.rb b/lib/protobuf/field/bool_field.rb index 8b4ee651..afe6c112 100644 --- a/lib/protobuf/field/bool_field.rb +++ b/lib/protobuf/field/bool_field.rb @@ -46,13 +46,20 @@ def encode(value) # def define_getter - super - field = self + method_name = field.getter message_class.class_eval do - alias_method "#{field.getter}?", field.getter + define_method(method_name) do + @values.fetch(field.name, field.default_value) + end end + + message_class.class_eval do + alias_method "#{method_name}?", method_name + end + + ::Protobuf.field_deprecator.deprecate_method(message_class, method_name) if field.deprecated? end end From 2970c0d662ce5619c3f52b6d5f2f6a833603d8ad Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Mon, 8 Feb 2016 09:26:12 -0700 Subject: [PATCH 291/298] Bump version to 3.6.6 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 0f3c9517..6e6da081 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.5' + VERSION = '3.6.6' end From ad4d8523f76364db5614243f7cd12ec66fa102f5 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Wed, 17 Feb 2016 20:12:50 -0700 Subject: [PATCH 292/298] Remove memoization on encode Changing values in repeated fields does not clear the memoized encoded value. This means that changes to repated fields after the memoized encoding has been computed will never be encoded. The pattern works for other field types because the memoized value is being cleared in the setter on the message before we call into the field. The field itself is not involved in clearing the memoized value at all. Repeated fields are a different story. If we were completely resetting a repeated field to a new array, the memoized encoding would be correctly cleared, but because the field array we are pushing into doesn't have any concept of a message, let alone the specific message instance the field belongs to, there is no way to clear the memoized encoded message. We need to remove the memoization until we can find a better approach. Fixes #304. --- lib/protobuf/field/base_field.rb | 2 - lib/protobuf/field/bytes_field.rb | 1 - lib/protobuf/field/enum_field.rb | 1 - lib/protobuf/field/message_field.rb | 1 - lib/protobuf/message/serialization.rb | 10 ++--- spec/lib/protobuf/message_spec.rb | 58 --------------------------- 6 files changed, 4 insertions(+), 69 deletions(-) diff --git a/lib/protobuf/field/base_field.rb b/lib/protobuf/field/base_field.rb index 3ae505a4..e50895ae 100644 --- a/lib/protobuf/field/base_field.rb +++ b/lib/protobuf/field/base_field.rb @@ -198,7 +198,6 @@ def define_array_setter message_class.class_eval do define_method(method_name) do |val| - @encode = nil if val.is_a?(Array) val = val.dup val.compact! @@ -240,7 +239,6 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| - @encode = nil if val.nil? || (val.respond_to?(:empty?) && val.empty?) @values.delete(field.name) elsif field.acceptable?(val) diff --git a/lib/protobuf/field/bytes_field.rb b/lib/protobuf/field/bytes_field.rb index d7f4aee4..6c017558 100644 --- a/lib/protobuf/field/bytes_field.rb +++ b/lib/protobuf/field/bytes_field.rb @@ -62,7 +62,6 @@ def define_setter message_class.class_eval do define_method(method_name) do |val| - @encode = nil case val when String, Symbol @values[field.name] = "#{val}" diff --git a/lib/protobuf/field/enum_field.rb b/lib/protobuf/field/enum_field.rb index 71632cde..ac26ea0e 100644 --- a/lib/protobuf/field/enum_field.rb +++ b/lib/protobuf/field/enum_field.rb @@ -42,7 +42,6 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |value| - @encode = nil orig_value = value if value.nil? @values.delete(field.name) diff --git a/lib/protobuf/field/message_field.rb b/lib/protobuf/field/message_field.rb index 8cb37bd7..6e62cdf4 100644 --- a/lib/protobuf/field/message_field.rb +++ b/lib/protobuf/field/message_field.rb @@ -40,7 +40,6 @@ def define_setter field = self message_class.class_eval do define_method("#{field.name}=") do |val| - @encode = nil case when val.nil? @values.delete(field.name) diff --git a/lib/protobuf/message/serialization.rb b/lib/protobuf/message/serialization.rb index 668b6cea..6526a95c 100644 --- a/lib/protobuf/message/serialization.rb +++ b/lib/protobuf/message/serialization.rb @@ -48,12 +48,10 @@ def decode_from(stream) # Encode this message # def encode - @encode ||= begin - stream = ::StringIO.new - stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) - encode_to(stream) - stream.string - end + stream = ::StringIO.new + stream.set_encoding(::Protobuf::Field::BytesField::BYTES_ENCODING) + encode_to(stream) + stream.string end # Encode this message to the given stream. diff --git a/spec/lib/protobuf/message_spec.rb b/spec/lib/protobuf/message_spec.rb index 1ac3bff0..f4b345c8 100644 --- a/spec/lib/protobuf/message_spec.rb +++ b/spec/lib/protobuf/message_spec.rb @@ -268,64 +268,6 @@ end end - describe 'memoization' do - it "should memoize enum message" do - test_enum = Test::EnumTestMessage.new - test_enum.encode - expect(test_enum.instance_variable_get(:@encode)).to eq("") - test_enum.non_default_enum = 2 - expect(test_enum.instance_variable_get(:@encode)).to be_nil - end - - context "boolean fields" do - let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } - let(:test_resource) { ::Test::Resource.new(values) } - - it "should memoize after bool values change " do - test_resource.encode - expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.ext_is_searchable = false - expect(test_resource.instance_variable_get(:@encode)).to be_nil - end - end - - context "string" do - let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } - let(:test_resource) { ::Test::Resource.new(values) } - - it "should memoize after bool values change " do - test_resource.encode - expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.name = "MVP" - expect(test_resource.instance_variable_get(:@encode)).to be_nil - end - end - - context "string" do - let(:values) { { :ext_is_searchable => true, :name => "STEPH CURRY" } } - let(:test_resource) { ::Test::Resource.new(values) } - - it "should memoize after string values change " do - test_resource.encode - expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.name = "MVP" - expect(test_resource.instance_variable_get(:@encode)).to be_nil - end - end - - context "Int64" do - let(:values) { { :name => "STEPH CURRY", :date_created => 1454712125 } } - let(:test_resource) { ::Test::Resource.new(values) } - - it "should memoize after Int64 values change " do - test_resource.encode - expect(test_resource.instance_variable_get(:@encode)).to eq(test_resource.encode) - test_resource.date_created = 5554712127 - expect(test_resource.instance_variable_get(:@encode)).to be_nil - end - end - end - context "when there's no value for a required field" do let(:message) { ::Test::ResourceWithRequiredField.new } From dee8a9d506c75c3c018c8ea78c97f263405b93b3 Mon Sep 17 00:00:00 2001 From: Adam Hutchison Date: Thu, 18 Feb 2016 21:39:42 -0700 Subject: [PATCH 293/298] Bump version to 3.6.7 --- lib/protobuf/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 6e6da081..cd372fee 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.6' + VERSION = '3.6.7' end From ddac25d7364aba0500be9cfd8679ff7ad5585935 Mon Sep 17 00:00:00 2001 From: Devin Christensen Date: Wed, 11 May 2016 20:31:11 -0600 Subject: [PATCH 294/298] Allow user defined service directories Currently, ZMQ assumes that UDP broadcast based service discovery will fit all needs. This change allows a user to create their own service directory and plug it into the ZMQ connector. --- lib/protobuf/rpc/connectors/zmq.rb | 2 +- lib/protobuf/rpc/service_directory.rb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/protobuf/rpc/connectors/zmq.rb b/lib/protobuf/rpc/connectors/zmq.rb index 8605f488..5bb3079b 100644 --- a/lib/protobuf/rpc/connectors/zmq.rb +++ b/lib/protobuf/rpc/connectors/zmq.rb @@ -226,7 +226,7 @@ def service # Alias for ::Protobuf::Rpc::ServiceDirectory.instance def service_directory - ::Protobuf::Rpc::ServiceDirectory.instance + ::Protobuf::Rpc.service_directory end def snd_timeout diff --git a/lib/protobuf/rpc/service_directory.rb b/lib/protobuf/rpc/service_directory.rb index 81696853..272c3e85 100644 --- a/lib/protobuf/rpc/service_directory.rb +++ b/lib/protobuf/rpc/service_directory.rb @@ -9,6 +9,14 @@ module Protobuf module Rpc + def self.service_directory + @service_directory ||= ::Protobuf::Rpc::ServiceDirectory.instance + end + + def self.service_directory=(directory) + @service_directory = directory + end + class ServiceDirectory include ::Singleton include ::Protobuf::Logging From 573df7793f4963373d321dc6303e3c5085806d64 Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 20 May 2016 12:05:40 -0600 Subject: [PATCH 295/298] Bump version to 3.6.8 --- CHANGES.md | 4 ++++ lib/protobuf/version.rb | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGES.md b/CHANGES.md index 918fba91..59efd534 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,5 +1,9 @@ # Stable (3.x) +3.6.8 +-------- +- Make protobuf serivce directory pluggable. + 3.5.5 -------- - Add native Varint for MRI. diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index cd372fee..264bfa63 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.7' + VERSION = '3.6.8' end From ebf7d343870021c34b7533cec1bd160829f98f8f Mon Sep 17 00:00:00 2001 From: Garrett Thornburg Date: Fri, 20 May 2016 12:07:23 -0600 Subject: [PATCH 296/298] bump version to 3.6.9 because 3.6.8 is a yanked version --- CHANGES.md | 2 +- lib/protobuf/version.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 59efd534..42bd416c 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,6 @@ # Stable (3.x) -3.6.8 +3.6.9 -------- - Make protobuf serivce directory pluggable. diff --git a/lib/protobuf/version.rb b/lib/protobuf/version.rb index 264bfa63..7d30e936 100644 --- a/lib/protobuf/version.rb +++ b/lib/protobuf/version.rb @@ -1,3 +1,3 @@ module Protobuf - VERSION = '3.6.8' + VERSION = '3.6.9' end From 730e2c32ac1f0d1b31e7f56fd02162b88b7b4ec9 Mon Sep 17 00:00:00 2001 From: Atin Malaviya Date: Fri, 16 Sep 2016 11:04:32 -0400 Subject: [PATCH 297/298] Removed versions of ruby we don't support --- .travis.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index 793e2f9d..4eb84129 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,18 +1,13 @@ language: ruby rvm: - 1.9.3 - - 2.0.0 - - 2.1 - - 2.2 - 2.3.1 - jruby - - rbx-2 env: - PROTOBUF_VERSION=2.6.1 - PROTOBUF_VERSION=3.0.0-alpha-2 matrix: allow_failures: - - rvm: rbx-2 - env: PROTOBUF_VERSION=3.0.0-alpha-2 before_install: - gem install bundler From be96b4cc2f1d7b315814a6f6bf1a4c02e371d461 Mon Sep 17 00:00:00 2001 From: Atin Malaviya Date: Fri, 16 Sep 2016 11:10:54 -0400 Subject: [PATCH 298/298] Force install bundler 1.12.5 --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4eb84129..dcd37e11 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,7 +10,7 @@ matrix: allow_failures: - env: PROTOBUF_VERSION=3.0.0-alpha-2 before_install: - - gem install bundler + - gem install bundler -v 1.12.5 script: NO_COMPILE_TEST_PROTOS=1 bundle _1.12.5_ exec rake spec/lib notifications: webhooks: