File tree Expand file tree Collapse file tree 2 files changed +50
-4
lines changed Expand file tree Collapse file tree 2 files changed +50
-4
lines changed Original file line number Diff line number Diff line change @@ -227,15 +227,21 @@ def handshake!
227227 # @api private
228228 def check_document
229229 server_api = @app_metadata . server_api || options [ :server_api ]
230- if hello_ok? || server_api
231- doc = HELLO_DOC
230+ doc = if hello_ok? || server_api
231+ _doc = HELLO_DOC
232232 if server_api
233- doc = doc . merge ( Utils . transform_server_api ( server_api ) )
233+ _doc = _doc . merge ( Utils . transform_server_api ( server_api ) )
234234 end
235- doc
235+ _doc
236236 else
237237 LEGACY_HELLO_DOC
238238 end
239+ # compressors must be set to maintain correct compression status
240+ # in the server description. See RUBY-2427
241+ if compressors = options [ :compressors ]
242+ doc = doc . merge ( compression : compressors )
243+ end
244+ doc
239245 end
240246
241247 private
Original file line number Diff line number Diff line change 135135 end
136136 end
137137 end
138+
139+ describe 'server description changed' do
140+ require_topology :single
141+
142+ let ( :sdam_proc ) do
143+ Proc . new do |client |
144+ client . subscribe ( Mongo ::Monitoring ::SERVER_DESCRIPTION_CHANGED , subscriber )
145+ end
146+ end
147+
148+ let ( :client ) do
149+ new_local_client ( SpecConfig . instance . addresses ,
150+ # Heartbeat interval is bound by 500 ms
151+ SpecConfig . instance . test_options . merge ( client_options ) . merge (
152+ heartbeat_frequency : 0.5 ,
153+ sdam_proc : sdam_proc ,
154+ ) ,
155+ )
156+ end
157+
158+ let ( :client_options ) do
159+ { }
160+ end
161+
162+ it 'is not published when there are no changes in server state' do
163+ client
164+ sleep 6
165+ client . close
166+
167+ events = subscriber . select_succeeded_events ( Mongo ::Monitoring ::Event ::ServerDescriptionChanged )
168+
169+ # In 6 seconds we should have about 10 or 12 heartbeats.
170+ # We expect 1 or 2 description changes:
171+ # The first one from unknown to known,
172+ # The second one because server changes the fields it returns based on
173+ # driver server check payload (e.g. ismaster/isWritablePrimary).
174+ events . length . should >= 1
175+ events . length . should <= 2
176+ end
177+ end
138178end
You can’t perform that action at this time.
0 commit comments