Skip to content

Commit

Permalink
RUBY-2433 Add test coverage for Database#collections, Database#collec…
Browse files Browse the repository at this point in the history
…tion_names when there are more than 100 collections
  • Loading branch information
p committed Nov 15, 2020
1 parent 3aab8d9 commit 8431764
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongo/database/view.rb
Expand Up @@ -100,7 +100,7 @@ def collection_names(options = {})
#
# @return [ Array<Hash> ] Info for each collection in the database.
#
# @since 2.0.5
# @since 2.0.5
def list_collections(options = {})
session = client.send(:get_session)
collections_info(session, ServerSelector.primary, options)
Expand Down
76 changes: 76 additions & 0 deletions spec/mongo/database_spec.rb
Expand Up @@ -2,6 +2,19 @@

describe Mongo::Database do

shared_context 'more than 100 collections' do
let(:client) do
root_authorized_client.use('many-collections')
end

before do
120.times do |i|
client["coll-#{i}"].drop
client["coll-#{i}"].create
end
end
end

describe '#==' do

let(:database) do
Expand Down Expand Up @@ -228,6 +241,24 @@
end
end
end

context 'when there are more than 100 collections' do
include_context 'more than 100 collections'

let(:collection_names) do
client.database.collection_names.sort
end

it 'lists all collections' do
if ClusterConfig.instance.fcv_ish == '2.6'
pending 'RUBY-2432'
end

collection_names.length.should == 120
collection_names.should include('coll-0')
collection_names.should include('coll-119')
end
end
end

describe '#list_collections' do
Expand Down Expand Up @@ -391,6 +422,29 @@
end
end
end

context 'when there are more than 100 collections' do
include_context 'more than 100 collections'

let(:collections) do
client.database.list_collections
end

let(:collection_names) do
# 2.6 server prefixes collection names with database name
collections.map { |info| info['name'].sub(/^many-collections\./, '') }.sort
end

it 'lists all collections' do
if ClusterConfig.instance.fcv_ish == '2.6'
pending 'RUBY-2432'
end

collections.length.should == 120
collection_names.should include('coll-0')
collection_names.should include('coll-119')
end
end
end

describe '#collections' do
Expand Down Expand Up @@ -541,6 +595,28 @@
end
end
end

context 'when there are more than 100 collections' do
include_context 'more than 100 collections'

let(:collections) do
client.database.collections
end

let(:collection_names) do
collections.map(&:name).sort
end

it 'lists all collections' do
if ClusterConfig.instance.fcv_ish == '2.6'
pending 'RUBY-2432'
end

collections.length.should == 120
collection_names.should include('coll-0')
collection_names.should include('coll-119')
end
end
end

describe '#command' do
Expand Down

0 comments on commit 8431764

Please sign in to comment.