From 9ce96e806e9d1ec3f2ef687fa33f1817457ff87e Mon Sep 17 00:00:00 2001 From: Matt Dale <9760375+matthewdale@users.noreply.github.com> Date: Mon, 8 Apr 2024 18:38:38 -0700 Subject: [PATCH] Make pool monitor tests more reliable on Windows. --- x/mongo/driver/topology/pool_test.go | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/x/mongo/driver/topology/pool_test.go b/x/mongo/driver/topology/pool_test.go index ab7b38d956..bc7115ee2c 100644 --- a/x/mongo/driver/topology/pool_test.go +++ b/x/mongo/driver/topology/pool_test.go @@ -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" ) @@ -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")