Skip to content

Commit e2b7765

Browse files
comandeo-mongop
andauthored
MONGOID-5130 Remove conn count from client spec (#5055)
Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent 9e28a6f commit e2b7765

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

lib/mongoid/persistence_context.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,9 @@ def get(object)
210210
# context that was set before this context was used.
211211
def clear(object, cluster = nil, original_context = nil)
212212
if context = get(object)
213-
context.client.close unless (context.cluster.equal?(cluster) || cluster.nil?)
213+
unless cluster.nil? || context.cluster.equal?(cluster)
214+
context.client.close
215+
end
214216
end
215217
ensure
216218
Thread.current["[mongoid][#{object.object_id}]:context"] = original_context

spec/mongoid/clients/options_spec.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,9 +82,11 @@
8282

8383
let!(:connections_and_cluster_during) do
8484
connections = nil
85-
cluster = Minim.with(options) do |klass|
85+
cluster = nil
86+
Minim.with(options) do |klass|
8687
klass.where(name: 'emily').to_a
8788
connections = Minim.mongo_client.database.command(serverStatus: 1).first['connections']['current']
89+
cluster = Minim.collection.cluster
8890
end
8991
[ connections, cluster ]
9092
end
@@ -123,9 +125,10 @@
123125
end
124126

125127
it 'disconnects the new cluster when the block exits' do
126-
skip 'https://jira.mongodb.org/browse/MONGOID-5130'
128+
expect(cluster_after).not_to be(cluster_during)
127129

128-
expect(connections_before).to eq(connections_after)
130+
cluster_during.connected?.should be false
131+
cluster_before.connected?.should be true
129132
end
130133
end
131134

@@ -139,13 +142,14 @@
139142

140143
it 'does not create a new cluster' do
141144
expect(connections_during).to eq(connections_before)
145+
146+
cluster_during.should be cluster_before
142147
end
143148

144149
it 'does not disconnect the original cluster' do
145-
skip 'https://jira.mongodb.org/browse/MONGOID-5130'
146-
147-
expect(connections_after).to eq(connections_before)
148150
expect(cluster_before).to be(cluster_after)
151+
152+
cluster_before.connected?.should be true
149153
end
150154
end
151155

0 commit comments

Comments
 (0)