@@ -10,6 +10,7 @@ import (
10
10
"context"
11
11
"net"
12
12
"testing"
13
+ "time"
13
14
14
15
"github.com/mongodb/mongo-go-driver/x/mongo/driver/topology"
15
16
"github.com/mongodb/mongo-go-driver/x/network/connection"
@@ -85,6 +86,40 @@ func TestTopologyTopology(t *testing.T) {
85
86
d .lenclosed (), d .lenopened ())
86
87
}
87
88
})
89
+ t .Run ("can disconnect from hung server" , func (t * testing.T ) {
90
+ bctx , cancel := context .WithCancel (context .Background ())
91
+ defer cancel ()
92
+ start := make (chan struct {}, 1 )
93
+ addr := bootstrapConnections (t , 5 , func (_ net.Conn ) {
94
+ start <- struct {}{}
95
+ <- bctx .Done ()
96
+ })
97
+ topo , err := topology .New (
98
+ topology .WithConnString (
99
+ func (connstring.ConnString ) connstring.ConnString {
100
+ cs , err := connstring .Parse ("mongodb://" + addr .String () + "/" )
101
+ noerr (t , err )
102
+ cs .ConnectTimeout = 20 * time .Millisecond
103
+ return cs
104
+ },
105
+ ),
106
+ )
107
+ noerr (t , err )
108
+ err = topo .Connect (context .TODO ())
109
+ noerr (t , err )
110
+ <- start
111
+ done := make (chan struct {}, 1 )
112
+ go func () {
113
+ err := topo .Disconnect (bctx )
114
+ noerr (t , err )
115
+ done <- struct {}{}
116
+ }()
117
+ select {
118
+ case <- done :
119
+ case <- time .After (300 * time .Millisecond ):
120
+ t .Error ("Could not disconnect a topology within required timelimit" )
121
+ }
122
+ })
88
123
})
89
124
t .Run ("Connect" , func (t * testing.T ) {
90
125
t .Run ("can reconnect a disconnected topology" , func (t * testing.T ) {
0 commit comments