@@ -175,83 +175,62 @@ class RetryableHost
175
175
176
176
context 'when an operation failure occurs' do
177
177
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
179
183
180
184
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
183
186
end
184
187
185
- it 'raises an exception' do
188
+ it 'raises the exception' do
186
189
expect {
187
190
read_operation
188
191
} . to raise_error ( Mongo ::Error ::OperationFailure )
189
192
end
190
193
end
191
194
192
- context 'when the cluster is a mongos ' do
195
+ context 'when the operation failure is retryable ' do
193
196
194
- context 'when the operation failure is not retryable' do
197
+ let ( :error ) do
198
+ Mongo ::Error ::OperationFailure . new ( 'not master' )
199
+ end
195
200
196
- let ( :error ) do
197
- Mongo ::Error ::OperationFailure . new ( 'not authorized' )
198
- end
201
+ context 'when the retry succeeds' do
199
202
200
203
before do
204
+ expect ( retryable ) . to receive ( :select_server ) . ordered
201
205
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
203
209
end
204
210
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
209
213
end
210
214
end
211
215
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 }
213
218
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
219
222
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
228
226
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
232
230
end
233
231
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
255
234
end
256
235
end
257
236
end
0 commit comments