@@ -16,6 +16,7 @@ import (
1616 "go.mongodb.org/mongo-driver/v2/bson"
1717 "go.mongodb.org/mongo-driver/v2/internal/assert"
1818 "go.mongodb.org/mongo-driver/v2/internal/assert/assertbson"
19+ "go.mongodb.org/mongo-driver/v2/internal/handshake"
1920 "go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
2021 "go.mongodb.org/mongo-driver/v2/internal/require"
2122 "go.mongodb.org/mongo-driver/v2/mongo/options"
@@ -261,6 +262,8 @@ func TestHandshakeProse(t *testing.T) {
261262 }
262263
263264 for _ , tc := range testCases {
265+ tc := tc // Avoid implicit memory aliasing in for loop.
266+
264267 mt .RunOpts (tc .name , opts , func (mt * mtest.T ) {
265268 for k , v := range tc .env {
266269 mt .Setenv (k , v )
@@ -301,7 +304,7 @@ func TestLoadBalancedConnectionHandshake(t *testing.T) {
301304
302305 // Per the specifications, if loadBalanced=true, drivers MUST use the hello
303306 // command for the initial handshake and use the OP_MSG protocol.
304- assert .True (mt , firstMessage . IsHandshake (), "expected first message to be a handshake" )
307+ assert .Equal (mt , "hello" , firstMessage . CommandName )
305308 assert .Equal (mt , wiremessage .OpMsg , firstMessage .Sent .OpCode )
306309 })
307310
@@ -320,13 +323,17 @@ func TestLoadBalancedConnectionHandshake(t *testing.T) {
320323 require .NotNil (mt , firstMessage , "expected to capture a proxied message" )
321324
322325 want := wiremessage .OpQuery
326+
327+ hello := handshake .LegacyHello
323328 if os .Getenv ("REQUIRE_API_VERSION" ) == "true" {
329+ hello = "hello"
330+
324331 // If the server API version is requested, then we should use OP_MSG
325332 // regardless of the topology
326333 want = wiremessage .OpMsg
327334 }
328335
329- assert .True (mt , firstMessage . IsHandshake () , "expected first message to be a handshake" )
336+ assert .Equal (mt , hello , firstMessage , "expected first message to be a handshake" )
330337 assert .Equal (mt , want , firstMessage .Sent .OpCode )
331338 })
332339}
@@ -655,6 +662,8 @@ func TestHandshakeProse_AppendMetadata_Test1_Test2_Test3(t *testing.T) {
655662 }
656663
657664 for _ , tc := range testCases {
665+ tc := tc // Avoid implicit memory aliasing in for loop.
666+
658667 // Create a top-level client that can be shared among sub-tests. This is
659668 // necessary to test appending driver info to an existing client.
660669 opts := mtest .NewOptions ().CreateClient (false ).ClientType (mtest .Proxy )
@@ -686,7 +695,7 @@ func TestHandshakeProse_AppendMetadata_Test1_Test2_Test3(t *testing.T) {
686695 assert .True (mt , initialClientMetadata .IsHandshake (), "expected first message to be a handshake" )
687696
688697 // Wait 5ms for the connection to become idle.
689- time .Sleep (20 * time .Millisecond )
698+ time .Sleep (5 * time .Millisecond )
690699
691700 mt .Client .AppendDriverInfo (tc .driverInfo )
692701
@@ -736,7 +745,7 @@ func TestHandshakeProse_AppendMetadata_MultipleUpdatesWithDuplicateFields(t *tes
736745 require .NoError (mt , err , "Ping error: %v" , err )
737746
738747 // 4. Wait 5ms for the connection to become idle.
739- time .Sleep (20 * time .Millisecond )
748+ time .Sleep (5 * time .Millisecond )
740749
741750 // 5. Append new driver info.
742751 mt .Client .AppendDriverInfo (options.DriverInfo {
@@ -771,7 +780,7 @@ func TestHandshakeProse_AppendMetadata_MultipleUpdatesWithDuplicateFields(t *tes
771780 })
772781
773782 // 8. Wait 5ms for the connection to become idle.
774- time .Sleep (20 * time .Millisecond )
783+ time .Sleep (5 * time .Millisecond )
775784
776785 // Drain the proxy to ensure we only capture messages after appending.
777786 mt .GetProxyCapture ().Drain ()
@@ -838,7 +847,7 @@ func TestHandshakeProse_AppendMetadata_NotAppendedIfIdentical(t *testing.T) {
838847 })
839848
840849 // 3. Wait 5ms for the connection to become idle.
841- time .Sleep (20 * time .Millisecond )
850+ time .Sleep (5 * time .Millisecond )
842851
843852 // 5. Append new driver info.
844853 mt .Client .AppendDriverInfo (options.DriverInfo {
@@ -894,7 +903,7 @@ func TestHandshakeProse_AppendMetadata_NotAppendedIfIdentical_NonSequential(t *t
894903 require .NoError (mt , err , "Ping error: %v" , err )
895904
896905 // 3. Wait 5ms for the connection to become idle.
897- time .Sleep (20 * time .Millisecond )
906+ time .Sleep (5 * time .Millisecond )
898907
899908 // 4. Append new driver info.
900909 mt .Client .AppendDriverInfo (options.DriverInfo {
@@ -929,7 +938,7 @@ func TestHandshakeProse_AppendMetadata_NotAppendedIfIdentical_NonSequential(t *t
929938 })
930939
931940 // 7. Wait 5ms for the connection to become idle.
932- time .Sleep (20 * time .Millisecond )
941+ time .Sleep (5 * time .Millisecond )
933942
934943 // 8. Append new driver info.
935944 mt .Client .AppendDriverInfo (options.DriverInfo {
@@ -1040,6 +1049,8 @@ func TestHandshakeProse_AppendMetadata_EmptyStrings(t *testing.T) {
10401049 }
10411050
10421051 for _ , tc := range testCases {
1052+ tc := tc // Avoid implicit memory aliasing in for loop.
1053+
10431054 // Create a top-level client that can be shared among sub-tests. This is
10441055 // necessary to test appending driver info to an existing client.
10451056 opts := mtest .NewOptions ().CreateClient (false ).ClientType (mtest .Proxy )
@@ -1074,7 +1085,7 @@ func TestHandshakeProse_AppendMetadata_EmptyStrings(t *testing.T) {
10741085 // metadata value.
10751086
10761087 // 5. Wait 5ms for the connection to become idle.
1077- time .Sleep (20 * time .Millisecond )
1088+ time .Sleep (5 * time .Millisecond )
10781089
10791090 // 6. Append the `DriverInfoOptions` from the selected test case from
10801091 // the appended metadata section.
@@ -1216,7 +1227,7 @@ func TestHandshakeProse_AppendMetadata_EmptyStrings_InitializedClient(t *testing
12161227 // metadata value.
12171228
12181229 // 4. Wait 5ms for the connection to become idle.
1219- time .Sleep (20 * time .Millisecond )
1230+ time .Sleep (5 * time .Millisecond )
12201231
12211232 // 5. Append the `DriverInfoOptions` from the selected test case from
12221233 // the appended metadata section.
0 commit comments