File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -276,9 +276,6 @@ def closed?
276
276
# the server.
277
277
#
278
278
# @return [ nil ] Always nil.
279
- #
280
- # @raise [ Error::OperationFailure ] If the server cursor close fails.
281
- # @raise [ Error::SocketError | Error::SocketTimeoutError ] When there is a network error.
282
279
def close
283
280
return if closed?
284
281
@@ -294,6 +291,8 @@ def close
294
291
end
295
292
296
293
nil
294
+ rescue Error ::OperationFailure , Error ::SocketError , Error ::SocketTimeoutError
295
+ # Errors are swallowed since there is noting can be done by handling them.
297
296
ensure
298
297
end_session
299
298
@cursor_id = 0
Original file line number Diff line number Diff line change 697
697
698
698
describe '#close' do
699
699
let ( :view ) do
700
- Mongo ::Collection ::View . new ( authorized_collection )
700
+ Mongo ::Collection ::View . new (
701
+ authorized_collection ,
702
+ { } ,
703
+ batch_size : 2 ,
704
+ )
701
705
end
702
706
703
707
let ( :server ) do
712
716
described_class . new ( view , reply , server )
713
717
end
714
718
719
+ let ( :documents ) do
720
+ ( 1 ..10 ) . map { |i | { field : "test#{ i } " } }
721
+ end
722
+
723
+ before do
724
+ authorized_collection . drop
725
+ authorized_collection . insert_many ( documents )
726
+ end
727
+
715
728
it 'closes' do
729
+ expect ( cursor ) . not_to be_closed
716
730
cursor . close
717
731
expect ( cursor ) . to be_closed
718
732
end
719
733
720
734
context 'when there is a socket error during close' do
721
735
clean_slate
722
736
723
- before do
737
+ it 'does not raise an error' do
738
+ cursor
724
739
server . with_connection do |conn |
725
740
expect ( conn ) . to receive ( :deliver )
741
+ . at_least ( :once )
726
742
. and_raise ( Mongo ::Error ::SocketError , "test error" )
727
743
end
728
- end
729
-
730
- it 'raises an error' do
731
744
expect do
732
745
cursor . close
733
- end . to raise_error ( Mongo :: Error :: SocketError , "test error" )
746
+ end . not_to raise_error
734
747
end
735
748
end
736
749
end
You can’t perform that action at this time.
0 commit comments