@@ -15,6 +15,7 @@ import (
15
15
16
16
"go.mongodb.org/mongo-driver/bson"
17
17
"go.mongodb.org/mongo-driver/internal/assert"
18
+ "go.mongodb.org/mongo-driver/internal/require"
18
19
"go.mongodb.org/mongo-driver/mongo"
19
20
"go.mongodb.org/mongo-driver/mongo/integration/mtest"
20
21
"go.mongodb.org/mongo-driver/mongo/options"
@@ -99,5 +100,33 @@ func TestLoadBalancerSupport(t *testing.T) {
99
100
_ , err := mt .Coll .InsertOne (ctx , bson.M {"x" : 1 })
100
101
assertErrorHasInfo (mt , err , 0 , 1 , 0 )
101
102
})
103
+
104
+ // GODRIVER-2867: Test that connections are unpinned from transactions
105
+ // when the transaction session is ended. Create a Client with
106
+ // maxPoolSize=1 and expect that it can start and commit 5 transactions
107
+ // with that 1 connection.
108
+ mt .RunOpts ("transaction connections are unpinned" , maxPoolSizeMtOpts , func (mt * mtest.T ) {
109
+ {
110
+ ctx , cancel := context .WithTimeout (context .Background (), 1 * time .Minute )
111
+ defer cancel ()
112
+
113
+ for i := 0 ; i < 5 ; i ++ {
114
+ sess , err := mt .Client .StartSession ()
115
+ require .NoError (mt , err , "StartSession error" )
116
+
117
+ err = sess .StartTransaction ()
118
+ require .NoError (mt , err , "StartTransaction error" )
119
+
120
+ ctx := mongo .NewSessionContext (ctx , sess )
121
+ _ , err = mt .Coll .InsertOne (ctx , bson.M {"x" : 1 })
122
+ assert .NoError (mt , err , "InsertOne error" )
123
+
124
+ err = sess .CommitTransaction (ctx )
125
+ assert .NoError (mt , err , "CommitTransaction error" )
126
+
127
+ sess .EndSession (ctx )
128
+ }
129
+ }
130
+ })
102
131
})
103
132
}
0 commit comments