@@ -319,14 +319,20 @@ func TestReconnectSucceed(t *testing.T) {
319319 // Close the old conn before reconnection.
320320 require .NoError (t , proxy .serverConn .Close ())
321321
322- // Accept the connection inside a goroutine. We will also write some
323- // data so that the reconnection can succeed. We will mock three writes
324- // and two reads inside our proxy server,
325- // - write protocol info
326- // - read auth info
327- // - write auth challenge
328- // - read auth challenge
329- // - write OK
322+ // Accept the connection inside a goroutine. When the client makes a
323+ // reconnection, the messages flow is,
324+ // 1. the client sends the command PROTOCOLINFO to the server.
325+ // 2. the server responds with its protocol version.
326+ // 3. the client reads the response and sends the command AUTHENTICATE
327+ // to the server
328+ // 4. the server responds with the authentication info.
329+ //
330+ // From the server's PoV, We need to mock two reads and two writes
331+ // inside the connection,
332+ // 1. read the command PROTOCOLINFO sent from the client.
333+ // 2. write protocol info so the client can read it.
334+ // 3. read the command AUTHENTICATE sent from the client.
335+ // 4. write auth challenge so the client can read it.
330336 go func () {
331337 // Accept the new connection.
332338 server , err := proxy .server .Accept ()
@@ -335,6 +341,11 @@ func TestReconnectSucceed(t *testing.T) {
335341 t .Logf ("server listening on %v, client listening on %v" ,
336342 server .LocalAddr (), server .RemoteAddr ())
337343
344+ // Read the protocol command from the client.
345+ buf := make ([]byte , 65535 )
346+ _ , err = server .Read (buf )
347+ require .NoError (t , err )
348+
338349 // Write the protocol info.
339350 resp := "250-PROTOCOLINFO 1\n " +
340351 "250-AUTH METHODS=NULL\n " +
@@ -343,23 +354,13 @@ func TestReconnectSucceed(t *testing.T) {
343354 require .NoErrorf (t , err , "failed to write protocol info" )
344355
345356 // Read the auth info from the client.
346- buf := make ([]byte , 65535 )
347357 _ , err = server .Read (buf )
348358 require .NoError (t , err )
349359
350360 // Write the auth challenge.
351361 resp = "250 AUTHCHALLENGE SERVERHASH=fake\n "
352362 _ , err = server .Write ([]byte (resp ))
353363 require .NoErrorf (t , err , "failed to write auth challenge" )
354-
355- // Read the auth challenge resp from the client.
356- _ , err = server .Read (buf )
357- require .NoError (t , err )
358-
359- // Write OK resp.
360- resp = "250 OK\n "
361- _ , err = server .Write ([]byte (resp ))
362- require .NoErrorf (t , err , "failed to write response auth" )
363364 }()
364365
365366 // Reconnect should succeed.
0 commit comments