@@ -594,7 +594,43 @@ func TestSessionsProse(t *testing.T) {
594
594
currentClusterTime , err := pingStartedCommands [1 ].LookupErr ("$clusterTime" )
595
595
require .NoError (mt , err , "$clusterTime not found in command" )
596
596
assert .Equal (mt , initialClusterTime , currentClusterTime , "expected same cluster time, got %v and %v" , initialClusterTime , currentClusterTime )
597
- mt .Fatalf ("$clusterTime: %v %v" , initialClusterTime , currentClusterTime )
597
+ })
598
+ mt .Run ("ping test" , func (mt * mtest.T ) {
599
+ serverMonitor := & event.ServerMonitor {
600
+ ServerHeartbeatStarted : func (e * event.ServerHeartbeatStartedEvent ) {
601
+ fmt .Println ("Server heartbeat started:" , e .ConnectionID )
602
+ },
603
+ ServerHeartbeatSucceeded : func (e * event.ServerHeartbeatSucceededEvent ) {
604
+ fmt .Println ("Server heartbeat succeeded:" , e .ConnectionID , e .Duration , e .Reply )
605
+ },
606
+ }
607
+
608
+ commandMonitor := & event.CommandMonitor {
609
+ Started : func (_ context.Context , cse * event.CommandStartedEvent ) {
610
+ fmt .Println ("Command started:" , cse .CommandName , cse .Command )
611
+ },
612
+ Succeeded : func (_ context.Context , cse * event.CommandSucceededEvent ) {
613
+ fmt .Println ("Command succeeded:" , cse .CommandName , cse .Reply )
614
+ },
615
+ }
616
+
617
+ opts := options .Client ().
618
+ ApplyURI (mtest .ClusterURI ()).
619
+ SetHosts ([]string {mtest .ClusterConnString ().Hosts [0 ]}).
620
+ SetDirect (true ).
621
+ SetHeartbeatInterval (500 * time .Millisecond ). // Minimum interval
622
+ SetServerMonitor (serverMonitor ).
623
+ SetMonitor (commandMonitor )
624
+
625
+ client , err := mongo .Connect (opts )
626
+ require .NoError (mt , err , "expected no error connecting to client, got: %v" , err )
627
+ defer func () {
628
+ err = client .Disconnect (context .Background ())
629
+ require .NoError (mt , err , "expected no error disconnecting client, got: %v" , err )
630
+ }()
631
+
632
+ err = client .Ping (context .Background (), readpref .Primary ())
633
+ require .NoError (mt , err , "expected no error, got: %v" , err )
598
634
})
599
635
}
600
636
0 commit comments