spec/mongo/retryable_spec.rb in mongo-2.4.1 vs spec/mongo/retryable_spec.rb in mongo-2.4.2
- old
+ new
@@ -34,23 +34,23 @@
end
end
end
end
- describe '#read_with_retry' do
+ let(:operation) do
+ double('operation')
+ end
- let(:operation) do
- double('operation')
- end
+ let(:cluster) do
+ double('cluster')
+ end
- let(:cluster) do
- double('cluster')
- end
+ let(:retryable) do
+ klass.new(operation, cluster)
+ end
- let(:retryable) do
- klass.new(operation, cluster)
- end
+ describe '#read_with_retry' do
context 'when no exception occurs' do
before do
expect(operation).to receive(:execute).and_return(true)
@@ -63,10 +63,11 @@
context 'when a socket error occurs' do
before do
expect(operation).to receive(:execute).and_raise(Mongo::Error::SocketError).ordered
+ expect(cluster).to receive(:max_read_retries).and_return(1).ordered
expect(cluster).to receive(:scan!).and_return(true).ordered
expect(operation).to receive(:execute).and_return(true).ordered
end
it 'executes the operation twice' do
@@ -76,10 +77,11 @@
context 'when a socket timeout error occurs' do
before do
expect(operation).to receive(:execute).and_raise(Mongo::Error::SocketTimeoutError).ordered
+ expect(cluster).to receive(:max_read_retries).and_return(1).ordered
expect(cluster).to receive(:scan!).and_return(true).ordered
expect(operation).to receive(:execute).and_return(true).ordered
end
it 'executes the operation twice' do
@@ -167,22 +169,10 @@
end
end
describe '#write_with_retry' do
- let(:operation) do
- double('operation')
- end
-
- let(:cluster) do
- double('cluster')
- end
-
- let(:retryable) do
- klass.new(operation, cluster)
- end
-
context 'when no exception occurs' do
before do
expect(operation).to receive(:execute).and_return(true)
end
@@ -203,10 +193,23 @@
it 'executes the operation twice' do
expect(retryable.write).to be true
end
end
+ context 'when a not primary error occurs' do
+
+ before do
+ expect(operation).to receive(:execute).and_raise(Mongo::Error::OperationFailure.new('Not primary')).ordered
+ expect(cluster).to receive(:scan!).and_return(true).ordered
+ expect(operation).to receive(:execute).and_return(true).ordered
+ end
+
+ it 'executes the operation twice' do
+ expect(retryable.write).to be true
+ end
+ end
+
context 'when a normal operation failure occurs' do
before do
expect(operation).to receive(:execute).and_raise(Mongo::Error::OperationFailure).ordered
end
@@ -215,7 +218,8 @@
expect {
retryable.write
}.to raise_error(Mongo::Error::OperationFailure)
end
end
+
end
end