@@ -175,83 +175,62 @@ class RetryableHost
175175
176176 context 'when an operation failure occurs' do
177177
178- context 'when the cluster is not a mongos' do
178+ context 'when the operation failure is not retryable' do
179+
180+ let ( :error ) do
181+ Mongo ::Error ::OperationFailure . new ( 'not authorized' )
182+ end
179183
180184 before do
181- expect ( operation ) . to receive ( :execute ) . and_raise ( Mongo ::Error ::OperationFailure ) . ordered
182- expect ( cluster ) . to receive ( :sharded? ) . and_return ( false )
185+ expect ( operation ) . to receive ( :execute ) . and_raise ( error ) . ordered
183186 end
184187
185- it 'raises an exception' do
188+ it 'raises the exception' do
186189 expect {
187190 read_operation
188191 } . to raise_error ( Mongo ::Error ::OperationFailure )
189192 end
190193 end
191194
192- context 'when the cluster is a mongos ' do
195+ context 'when the operation failure is retryable ' do
193196
194- context 'when the operation failure is not retryable' do
197+ let ( :error ) do
198+ Mongo ::Error ::OperationFailure . new ( 'not master' )
199+ end
195200
196- let ( :error ) do
197- Mongo ::Error ::OperationFailure . new ( 'not authorized' )
198- end
201+ context 'when the retry succeeds' do
199202
200203 before do
204+ expect ( retryable ) . to receive ( :select_server ) . ordered
201205 expect ( operation ) . to receive ( :execute ) . and_raise ( error ) . ordered
202- expect ( cluster ) . to receive ( :sharded? ) . and_return ( true )
206+ expect ( client ) . to receive ( :read_retry_interval ) . and_return ( 0.1 ) . ordered
207+ expect ( retryable ) . to receive ( :select_server ) . ordered
208+ expect ( operation ) . to receive ( :execute ) . and_return ( true ) . ordered
203209 end
204210
205- it 'raises the exception' do
206- expect {
207- read_operation
208- } . to raise_error ( Mongo ::Error ::OperationFailure )
211+ it 'returns the result' do
212+ expect ( read_operation ) . to be true
209213 end
210214 end
211215
212- context 'when the operation failure is retryable' do
216+ context 'when the retry fails once and then succeeds' do
217+ let ( :max_read_retries ) { 2 }
213218
214- let ( :error ) do
215- Mongo ::Error ::OperationFailure . new ( 'not master' )
216- end
217-
218- context 'when the retry succeeds' do
219+ before do
220+ expect ( retryable ) . to receive ( :select_server ) . ordered
221+ expect ( operation ) . to receive ( :execute ) . and_raise ( error ) . ordered
219222
220- before do
221- expect ( retryable ) . to receive ( :select_server ) . ordered
222- expect ( operation ) . to receive ( :execute ) . and_raise ( error ) . ordered
223- expect ( cluster ) . to receive ( :sharded? ) . and_return ( true )
224- expect ( client ) . to receive ( :read_retry_interval ) . and_return ( 0.1 ) . ordered
225- expect ( retryable ) . to receive ( :select_server ) . ordered
226- expect ( operation ) . to receive ( :execute ) . and_return ( true ) . ordered
227- end
223+ expect ( client ) . to receive ( :read_retry_interval ) . and_return ( 0.1 ) . ordered
224+ expect ( retryable ) . to receive ( :select_server ) . ordered
225+ expect ( operation ) . to receive ( :execute ) . and_raise ( error ) . ordered
228226
229- it 'returns the result' do
230- expect ( read_operation ) . to be true
231- end
227+ expect ( client ) . to receive ( :read_retry_interval ) . and_return ( 0.1 ) . ordered
228+ expect ( retryable ) . to receive ( :select_server ) . ordered
229+ expect ( operation ) . to receive ( :execute ) . and_return ( true ) . ordered
232230 end
233231
234- context 'when the retry fails once and then succeeds' do
235- let ( :max_read_retries ) { 2 }
236-
237- before do
238- expect ( retryable ) . to receive ( :select_server ) . ordered
239- expect ( operation ) . to receive ( :execute ) . and_raise ( error ) . ordered
240-
241- expect ( cluster ) . to receive ( :sharded? ) . and_return ( true )
242- expect ( client ) . to receive ( :read_retry_interval ) . and_return ( 0.1 ) . ordered
243- expect ( retryable ) . to receive ( :select_server ) . ordered
244- expect ( operation ) . to receive ( :execute ) . and_raise ( error ) . ordered
245-
246- expect ( cluster ) . to receive ( :sharded? ) . and_return ( true )
247- expect ( client ) . to receive ( :read_retry_interval ) . and_return ( 0.1 ) . ordered
248- expect ( retryable ) . to receive ( :select_server ) . ordered
249- expect ( operation ) . to receive ( :execute ) . and_return ( true ) . ordered
250- end
251-
252- it 'returns the result' do
253- expect ( read_operation ) . to be true
254- end
232+ it 'returns the result' do
233+ expect ( read_operation ) . to be true
255234 end
256235 end
257236 end
0 commit comments