Skip to content

Commit

Permalink
Make pool monitor tests more reliable on Windows.
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewdale committed Apr 9, 2024
1 parent d6e10d3 commit 9ce96e8
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions x/mongo/driver/topology/pool_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"go.mongodb.org/mongo-driver/internal/eventtest"
"go.mongodb.org/mongo-driver/internal/require"
"go.mongodb.org/mongo-driver/mongo/address"
"go.mongodb.org/mongo-driver/x/mongo/driver"
"go.mongodb.org/mongo-driver/x/mongo/driver/operation"
)

Expand Down Expand Up @@ -1178,10 +1179,22 @@ func TestPool_PoolMonitor(t *testing.T) {
})

tpm := eventtest.NewTestPoolMonitor()
p := newPool(poolConfig{
Address: address.Address(addr.String()),
PoolMonitor: tpm.PoolMonitor,
})
p := newPool(
poolConfig{
Address: address.Address(addr.String()),
PoolMonitor: tpm.PoolMonitor,
},
// Add a 10ms delay in the handshake so the test is reliable on
// operating systems that can't measure very short durations (e.g.
// Windows).
WithHandshaker(func(Handshaker) Handshaker {
return &testHandshaker{
getHandshakeInformation: func(context.Context, address.Address, driver.Connection) (driver.HandshakeInformation, error) {
time.Sleep(10 * time.Millisecond)
return driver.HandshakeInformation{}, nil
},
}
}))

err := p.ready()
require.NoError(t, err, "ready error")
Expand Down

0 comments on commit 9ce96e8

Please sign in to comment.