Skip to content

Commit 9a0c3cd

Browse files
committed
RUBY-1279 Close all clients opened in client spec
1 parent 4e9524b commit 9a0c3cd

File tree

1 file changed

+14
-21
lines changed

1 file changed

+14
-21
lines changed

spec/mongo/client_spec.rb

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
describe Mongo::Client do
44

5+
after do
6+
begin; client.close; rescue; end
7+
end
8+
59
describe '#==' do
610

711
let(:client) do
@@ -12,12 +16,12 @@
1216
)
1317
end
1418

15-
after do
16-
client.close
17-
end
18-
1919
context 'when the other is a client' do
2020

21+
after do
22+
other.close
23+
end
24+
2125
context 'when the options and cluster are equal' do
2226

2327
let(:other) do
@@ -105,6 +109,10 @@
105109

106110
context 'when the other is a client' do
107111

112+
after do
113+
other.close
114+
end
115+
108116
context 'when the options and cluster are equal' do
109117

110118
let(:other) do
@@ -228,10 +236,6 @@
228236
described_class.new([default_address.seed], authorized_client.options.merge(options))
229237
end
230238

231-
after do
232-
client.close
233-
end
234-
235239
it 'sets the option' do
236240
expect(client.options['retry_writes']).to eq(options[:retry_writes])
237241
end
@@ -243,10 +247,6 @@
243247
described_class.new([default_address.seed], authorized_client.options.merge(options))
244248
end
245249

246-
after do
247-
client.close
248-
end
249-
250250
context 'when the compressor is supported' do
251251

252252
let(:options) do
@@ -456,10 +456,6 @@
456456
authorized_client.with(logger: logger)
457457
end
458458

459-
after do
460-
client.close
461-
end
462-
463459
it 'does not use the global logger' do
464460
expect(client.cluster.logger).to_not eq(Mongo::Logger.logger)
465461
end
@@ -1373,10 +1369,6 @@
13731369
client.list_databases({}, true)
13741370
end
13751371

1376-
after do
1377-
client.close
1378-
end
1379-
13801372
it 'sends the command with the nameOnly flag set to true' do
13811373
expect(command[:nameOnly]).to be(true)
13821374
end
@@ -1429,7 +1421,8 @@
14291421
end
14301422

14311423
before do
1432-
expect(client.cluster).to receive(:disconnect!).and_call_original
1424+
# note that disconnect! is called also in the after block
1425+
expect(client.cluster).to receive(:disconnect!).twice.and_call_original
14331426
end
14341427

14351428
it 'disconnects the cluster and returns true' do

0 commit comments

Comments
 (0)