@@ -21,6 +21,7 @@ import (
21
21
"go.mongodb.org/mongo-driver/v2/internal/eventtest"
22
22
"go.mongodb.org/mongo-driver/v2/internal/require"
23
23
"go.mongodb.org/mongo-driver/v2/mongo/address"
24
+ "go.mongodb.org/mongo-driver/v2/x/mongo/driver"
24
25
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation"
25
26
)
26
27
@@ -1584,3 +1585,26 @@ func TestPool_PoolMonitor(t *testing.T) {
1584
1585
"expected ConnectionCheckOutFailed Duration to be set" )
1585
1586
})
1586
1587
}
1588
+
1589
+ func TestPool_Error (t * testing.T ) {
1590
+ t .Parallel ()
1591
+
1592
+ t .Run ("should have TransientTransactionError" , func (t * testing.T ) {
1593
+ t .Parallel ()
1594
+
1595
+ p := newPool (poolConfig {})
1596
+ assert .Equalf (t , poolPaused , p .getState (), "expected new pool to be paused" )
1597
+
1598
+ // Since new pool is paused, checkout should throw PoolClearedError.
1599
+ _ , err := p .checkOut (context .Background ())
1600
+ var le driver.Error
1601
+ if errors .As (err , & le ) {
1602
+ assert .ErrorIs (t , poolClearedError {}, le .Unwrap (), "expect error to be PoolClearedError" )
1603
+ assert .True (t , le .HasErrorLabel (driver .TransientTransactionError ), `expected error to include the "TransientTransactionError" label` )
1604
+ } else {
1605
+ t .Errorf ("expected labeled error, got %v" , err )
1606
+ }
1607
+
1608
+ p .close (context .Background ())
1609
+ })
1610
+ }
0 commit comments