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
This commit is contained in:
Jake Farrell 2012-10-06 00:26:28 +00:00
parent bd6e2b198d
commit 96be0071c6
2 changed files with 26 additions and 26 deletions

View File

@ -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

View File

@ -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