From: Jake Farrell Date: Sat, 6 Oct 2012 00:26:28 +0000 (+0000) Subject: THRIFT-1707: Adjust server_spec.rb for RSpec 2.11.x and Ruby 1.9.3 X-Git-Tag: 0.9.1~289 X-Git-Url: https://source.supwisdom.com/gerrit/gitweb?a=commitdiff_plain;h=96be0071c62999befcd7ce018198b2219b7597b2;p=common%2Fthrift.git THRIFT-1707: Adjust server_spec.rb for RSpec 2.11.x and Ruby 1.9.3 Client: rb Patch: Nathan Beyer The message expectations in RSpec 2.11.x don't seem to work consistently on Ruby 1.9.x when Threads are used. This is causing a problem in a few tests in server_spec.rb. git-svn-id: https://svn.apache.org/repos/asf/thrift/trunk@1394868 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/lib/rb/spec/server_spec.rb b/lib/rb/spec/server_spec.rb index 0e952ab0..eaecbda0 100644 --- a/lib/rb/spec/server_spec.rb +++ b/lib/rb/spec/server_spec.rb @@ -92,41 +92,41 @@ describe 'Server' do describe Thrift::ThreadPoolServer do before(:each) do @processor = mock("Processor") - @serverTrans = mock("ServerTransport") + @server_trans = mock("ServerTransport") @trans = mock("BaseTransport") @prot = mock("BaseProtocol") @client = mock("Client") - @threadQ = mock("SizedQueue") - SizedQueue.should_receive(:new).with(20).and_return(@threadQ) - @excQ = mock("Queue") - Queue.should_receive(:new).and_return(@excQ) - @server = described_class.new(@processor, @serverTrans, @trans, @prot) - end - - it "should set up the queues" do - @server.instance_variable_get(:'@thread_q').should be(@threadQ) - @server.instance_variable_get(:'@exception_q').should be(@excQ) + @server = described_class.new(@processor, @server_trans, @trans, @prot) end it "should serve inside a thread" do - @server.should_receive(:serve) - @excQ.should_receive(:pop).and_throw(:popped) - lambda { @server.rescuable_serve }.should throw_symbol(:popped) + exception_q = @server.instance_variable_get(:@exception_q) + described_class.any_instance.should_receive(:serve) do + exception_q.push(StandardError.new('ERROR')) + end + expect { @server.rescuable_serve }.to(raise_error('ERROR')) end it "should avoid running the server twice when retrying rescuable_serve" do - @server.should_receive(:serve) - @excQ.should_receive(:pop).twice.and_throw(:popped) - lambda { @server.rescuable_serve }.should throw_symbol(:popped) - lambda { @server.rescuable_serve }.should throw_symbol(:popped) + exception_q = @server.instance_variable_get(:@exception_q) + described_class.any_instance.should_receive(:serve) do + exception_q.push(StandardError.new('ERROR1')) + exception_q.push(StandardError.new('ERROR2')) + end + expect { @server.rescuable_serve }.to(raise_error('ERROR1')) + expect { @server.rescuable_serve }.to(raise_error('ERROR2')) end it "should serve using a thread pool" do - @serverTrans.should_receive(:listen).ordered - @threadQ.should_receive(:push).with(:token) - @threadQ.should_receive(:pop) + thread_q = mock("SizedQueue") + exception_q = mock("Queue") + @server.instance_variable_set(:@thread_q, thread_q) + @server.instance_variable_set(:@exception_q, exception_q) + @server_trans.should_receive(:listen).ordered + thread_q.should_receive(:push).with(:token) + thread_q.should_receive(:pop) Thread.should_receive(:new).and_yield - @serverTrans.should_receive(:accept).exactly(3).times.and_return(@client) + @server_trans.should_receive(:accept).exactly(3).times.and_return(@client) @trans.should_receive(:get_transport).exactly(3).times.and_return(@trans) @prot.should_receive(:get_protocol).exactly(3).times.and_return(@prot) x = 0 @@ -139,9 +139,9 @@ describe 'Server' do end end @trans.should_receive(:close).exactly(3).times - @excQ.should_receive(:push).with(error).and_throw(:stop) - @serverTrans.should_receive(:close) - lambda { @server.serve }.should throw_symbol(:stop) + exception_q.should_receive(:push).with(error).and_throw(:stop) + @server_trans.should_receive(:close) + expect { @server.serve }.to(throw_symbol(:stop)) end end end diff --git a/lib/rb/thrift.gemspec b/lib/rb/thrift.gemspec index 99856e8c..299db08a 100644 --- a/lib/rb/thrift.gemspec +++ b/lib/rb/thrift.gemspec @@ -28,7 +28,7 @@ Gem::Specification.new do |s| s.require_paths = %w[lib ext] s.add_development_dependency 'rake' - s.add_development_dependency 'rspec', '~> 2.11.0' + s.add_development_dependency 'rspec', '~> 2.10.0' s.add_development_dependency 'mongrel', "1.2.0.pre2" end