@@ -110,6 +110,24 @@ def handshake_and_authenticate!
110
110
111
111
private
112
112
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
+
113
131
# @param [ BSON::Document | nil ] speculative_auth_doc The document to
114
132
# provide in speculativeAuthenticate field of handshake command.
115
133
#
@@ -131,12 +149,7 @@ def handshake!(speculative_auth_doc: nil)
131
149
doc = nil
132
150
@server . handle_handshake_failure! do
133
151
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 )
140
153
result = Operation ::Result . new ( [ response ] )
141
154
result . validate!
142
155
doc = result . documents . first
0 commit comments