File tree Expand file tree Collapse file tree 2 files changed +46
-13
lines changed Expand file tree Collapse file tree 2 files changed +46
-13
lines changed Original file line number Diff line number Diff line change @@ -50,22 +50,33 @@ def initialize
50
50
@lock = Mutex.new
51
51
end
52
52
53
- def global_client(name)
54
- if client = @global_clients[name]
53
+ class << self
54
+ def client_perished?( client)
55
55
if !client.cluster.connected?
56
- reconnect = true
56
+ true
57
57
else
58
- reconnect = false
58
+ perished = false
59
59
client.cluster.servers_list.each do |server|
60
60
thread = server.monitor.instance_variable_get('@thread')
61
61
if thread.nil? || !thread.alive?
62
- reconnect = true
62
+ perished = true
63
63
end
64
64
end
65
+ perished
65
66
end
66
- if reconnect
67
+ end
68
+ private :client_perished?
69
+
70
+ def reconnect_client_if_perished(client)
71
+ if client_perished?(client)
67
72
client.reconnect
68
73
end
74
+ end
75
+ end
76
+
77
+ def global_client(name)
78
+ if client = @global_clients[name]
79
+ self.class.reconnect_client_if_perished(client)
69
80
return client
70
81
end
71
82
@@ -204,6 +215,7 @@ def close_local_clients
204
215
end
205
216
206
217
def close_all_clients
218
+ ClusterTools.instance.close_clients
207
219
close_local_clients
208
220
@lock.synchronize do
209
221
@global_clients.each do |name, client|
Original file line number Diff line number Diff line change @@ -313,18 +313,39 @@ def admin_client
313
313
# Since we are triggering elections, we need to have a higher server
314
314
# selection timeout applied. The default timeout for tests assumes a
315
315
# stable deployment.
316
- @admin_client ||= ClientRegistry.instance.global_client('root_authorized').
317
- with(server_selection_timeout: 15).use(:admin)
316
+ (
317
+ @admin_client ||= ClientRegistry.instance.global_client('root_authorized').
318
+ with(server_selection_timeout: 15).use(:admin)
319
+ ).tap do |client|
320
+ ClientRegistry.reconnect_client_if_perished(client)
321
+ end
318
322
end
319
323
320
324
def direct_client(address, options = {})
321
325
@direct_clients ||= {}
322
326
cache_key = {address: address}.update(options)
323
- @direct_clients[cache_key] ||= ClientRegistry.instance.new_local_client(
324
- [address.to_s],
325
- SpecConfig.instance.test_options.merge(
326
- SpecConfig.instance.auth_options).merge(
327
- connect: :direct, server_selection_timeout: 10).merge(options))
327
+ (
328
+ @direct_clients[cache_key] ||= ClientRegistry.instance.new_local_client(
329
+ [address.to_s],
330
+ SpecConfig.instance.test_options.merge(
331
+ SpecConfig.instance.auth_options).merge(
332
+ connect: :direct, server_selection_timeout: 10).merge(options))
333
+ ).tap do |client|
334
+ ClientRegistry.reconnect_client_if_perished(client)
335
+ end
336
+ end
337
+
338
+ def close_clients
339
+ if @admin_client
340
+ @admin_client.close
341
+ @admin_client = nil
342
+ end
343
+ if @direct_clients
344
+ @direct_clients.each do |cache_key, client|
345
+ client.close
346
+ end
347
+ @direct_clients = nil
348
+ end
328
349
end
329
350
330
351
private
You can’t perform that action at this time.
0 commit comments