@@ -50,6 +50,21 @@ func TestSessionPool(t *testing.T) {
50
50
got = getSessionID (mt , secondSess )
51
51
assert .True (mt , sessionIDsEqual (mt , want , got ), "expected session ID %v, got %v" , want , got )
52
52
})
53
+ mt .Run ("last use time updated" , func (mt * mtest.T ) {
54
+ sess , err := mt .Client .StartSession ()
55
+ assert .Nil (mt , err , "StartSession error: %v" , err )
56
+ defer sess .EndSession (mtest .Background )
57
+ initialLastUsedTime := getSessionLastUsedTime (mt , sess )
58
+
59
+ err = mongo .WithSession (mtest .Background , sess , func (sc mongo.SessionContext ) error {
60
+ return mt .Client .Ping (sc , readpref .Primary ())
61
+ })
62
+ assert .Nil (mt , err , "WithSession error: %v" , err )
63
+
64
+ newLastUsedTime := getSessionLastUsedTime (mt , sess )
65
+ assert .True (mt , newLastUsedTime .After (initialLastUsedTime ),
66
+ "last used time %s is not after the initial last used time %s" , newLastUsedTime , initialLastUsedTime )
67
+ })
53
68
}
54
69
55
70
func TestSessions (t * testing.T ) {
@@ -363,3 +378,9 @@ func extractSentSessionID(mt *mtest.T) []byte {
363
378
_ , data := lsid .Document ().Lookup ("id" ).Binary ()
364
379
return data
365
380
}
381
+
382
+ func getSessionLastUsedTime (mt * mtest.T , sess mongo.Session ) time.Time {
383
+ xsess , ok := sess .(mongo.XSession )
384
+ assert .True (mt , ok , "expected session to implement mongo.XSession, but got %T" , sess )
385
+ return xsess .ClientSession ().LastUsed
386
+ }
0 commit comments