@@ -110,6 +110,24 @@ def handshake_and_authenticate!
110110
111111 private
112112
113+ # Sends the hello command to the server, then receive and deserialize
114+ # the response.
115+ #
116+ # This method is extracted to be mocked in the tests.
117+ #
118+ # @param [ Protocol::Message ] Command that should be sent to a server
119+ # for handshake purposes.
120+ #
121+ # @return [ Mongo::Protocol::Reply ] Deserialized server response.
122+ def get_handshake_response ( hello_command )
123+ @server . round_trip_time_averager . measure do
124+ add_server_diagnostics do
125+ socket . write ( hello_command . serialize . to_s )
126+ Protocol ::Message . deserialize ( socket , Protocol ::Message ::MAX_MESSAGE_SIZE )
127+ end
128+ end
129+ end
130+
113131 # @param [ BSON::Document | nil ] speculative_auth_doc The document to
114132 # provide in speculativeAuthenticate field of handshake command.
115133 #
@@ -131,12 +149,7 @@ def handshake!(speculative_auth_doc: nil)
131149 doc = nil
132150 @server . handle_handshake_failure! do
133151 begin
134- response = @server . round_trip_time_averager . measure do
135- add_server_diagnostics do
136- socket . write ( hello_command . serialize . to_s )
137- Protocol ::Message . deserialize ( socket , Protocol ::Message ::MAX_MESSAGE_SIZE )
138- end
139- end
152+ response = get_handshake_response ( hello_command )
140153 result = Operation ::Result . new ( [ response ] )
141154 result . validate!
142155 doc = result . documents . first
0 commit comments