@@ -17,6 +17,7 @@ import (
1717 "time"
1818
1919 "go.mongodb.org/mongo-driver/v2/bson"
20+ "go.mongodb.org/mongo-driver/v2/event"
2021 "go.mongodb.org/mongo-driver/v2/internal/assert"
2122 "go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
2223 "go.mongodb.org/mongo-driver/v2/internal/mongoutil"
@@ -509,24 +510,40 @@ func TestSessionsProse(t *testing.T) {
509510
510511 })
511512
512- clustertimeopts := mtest .NewOptions ().ClientType (mtest .Pinned ).ClientOptions (options .Client ().SetDirect (true ))
513- mt .RunOpts ("20 Drivers do not gossip $clusterTime on SDAM commands" , clustertimeopts , func (mt * mtest.T ) {
514- res , err := mt .DB .RunCommand (context .Background (), bson.D {{"ping" , 1 }}).Raw ()
513+ mt .Run ("20 Drivers do not gossip $clusterTime on SDAM commands" , func (mt * mtest.T ) {
514+ opts := options .Client ().
515+ ApplyURI (mtest .ClusterURI ()).
516+ SetHosts ([]string {mtest .ClusterConnString ().Hosts [0 ]}).
517+ SetDirect (true ).
518+ SetHeartbeatInterval (500 * time .Millisecond ).
519+ SetMonitor (& event.CommandMonitor {
520+ Started : func (ctx context.Context , cse * event.CommandStartedEvent ) {
521+ fmt .Println ("Command started:" , cse .CommandName , cse .Command )
522+ },
523+ Succeeded : func (ctx context.Context , cse * event.CommandSucceededEvent ) {
524+ fmt .Println ("Command succeeded:" , cse .CommandName , cse .Reply )
525+ },
526+ })
527+
528+ client , err := mongo .Connect (opts )
529+ require .NoError (mt , err , "expected no error connecting to client, got: %v" , err )
530+ defer client .Disconnect (context .Background ())
531+
532+ res , err := client .Database ("admin" ).RunCommand (context .Background (), bson.D {
533+ {"ping" , 1 },
534+ }).Raw ()
515535 require .NoError (mt , err , "expected no error, got: %v" , err )
516536 mt .Log ("result of ping command:" , res )
517537
518- // assert $clusterTime was sent to server
519- started := mt .GetStartedEvent ()
520- require .NotNil (mt , started , "expected started event, got nil" )
521- _ , err = started .Command .LookupErr ("$clusterTime" )
522- require .NoError (mt , err , "$clusterTime not sent" )
523-
524- // record response cluster time
525- succeeded := mt .GetSucceededEvent ()
526- require .NotNil (mt , succeeded , "expected succeeded event, got nil" )
527- replyClusterTimeVal , err := succeeded .Reply .LookupErr ("$clusterTime" )
528- require .NoError (mt , err , "$clusterTime not found in response" )
529- mt .Fatalf ("$clusterTime: %v" , replyClusterTimeVal )
538+ mt .Client .Database ("test" ).Collection ("test" ).InsertOne (context .Background (), bson.D {{"advance" , "$clusterTime" }})
539+
540+ time .Sleep (3 * time .Second )
541+
542+ res , err = client .Database ("admin" ).RunCommand (context .Background (), bson.D {
543+ {"ping" , 1 },
544+ }).Raw ()
545+ require .NoError (mt , err , "expected no error, got: %v" , err )
546+ mt .Log ("result of ping command:" , res )
530547 })
531548}
532549
0 commit comments