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