Skip to content

Commit 9ce96e8

Browse files
committed
Make pool monitor tests more reliable on Windows.
1 parent d6e10d3 commit 9ce96e8

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

x/mongo/driver/topology/pool_test.go

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"go.mongodb.org/mongo-driver/internal/eventtest"
2020
"go.mongodb.org/mongo-driver/internal/require"
2121
"go.mongodb.org/mongo-driver/mongo/address"
22+
"go.mongodb.org/mongo-driver/x/mongo/driver"
2223
"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
2324
)
2425

@@ -1178,10 +1179,22 @@ func TestPool_PoolMonitor(t *testing.T) {
11781179
})
11791180

11801181
tpm := eventtest.NewTestPoolMonitor()
1181-
p := newPool(poolConfig{
1182-
Address: address.Address(addr.String()),
1183-
PoolMonitor: tpm.PoolMonitor,
1184-
})
1182+
p := newPool(
1183+
poolConfig{
1184+
Address: address.Address(addr.String()),
1185+
PoolMonitor: tpm.PoolMonitor,
1186+
},
1187+
// Add a 10ms delay in the handshake so the test is reliable on
1188+
// operating systems that can't measure very short durations (e.g.
1189+
// Windows).
1190+
WithHandshaker(func(Handshaker) Handshaker {
1191+
return &testHandshaker{
1192+
getHandshakeInformation: func(context.Context, address.Address, driver.Connection) (driver.HandshakeInformation, error) {
1193+
time.Sleep(10 * time.Millisecond)
1194+
return driver.HandshakeInformation{}, nil
1195+
},
1196+
}
1197+
}))
11851198

11861199
err := p.ready()
11871200
require.NoError(t, err, "ready error")

0 commit comments

Comments
 (0)