spec/mongo/retryable_spec.rb in mongo-2.10.5 vs spec/mongo/retryable_spec.rb in mongo-2.11.0.rc0
- old
+ new
@@ -173,65 +173,86 @@
end
end
context 'when an operation failure occurs' do
- context 'when the operation failure is not retryable' do
+ context 'when the cluster is not a mongos' do
- let(:error) do
- Mongo::Error::OperationFailure.new('not authorized')
- end
-
before do
- expect(operation).to receive(:execute).and_raise(error).ordered
+ expect(operation).to receive(:execute).and_raise(Mongo::Error::OperationFailure).ordered
+ expect(cluster).to receive(:sharded?).and_return(false)
end
- it 'raises the exception' do
+ it 'raises an exception' do
expect {
read_operation
}.to raise_error(Mongo::Error::OperationFailure)
end
end
- context 'when the operation failure is retryable' do
+ context 'when the cluster is a mongos' do
- let(:error) do
- Mongo::Error::OperationFailure.new('not master')
- end
+ context 'when the operation failure is not retryable' do
- context 'when the retry succeeds' do
+ let(:error) do
+ Mongo::Error::OperationFailure.new('not authorized')
+ end
before do
- expect(retryable).to receive(:select_server).ordered
expect(operation).to receive(:execute).and_raise(error).ordered
- expect(client).to receive(:read_retry_interval).and_return(0.1).ordered
- expect(retryable).to receive(:select_server).ordered
- expect(operation).to receive(:execute).and_return(true).ordered
+ expect(cluster).to receive(:sharded?).and_return(true)
end
- it 'returns the result' do
- expect(read_operation).to be true
+ it 'raises the exception' do
+ expect {
+ read_operation
+ }.to raise_error(Mongo::Error::OperationFailure)
end
end
- context 'when the retry fails once and then succeeds' do
- let(:max_read_retries) { 2 }
+ context 'when the operation failure is retryable' do
- before do
- expect(retryable).to receive(:select_server).ordered
- expect(operation).to receive(:execute).and_raise(error).ordered
+ let(:error) do
+ Mongo::Error::OperationFailure.new('not master')
+ end
- expect(client).to receive(:read_retry_interval).and_return(0.1).ordered
- expect(retryable).to receive(:select_server).ordered
- expect(operation).to receive(:execute).and_raise(error).ordered
+ context 'when the retry succeeds' do
- expect(client).to receive(:read_retry_interval).and_return(0.1).ordered
- expect(retryable).to receive(:select_server).ordered
- expect(operation).to receive(:execute).and_return(true).ordered
+ before do
+ expect(retryable).to receive(:select_server).ordered
+ expect(operation).to receive(:execute).and_raise(error).ordered
+ expect(cluster).to receive(:sharded?).and_return(true)
+ expect(client).to receive(:read_retry_interval).and_return(0.1).ordered
+ expect(retryable).to receive(:select_server).ordered
+ expect(operation).to receive(:execute).and_return(true).ordered
+ end
+
+ it 'returns the result' do
+ expect(read_operation).to be true
+ end
end
- it 'returns the result' do
- expect(read_operation).to be true
+ context 'when the retry fails once and then succeeds' do
+ let(:max_read_retries) { 2 }
+
+ before do
+ expect(retryable).to receive(:select_server).ordered
+ expect(operation).to receive(:execute).and_raise(error).ordered
+
+ expect(cluster).to receive(:sharded?).and_return(true)
+ expect(client).to receive(:read_retry_interval).and_return(0.1).ordered
+ expect(retryable).to receive(:select_server).ordered
+ expect(operation).to receive(:execute).and_raise(error).ordered
+
+ expect(cluster).to receive(:sharded?).and_return(true)
+ expect(client).to receive(:read_retry_interval).and_return(0.1).ordered
+ expect(retryable).to receive(:select_server).ordered
+ expect(operation).to receive(:execute).and_return(true).ordered
+ end
+
+ it 'returns the result' do
+ expect(read_operation).to be true
+ end
end
end
end
end
end