mongo 2.7.2 → 2.8.0.rc0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +1 -3
- data/lib/mongo/address.rb +17 -20
- data/lib/mongo/address/ipv4.rb +6 -3
- data/lib/mongo/address/ipv6.rb +6 -3
- data/lib/mongo/address/unix.rb +5 -2
- data/lib/mongo/auth.rb +15 -2
- data/lib/mongo/auth/cr/conversation.rb +4 -2
- data/lib/mongo/auth/ldap/conversation.rb +4 -2
- data/lib/mongo/auth/scram.rb +3 -7
- data/lib/mongo/auth/scram/conversation.rb +28 -19
- data/lib/mongo/auth/user.rb +45 -10
- data/lib/mongo/auth/x509/conversation.rb +4 -2
- data/lib/mongo/cluster.rb +9 -17
- data/lib/mongo/error.rb +2 -0
- data/lib/mongo/error/missing_password.rb +29 -0
- data/lib/mongo/error/operation_failure.rb +7 -3
- data/lib/mongo/error/parser.rb +2 -1
- data/lib/mongo/error/sdam_error_detection.rb +54 -0
- data/lib/mongo/operation/aggregate/command.rb +1 -16
- data/lib/mongo/operation/aggregate/op_msg.rb +1 -1
- data/lib/mongo/operation/collections_info.rb +2 -3
- data/lib/mongo/operation/delete/command.rb +2 -15
- data/lib/mongo/operation/delete/legacy.rb +1 -16
- data/lib/mongo/operation/explain/command.rb +1 -16
- data/lib/mongo/operation/explain/legacy.rb +1 -16
- data/lib/mongo/operation/find/command.rb +1 -16
- data/lib/mongo/operation/find/legacy.rb +1 -16
- data/lib/mongo/operation/get_more/command.rb +1 -16
- data/lib/mongo/operation/indexes/command.rb +1 -16
- data/lib/mongo/operation/indexes/legacy.rb +4 -16
- data/lib/mongo/operation/list_collections/command.rb +1 -16
- data/lib/mongo/operation/map_reduce/command.rb +1 -16
- data/lib/mongo/operation/parallel_scan/command.rb +1 -16
- data/lib/mongo/operation/result.rb +3 -0
- data/lib/mongo/operation/shared/executable.rb +4 -0
- data/lib/mongo/operation/shared/polymorphic_lookup.rb +1 -1
- data/lib/mongo/operation/shared/polymorphic_result.rb +8 -1
- data/lib/mongo/operation/shared/result/aggregatable.rb +0 -5
- data/lib/mongo/operation/update/command.rb +2 -15
- data/lib/mongo/operation/update/legacy.rb +1 -16
- data/lib/mongo/operation/users_info/command.rb +1 -16
- data/lib/mongo/retryable.rb +22 -10
- data/lib/mongo/server.rb +10 -1
- data/lib/mongo/server/app_metadata.rb +7 -2
- data/lib/mongo/server/connectable.rb +0 -6
- data/lib/mongo/server/connection.rb +86 -135
- data/lib/mongo/server/connection_base.rb +133 -0
- data/lib/mongo/server/connection_pool.rb +11 -24
- data/lib/mongo/server/connection_pool/queue.rb +41 -41
- data/lib/mongo/server/description.rb +1 -1
- data/lib/mongo/server/monitor.rb +4 -4
- data/lib/mongo/server/monitor/connection.rb +26 -7
- data/lib/mongo/server/pending_connection.rb +36 -0
- data/lib/mongo/server_selector/selectable.rb +9 -1
- data/lib/mongo/session.rb +0 -1
- data/lib/mongo/socket.rb +23 -6
- data/lib/mongo/socket/ssl.rb +11 -18
- data/lib/mongo/socket/tcp.rb +13 -14
- data/lib/mongo/socket/unix.rb +9 -27
- data/lib/mongo/uri.rb +1 -1
- data/lib/mongo/version.rb +1 -1
- data/spec/integration/auth_spec.rb +160 -0
- data/spec/integration/retryable_writes_spec.rb +55 -58
- data/spec/integration/sdam_error_handling_spec.rb +115 -0
- data/spec/mongo/address/ipv4_spec.rb +4 -0
- data/spec/mongo/address/ipv6_spec.rb +4 -0
- data/spec/mongo/auth/scram/conversation_spec.rb +6 -5
- data/spec/mongo/auth/scram/negotiation_spec.rb +25 -36
- data/spec/mongo/auth/scram_spec.rb +2 -2
- data/spec/mongo/auth/user_spec.rb +97 -0
- data/spec/mongo/client_construction_spec.rb +1 -1
- data/spec/mongo/error/operation_failure_spec.rb +125 -1
- data/spec/mongo/retryable_spec.rb +17 -8
- data/spec/mongo/server/connection_pool/queue_spec.rb +24 -10
- data/spec/mongo/server/connection_pool_spec.rb +30 -117
- data/spec/mongo/server/connection_spec.rb +147 -25
- data/spec/mongo/server/description_spec.rb +0 -14
- data/spec/mongo/server/monitor/connection_spec.rb +22 -0
- data/spec/mongo/server_selector_spec.rb +1 -0
- data/spec/mongo/server_spec.rb +6 -6
- data/spec/mongo/socket/ssl_spec.rb +48 -116
- data/spec/mongo/socket/tcp_spec.rb +22 -0
- data/spec/mongo/socket/unix_spec.rb +9 -9
- data/spec/mongo/socket_spec.rb +15 -3
- data/spec/spec_tests/server_selection_spec.rb +2 -0
- data/spec/support/client_registry.rb +8 -2
- data/spec/support/common_shortcuts.rb +20 -1
- data/spec/support/constraints.rb +10 -2
- data/spec/support/lite_constraints.rb +8 -0
- data/spec/support/spec_config.rb +9 -1
- metadata +14 -4
- metadata.gz.sig +0 -0
@@ -203,7 +203,7 @@ describe Mongo::Client do
|
|
203
203
|
it 'does not use compression for authentication messages' do
|
204
204
|
expect(Mongo::Protocol::Compressed).not_to receive(:new)
|
205
205
|
client.cluster.next_primary.send(:with_connection) do |conn|
|
206
|
-
conn.send(:authenticate
|
206
|
+
conn.send(:authenticate!, conn)
|
207
207
|
end
|
208
208
|
end
|
209
209
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require '
|
1
|
+
require 'lite_spec_helper'
|
2
2
|
|
3
3
|
describe Mongo::Error::OperationFailure do
|
4
4
|
|
@@ -219,4 +219,128 @@ describe Mongo::Error::OperationFailure do
|
|
219
219
|
end
|
220
220
|
end
|
221
221
|
end
|
222
|
+
|
223
|
+
describe '#not_master?' do
|
224
|
+
[10107, 13435].each do |code|
|
225
|
+
context "error code #{code}" do
|
226
|
+
subject do
|
227
|
+
described_class.new("thingy (#{code})", nil,
|
228
|
+
:code => code, :code_name => 'thingy')
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'is true' do
|
232
|
+
expect(subject.not_master?).to be true
|
233
|
+
end
|
234
|
+
end
|
235
|
+
end
|
236
|
+
|
237
|
+
# node is recovering error codes
|
238
|
+
[11600, 11602, 13436, 189, 91].each do |code|
|
239
|
+
context "error code #{code}" do
|
240
|
+
subject do
|
241
|
+
described_class.new("thingy (#{code})", nil,
|
242
|
+
:code => code, :code_name => 'thingy')
|
243
|
+
end
|
244
|
+
|
245
|
+
it 'is false' do
|
246
|
+
expect(subject.not_master?).to be false
|
247
|
+
end
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
context 'another error code' do
|
252
|
+
subject do
|
253
|
+
described_class.new('some error (123)', nil,
|
254
|
+
:code => 123, :code_name => 'SomeError')
|
255
|
+
end
|
256
|
+
|
257
|
+
it 'is false' do
|
258
|
+
expect(subject.not_master?).to be false
|
259
|
+
end
|
260
|
+
end
|
261
|
+
|
262
|
+
context 'not master in message with different code' do
|
263
|
+
subject do
|
264
|
+
described_class.new('not master (999)', nil,
|
265
|
+
:code => 999, :code_name => nil)
|
266
|
+
end
|
267
|
+
|
268
|
+
it 'is true' do
|
269
|
+
expect(subject.not_master?).to be true
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
context 'not master or secondary text' do
|
274
|
+
subject do
|
275
|
+
described_class.new('not master or secondary (999)', nil,
|
276
|
+
:code => 999, :code_name => nil)
|
277
|
+
end
|
278
|
+
|
279
|
+
it 'is false' do
|
280
|
+
expect(subject.not_master?).to be false
|
281
|
+
end
|
282
|
+
end
|
283
|
+
end
|
284
|
+
|
285
|
+
describe '#node_recovering?' do
|
286
|
+
[11600, 11602, 13436, 189, 91].each do |code|
|
287
|
+
context "error code #{code}" do
|
288
|
+
subject do
|
289
|
+
described_class.new("thingy (#{code})", nil,
|
290
|
+
:code => code, :code_name => 'thingy')
|
291
|
+
end
|
292
|
+
|
293
|
+
it 'is true' do
|
294
|
+
expect(subject.node_recovering?).to be true
|
295
|
+
end
|
296
|
+
end
|
297
|
+
end
|
298
|
+
|
299
|
+
# not master error codes
|
300
|
+
[10107, 13435].each do |code|
|
301
|
+
context "error code #{code}" do
|
302
|
+
subject do
|
303
|
+
described_class.new("thingy (#{code})", nil,
|
304
|
+
:code => code, :code_name => 'thingy')
|
305
|
+
end
|
306
|
+
|
307
|
+
it 'is false' do
|
308
|
+
expect(subject.node_recovering?).to be false
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
context 'another error code' do
|
314
|
+
subject do
|
315
|
+
described_class.new('some error (123)', nil,
|
316
|
+
:code => 123, :code_name => 'SomeError')
|
317
|
+
end
|
318
|
+
|
319
|
+
it 'is false' do
|
320
|
+
expect(subject.node_recovering?).to be false
|
321
|
+
end
|
322
|
+
end
|
323
|
+
|
324
|
+
context 'node is recovering in message with different code' do
|
325
|
+
subject do
|
326
|
+
described_class.new('node is recovering (999)', nil,
|
327
|
+
:code => 999, :code_name => nil)
|
328
|
+
end
|
329
|
+
|
330
|
+
it 'is true' do
|
331
|
+
expect(subject.node_recovering?).to be true
|
332
|
+
end
|
333
|
+
end
|
334
|
+
|
335
|
+
context 'not master or secondary text' do
|
336
|
+
subject do
|
337
|
+
described_class.new('not master or secondary (999)', nil,
|
338
|
+
:code => 999, :code_name => nil)
|
339
|
+
end
|
340
|
+
|
341
|
+
it 'is true' do
|
342
|
+
expect(subject.node_recovering?).to be true
|
343
|
+
end
|
344
|
+
end
|
345
|
+
end
|
222
346
|
end
|
@@ -79,12 +79,14 @@ describe Mongo::Retryable do
|
|
79
79
|
double('operation')
|
80
80
|
end
|
81
81
|
|
82
|
+
let(:server) { double('server') }
|
83
|
+
|
82
84
|
let(:cluster) do
|
83
|
-
double('cluster', next_primary:
|
85
|
+
double('cluster', next_primary: server)
|
84
86
|
end
|
85
87
|
|
86
88
|
let(:server_selector) do
|
87
|
-
double('server_selector', select_server:
|
89
|
+
double('server_selector', select_server: server)
|
88
90
|
end
|
89
91
|
|
90
92
|
let(:retryable) do
|
@@ -418,7 +420,7 @@ describe Mongo::Retryable do
|
|
418
420
|
# Quick sanity check that the expected code path is being exercised
|
419
421
|
expect(retryable.retry_write_allowed_as_configured?).to be true
|
420
422
|
|
421
|
-
allow(
|
423
|
+
allow(server).to receive(:retry_writes?).and_return(true)
|
422
424
|
allow(cluster).to receive(:scan!)
|
423
425
|
end
|
424
426
|
|
@@ -442,9 +444,9 @@ describe Mongo::Retryable do
|
|
442
444
|
context 'when a not master error occurs' do
|
443
445
|
|
444
446
|
before do
|
447
|
+
server = cluster.next_primary
|
445
448
|
expect(operation).to receive(:execute).and_raise(
|
446
449
|
Mongo::Error::OperationFailure.new('not master')).ordered
|
447
|
-
expect(cluster).to receive(:scan!).and_return(true).ordered
|
448
450
|
expect(operation).to receive(:execute).and_return(true).ordered
|
449
451
|
end
|
450
452
|
|
@@ -454,9 +456,9 @@ describe Mongo::Retryable do
|
|
454
456
|
context 'when a node is recovering error occurs' do
|
455
457
|
|
456
458
|
before do
|
459
|
+
server = cluster.next_primary
|
457
460
|
expect(operation).to receive(:execute).and_raise(
|
458
461
|
Mongo::Error::OperationFailure.new('node is recovering')).ordered
|
459
|
-
expect(cluster).to receive(:scan!).and_return(true).ordered
|
460
462
|
expect(operation).to receive(:execute).and_return(true).ordered
|
461
463
|
end
|
462
464
|
|
@@ -466,10 +468,10 @@ describe Mongo::Retryable do
|
|
466
468
|
context 'when a retryable error occurs with a code' do
|
467
469
|
|
468
470
|
before do
|
471
|
+
server = cluster.next_primary
|
469
472
|
expect(operation).to receive(:execute).and_raise(
|
470
473
|
Mongo::Error::OperationFailure.new('message missing', nil,
|
471
474
|
:code => 91, :code_name => 'ShutdownInProgress')).ordered
|
472
|
-
expect(cluster).to receive(:scan!).and_return(true).ordered
|
473
475
|
expect(operation).to receive(:execute).and_return(true).ordered
|
474
476
|
end
|
475
477
|
|
@@ -494,7 +496,10 @@ describe Mongo::Retryable do
|
|
494
496
|
before do
|
495
497
|
expect(operation).to receive(:execute).and_raise(
|
496
498
|
Mongo::Error::SocketError.new('socket error')).ordered
|
497
|
-
|
499
|
+
# This is where the server would be marked unknown, but since
|
500
|
+
# we are not tracking which server the operation was sent to,
|
501
|
+
# we are not able to assert this.
|
502
|
+
# There is no explicit cluster scan requested.
|
498
503
|
expect(operation).to receive(:execute).and_return(true).ordered
|
499
504
|
end
|
500
505
|
|
@@ -506,7 +511,11 @@ describe Mongo::Retryable do
|
|
506
511
|
before do
|
507
512
|
expect(operation).to receive(:execute).and_raise(
|
508
513
|
Mongo::Error::SocketTimeoutError.new('socket timeout')).ordered
|
509
|
-
|
514
|
+
# This is where the server would be marked unknown, but since
|
515
|
+
# we are not tracking which server the operation was sent to,
|
516
|
+
# we are not able to assert this.
|
517
|
+
# There is no explicit cluster scan requested (and the operation may
|
518
|
+
# end up being sent to the same server it was sent to originally).
|
510
519
|
expect(operation).to receive(:execute).and_return(true).ordered
|
511
520
|
end
|
512
521
|
|
@@ -96,14 +96,14 @@ describe Mongo::Server::ConnectionPool::Queue do
|
|
96
96
|
create_queue(1)
|
97
97
|
end
|
98
98
|
|
99
|
-
it 'disconnects all connections in the queue and
|
99
|
+
it 'disconnects all connections in the queue and bumps generation' do
|
100
100
|
expect(queue.queue_size).to eq(2)
|
101
101
|
expect(queue.pool_size).to eq(2)
|
102
102
|
|
103
103
|
queue.disconnect!
|
104
104
|
|
105
|
-
expect(queue.queue_size).to eq(
|
106
|
-
expect(queue.pool_size).to eq(
|
105
|
+
expect(queue.queue_size).to eq(0)
|
106
|
+
expect(queue.pool_size).to eq(0)
|
107
107
|
|
108
108
|
new_connection = queue.dequeue
|
109
109
|
expect(new_connection).not_to eq(connection)
|
@@ -304,12 +304,14 @@ describe Mongo::Server::ConnectionPool::Queue do
|
|
304
304
|
end
|
305
305
|
|
306
306
|
describe 'close_stale_sockets!!' do
|
307
|
+
after do
|
308
|
+
Timecop.return
|
309
|
+
end
|
307
310
|
|
308
311
|
let(:queue) do
|
309
312
|
described_class.new(max_pool_size: 2, max_idle_time: 0.5) do
|
310
313
|
double('connection').tap do |con|
|
311
314
|
expect(con).to receive(:generation).and_return(1)
|
312
|
-
expect(con).to receive(:disconnect!).and_return(true)
|
313
315
|
allow(con).to receive(:record_checkin!) do
|
314
316
|
allow(con).to receive(:last_checkin).and_return(Time.now)
|
315
317
|
con
|
@@ -324,16 +326,28 @@ describe Mongo::Server::ConnectionPool::Queue do
|
|
324
326
|
end
|
325
327
|
end
|
326
328
|
|
327
|
-
|
328
|
-
queue.
|
329
|
-
expect(
|
330
|
-
|
329
|
+
it 'disconnects all expired and only expired connections' do
|
330
|
+
c1 = queue.dequeue
|
331
|
+
expect(c1).to receive(:disconnect!)
|
332
|
+
c2 = queue.dequeue
|
333
|
+
expect(c2).not_to receive(:disconnect!)
|
334
|
+
|
335
|
+
queue.enqueue(c1)
|
336
|
+
Timecop.travel(Time.now + 1)
|
337
|
+
queue.enqueue(c2)
|
338
|
+
|
339
|
+
expect(queue.queue_size).to eq(2)
|
340
|
+
expect(queue.pool_size).to eq(2)
|
341
|
+
expect(queue.queue.length).to eq(2)
|
342
|
+
|
343
|
+
expect(c1).not_to receive(:connect!)
|
344
|
+
expect(c2).not_to receive(:connect!)
|
345
|
+
|
331
346
|
queue.close_stale_sockets!
|
332
|
-
end
|
333
347
|
|
334
|
-
it 'disconnects and reconnects up to min_size the expired connections' do
|
335
348
|
expect(queue.queue_size).to eq(1)
|
336
349
|
expect(queue.pool_size).to eq(1)
|
350
|
+
expect(queue.queue.length).to eq(1)
|
337
351
|
end
|
338
352
|
end
|
339
353
|
end
|
@@ -35,11 +35,11 @@ describe Mongo::Server::ConnectionPool do
|
|
35
35
|
end
|
36
36
|
|
37
37
|
let!(:pool) do
|
38
|
-
|
38
|
+
server.pool
|
39
39
|
end
|
40
40
|
|
41
41
|
after do
|
42
|
-
expect(
|
42
|
+
expect(server).to receive(:pool).and_return(pool)
|
43
43
|
server.disconnect!
|
44
44
|
end
|
45
45
|
|
@@ -70,7 +70,7 @@ describe Mongo::Server::ConnectionPool do
|
|
70
70
|
end
|
71
71
|
|
72
72
|
let!(:pool) do
|
73
|
-
|
73
|
+
server.pool
|
74
74
|
end
|
75
75
|
|
76
76
|
context 'when no connection is checked out on the same thread' do
|
@@ -129,36 +129,16 @@ describe Mongo::Server::ConnectionPool do
|
|
129
129
|
end
|
130
130
|
|
131
131
|
let!(:pool) do
|
132
|
-
|
132
|
+
server.pool
|
133
133
|
end
|
134
134
|
|
135
135
|
it 'disconnects the queue' do
|
136
|
-
expect(
|
136
|
+
expect(server).to receive(:pool).and_return(pool)
|
137
137
|
expect(pool.send(:queue)).to receive(:disconnect!).once.and_call_original
|
138
138
|
server.disconnect!
|
139
139
|
end
|
140
140
|
end
|
141
141
|
|
142
|
-
describe '.get' do
|
143
|
-
|
144
|
-
let(:server) do
|
145
|
-
Mongo::Server.new(address, cluster, monitoring, listeners, options)
|
146
|
-
end
|
147
|
-
|
148
|
-
let!(:pool) do
|
149
|
-
described_class.get(server)
|
150
|
-
end
|
151
|
-
|
152
|
-
after do
|
153
|
-
expect(cluster).to receive(:pool).with(server).and_return(pool)
|
154
|
-
server.disconnect!
|
155
|
-
end
|
156
|
-
|
157
|
-
it 'returns the pool for the server' do
|
158
|
-
expect(pool).to_not be_nil
|
159
|
-
end
|
160
|
-
end
|
161
|
-
|
162
142
|
describe '#inspect' do
|
163
143
|
|
164
144
|
let(:server) do
|
@@ -166,11 +146,11 @@ describe Mongo::Server::ConnectionPool do
|
|
166
146
|
end
|
167
147
|
|
168
148
|
let!(:pool) do
|
169
|
-
|
149
|
+
server.pool
|
170
150
|
end
|
171
151
|
|
172
152
|
after do
|
173
|
-
expect(
|
153
|
+
expect(server).to receive(:pool).and_return(pool)
|
174
154
|
server.disconnect!
|
175
155
|
end
|
176
156
|
|
@@ -190,7 +170,7 @@ describe Mongo::Server::ConnectionPool do
|
|
190
170
|
end
|
191
171
|
|
192
172
|
let!(:pool) do
|
193
|
-
|
173
|
+
server.pool
|
194
174
|
end
|
195
175
|
|
196
176
|
context 'when a connection cannot be checked out' do
|
@@ -217,7 +197,7 @@ describe Mongo::Server::ConnectionPool do
|
|
217
197
|
end
|
218
198
|
|
219
199
|
let!(:pool) do
|
220
|
-
|
200
|
+
server.pool
|
221
201
|
end
|
222
202
|
|
223
203
|
let(:options) do
|
@@ -245,7 +225,7 @@ describe Mongo::Server::ConnectionPool do
|
|
245
225
|
end
|
246
226
|
|
247
227
|
let!(:pool) do
|
248
|
-
|
228
|
+
server.pool
|
249
229
|
end
|
250
230
|
|
251
231
|
let(:queue) do
|
@@ -297,14 +277,16 @@ describe Mongo::Server::ConnectionPool do
|
|
297
277
|
end
|
298
278
|
|
299
279
|
context 'when min size is > 0' do
|
280
|
+
after do
|
281
|
+
Timecop.return
|
282
|
+
end
|
300
283
|
|
301
284
|
context 'when more than the number of min_size are checked out' do
|
302
|
-
|
303
285
|
let(:options) do
|
304
286
|
SpecConfig.instance.test_options.merge(max_pool_size: 5, min_pool_size: 3, max_idle_time: 0.5)
|
305
287
|
end
|
306
288
|
|
307
|
-
|
289
|
+
it 'closes and removes connections with stale sockets and does not connect new ones' do
|
308
290
|
first = pool.checkout
|
309
291
|
second = pool.checkout
|
310
292
|
third = pool.checkout
|
@@ -316,13 +298,14 @@ describe Mongo::Server::ConnectionPool do
|
|
316
298
|
expect(fifth).to receive(:disconnect!).and_call_original
|
317
299
|
expect(fifth).not_to receive(:connect!)
|
318
300
|
|
319
|
-
|
301
|
+
Timecop.travel(Time.now + 1)
|
302
|
+
expect(queue.length).to be(1)
|
320
303
|
pool.close_stale_sockets!
|
321
|
-
end
|
322
304
|
|
323
|
-
|
324
|
-
expect(queue.
|
325
|
-
expect(queue
|
305
|
+
expect(pool.send(:queue).pool_size).to be(4)
|
306
|
+
expect(pool.send(:queue).queue_size).to be(0)
|
307
|
+
expect(queue.length).to be(0)
|
308
|
+
expect(fifth.connected?).to be(false)
|
326
309
|
end
|
327
310
|
end
|
328
311
|
|
@@ -332,46 +315,7 @@ describe Mongo::Server::ConnectionPool do
|
|
332
315
|
SpecConfig.instance.test_options.merge(max_pool_size: 5, min_pool_size: 3, max_idle_time: 0.5)
|
333
316
|
end
|
334
317
|
|
335
|
-
|
336
|
-
first = pool.checkout
|
337
|
-
second = pool.checkout
|
338
|
-
third = pool.checkout
|
339
|
-
fourth = pool.checkout
|
340
|
-
fifth = pool.checkout
|
341
|
-
|
342
|
-
pool.checkin(third)
|
343
|
-
pool.checkin(fourth)
|
344
|
-
pool.checkin(fifth)
|
345
|
-
|
346
|
-
|
347
|
-
expect(third).to receive(:disconnect!).and_call_original
|
348
|
-
expect(third).not_to receive(:connect!)
|
349
|
-
|
350
|
-
expect(fourth).to receive(:disconnect!).and_call_original
|
351
|
-
expect(fourth).not_to receive(:connect!)
|
352
|
-
|
353
|
-
expect(fifth).to receive(:disconnect!).and_call_original
|
354
|
-
expect(fifth).to receive(:connect!).and_call_original
|
355
|
-
|
356
|
-
sleep(0.5)
|
357
|
-
pool.close_stale_sockets!
|
358
|
-
end
|
359
|
-
|
360
|
-
it 'closes all stale sockets and does not connect new ones' do
|
361
|
-
expect(queue.size).to be(3)
|
362
|
-
expect(queue[0].connected?).to be(true)
|
363
|
-
expect(queue[1].connected?).to be(false)
|
364
|
-
expect(queue[2].connected?).to be(false)
|
365
|
-
end
|
366
|
-
end
|
367
|
-
|
368
|
-
context 'when a stale connection is unsuccessfully reconnected' do
|
369
|
-
|
370
|
-
let(:options) do
|
371
|
-
SpecConfig.instance.test_options.merge(max_pool_size: 5, min_pool_size: 3, max_idle_time: 0.5)
|
372
|
-
end
|
373
|
-
|
374
|
-
before do
|
318
|
+
it 'closes and removes connections with stale sockets and does not connect new ones' do
|
375
319
|
first = pool.checkout
|
376
320
|
second = pool.checkout
|
377
321
|
third = pool.checkout
|
@@ -390,50 +334,19 @@ describe Mongo::Server::ConnectionPool do
|
|
390
334
|
expect(fourth).not_to receive(:connect!)
|
391
335
|
|
392
336
|
expect(fifth).to receive(:disconnect!).and_call_original
|
393
|
-
|
337
|
+
expect(fifth).not_to receive(:connect!).and_call_original
|
394
338
|
|
395
|
-
|
339
|
+
Timecop.travel(Time.now + 1)
|
340
|
+
expect(queue.length).to be(3)
|
396
341
|
pool.close_stale_sockets!
|
397
|
-
end
|
398
|
-
|
399
|
-
it 'is kept in the pool' do
|
400
|
-
expect(queue.size).to be(3)
|
401
|
-
expect(queue[0].connected?).to be(false)
|
402
|
-
expect(queue[1].connected?).to be(false)
|
403
|
-
expect(queue[2].connected?).to be(false)
|
404
|
-
end
|
405
|
-
end
|
406
342
|
|
407
|
-
|
408
|
-
|
409
|
-
|
410
|
-
SpecConfig.instance.test_options.merge(max_pool_size: 5, min_pool_size: 3, max_idle_time: 0.5)
|
411
|
-
end
|
412
|
-
|
413
|
-
before do
|
414
|
-
first = pool.checkout
|
415
|
-
second = pool.checkout
|
416
|
-
third = pool.checkout
|
417
|
-
fourth = pool.checkout
|
418
|
-
fifth = pool.checkout
|
419
|
-
|
420
|
-
pool.checkin(fourth)
|
421
|
-
pool.checkin(fifth)
|
422
|
-
|
423
|
-
expect(fourth).to receive(:disconnect!).and_call_original
|
424
|
-
expect(fourth).not_to receive(:connect!)
|
425
|
-
|
426
|
-
expect(fifth).to receive(:disconnect!).and_call_original
|
427
|
-
expect(fifth).not_to receive(:connect!)
|
428
|
-
|
429
|
-
sleep(0.5)
|
430
|
-
pool.close_stale_sockets!
|
431
|
-
end
|
343
|
+
expect(pool.send(:queue).pool_size).to be(2)
|
344
|
+
expect(pool.send(:queue).queue_size).to be(0)
|
345
|
+
expect(queue.length).to be(0)
|
432
346
|
|
433
|
-
|
434
|
-
expect(
|
435
|
-
expect(
|
436
|
-
expect(queue[1].connected?).to be(false)
|
347
|
+
expect(third.connected?).to be(false)
|
348
|
+
expect(fourth.connected?).to be(false)
|
349
|
+
expect(fifth.connected?).to be(false)
|
437
350
|
end
|
438
351
|
end
|
439
352
|
end
|