File tree Expand file tree Collapse file tree 2 files changed +28
-6
lines changed
lib/mongo/server_selector Expand file tree Collapse file tree 2 files changed +28
-6
lines changed Original file line number Diff line number Diff line change @@ -115,10 +115,12 @@ def select_server(cluster, ping = nil)
115
115
msg = "Cluster has no addresses, and therefore will never have a server"
116
116
raise Error ::NoServerAvailable . new ( self , cluster , msg )
117
117
end
118
+ =begin Add this check in version 3.0.0
118
119
unless cluster.connected?
119
120
msg = 'Cluster is disconnected'
120
121
raise Error::NoServerAvailable.new(self, cluster, msg)
121
122
end
123
+ =end
122
124
@local_threshold = cluster . options [ :local_threshold ] || LOCAL_THRESHOLD
123
125
@server_selection_timeout = cluster . options [ :server_selection_timeout ] || SERVER_SELECTION_TIMEOUT
124
126
deadline = Time . now + server_selection_timeout
@@ -168,6 +170,9 @@ def select_server(cluster, ping = nil)
168
170
if dead_monitors . any?
169
171
msg += ". The following servers have dead monitor threads: #{ dead_monitors . map ( &:summary ) . join ( ', ' ) } "
170
172
end
173
+ unless cluster . connected?
174
+ msg += ". The cluster is disconnected (client may have been closed)"
175
+ end
171
176
raise Error ::NoServerAvailable . new ( self , cluster , msg )
172
177
end
173
178
Original file line number Diff line number Diff line change 32
32
end
33
33
34
34
context 'client is closed' do
35
- before do
36
- client . close
35
+ context 'there is a known primary' do
36
+ before do
37
+ client . cluster . next_primary
38
+ client . close
39
+ expect ( client . cluster . connected? ) . to be false
40
+ end
41
+
42
+ it 'returns the primary for BC reasons' do
43
+ expect ( result ) . to be_a ( Mongo ::Server )
44
+ end
37
45
end
38
46
39
- it 'raises NoServerAvailable with a message explaining the situation' do
40
- expect do
41
- result
42
- end . to raise_error ( Mongo ::Error ::NoServerAvailable , "Cluster is disconnected" )
47
+ context 'there is no known primary' do
48
+ before do
49
+ primary_server = client . cluster . next_primary
50
+ client . close
51
+ expect ( client . cluster . connected? ) . to be false
52
+ primary_server . unknown!
53
+ end
54
+
55
+ it 'raises NoServerAvailable with a message explaining the situation' do
56
+ expect do
57
+ result
58
+ end . to raise_error ( Mongo ::Error ::NoServerAvailable , /The cluster is disconnected \( client may have been closed\) / )
59
+ end
43
60
end
44
61
end
45
62
You can’t perform that action at this time.
0 commit comments