From bb51db3ff6fc4e9341d158a66191817ed177cb71 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Thu, 29 Aug 2024 19:28:52 -0600 Subject: [PATCH 01/24] GODRIVER-3322 Apply client-level timeout to UploadFromStreamWithID --- internal/integration/csot_prose_test.go | 118 ++++++++++++++++++++++++ mongo/gridfs_bucket.go | 3 + 2 files changed, 121 insertions(+) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 28dcef7015..40d12dfda1 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -7,6 +7,7 @@ package integration import ( + "bytes" "context" "strings" "testing" @@ -83,6 +84,123 @@ func TestCSOTProse(t *testing.T) { assert.Equal(mt, started[1].CommandName, "insert", "expected a second insert event, got %v", started[1].CommandName) }) + + mt.RunOpts("6. gridfs - upload", mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { + // Drop and re-create the db.fs.files and db.fs.chunks collections. + err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) + assert.NoError(t, err, "failed to drop files") + + err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) + assert.NoError(t, err, "failed to drop chunks") + + // Set a blocking "insert" fail point. + mt.SetFailPoint(mtest.FailPoint{ + ConfigureFailPoint: "failCommand", + Mode: mtest.FailPointMode{ + Times: 1, + }, + Data: mtest.FailPointData{ + FailCommands: []string{"insert"}, + BlockConnection: true, + BlockTimeMS: 15, + }, + }) + + // Create a new MongoClient with timeoutMS=10. + cliOptions := options.Client().SetTimeout(10) + + client, err := mongo.Connect(cliOptions) + assert.NoError(t, err, "failed to connect to server") + + // Create a GridFS bucket that wraps the db database. + bucket := client.Database("db").GridFSBucket() + + // Note that UploadFromStream accounts for the following steps: + // - Call bucket.open_upload_stream() + // - Using uploadStream, upload a single 0x12 byte + // - Call uploadStream.close() to flush the stream and insert chunks + _, err = bucket.UploadFromStream(context.Background(), "filename", bytes.NewReader([]byte{0x12})) + assert.ErrorIs(t, err, context.DeadlineExceeded) + }) + + const test61 = "6.1 gridfs - upload and download with non-expiring client-level timeout" + mt.RunOpts(test61, mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { + // Drop and re-create the db.fs.files and db.fs.chunks collections. + err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) + assert.NoError(t, err, "failed to drop files") + + err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) + assert.NoError(t, err, "failed to drop chunks") + + // Create a new MongoClient with timeoutMS=10. + cliOptions := options.Client().SetTimeout(50 * time.Millisecond) + + client, err := mongo.Connect(cliOptions) + assert.NoError(t, err, "failed to connect to server") + + // Create a GridFS bucket that wraps the db database. + bucket := client.Database("db").GridFSBucket() + + // Upload file and ensure it uploaded correctly. + fileID, err := bucket.UploadFromStream(context.Background(), "filename", bytes.NewReader([]byte{0x12})) + assert.NoError(t, err, "failed to upload stream") + + buf := bytes.Buffer{} + + _, err = bucket.DownloadToStream(context.Background(), fileID, &buf) + assert.NoError(t, err, "failed to download stream") + assert.Equal(t, buf.Len(), 1) + assert.Equal(t, buf.Bytes(), []byte{0x12}) + }) + + const test62 = "6.2 gridfs - upload with operation-level timeout" + mt.RunOpts(test62, mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { + // Drop and re-create the db.fs.files and db.fs.chunks collections. + err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) + assert.NoError(t, err, "failed to drop files") + + err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) + assert.NoError(t, err, "failed to drop chunks") + + // Set a blocking "insert" fail point. + mt.SetFailPoint(mtest.FailPoint{ + ConfigureFailPoint: "failCommand", + Mode: mtest.FailPointMode{ + Times: 1, + }, + Data: mtest.FailPointData{ + FailCommands: []string{"insert"}, + BlockConnection: true, + BlockTimeMS: 15, + }, + }) + + // Create a new MongoClient with timeoutMS=10. + cliOptions := options.Client().SetTimeout(10 * time.Second) + + client, err := mongo.Connect(cliOptions) + assert.NoError(t, err, "failed to connect to server") + + // Create a GridFS bucket that wraps the db database. + bucket := client.Database("db").GridFSBucket() + + // If the operation-level context is not respected, then the client-level + // timeout will exceed deadline. + ctx, cancel := context.WithTimeout(context.Background(), 75*time.Millisecond) + defer cancel() + + // Upload file and ensure it uploaded correctly. + fileID, err := bucket.UploadFromStream(ctx, "filename", bytes.NewReader([]byte{0x12})) + assert.NoError(t, err, "failed to upload stream") + + buf := bytes.Buffer{} + + _, err = bucket.DownloadToStream(ctx, fileID, &buf) + assert.NoError(t, err, "failed to download stream") + assert.Equal(t, buf.Len(), 1) + assert.Equal(t, buf.Bytes(), []byte{0x12}) + }) + mt.Run("8. server selection", func(mt *mtest.T) { cliOpts := options.Client().ApplyURI("mongodb://invalid/?serverSelectionTimeoutMS=100") mtOpts := mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) diff --git a/mongo/gridfs_bucket.go b/mongo/gridfs_bucket.go index 65fd7bc29b..0ab92815a2 100644 --- a/mongo/gridfs_bucket.go +++ b/mongo/gridfs_bucket.go @@ -135,6 +135,9 @@ func (b *GridFSBucket) UploadFromStreamWithID( source io.Reader, opts ...options.Lister[options.GridFSUploadOptions], ) error { + ctx, cancel := csot.WithTimeout(ctx, b.db.client.timeout) + defer cancel() + us, err := b.OpenUploadStreamWithID(ctx, fileID, filename, opts...) if err != nil { return err From b8a04d98167beb4e793233e8388fb4f798dcdb14 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Thu, 29 Aug 2024 20:21:54 -0600 Subject: [PATCH 02/24] GODRIVER-3322 Add cluster URI --- internal/integration/csot_prose_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 40d12dfda1..77d725802a 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -107,7 +107,8 @@ func TestCSOTProse(t *testing.T) { }) // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(10) + cliOptions := options.Client().SetTimeout(10).ApplyURI(mtest.ClusterURI()) + integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) assert.NoError(t, err, "failed to connect to server") @@ -133,7 +134,8 @@ func TestCSOTProse(t *testing.T) { assert.NoError(t, err, "failed to drop chunks") // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(50 * time.Millisecond) + cliOptions := options.Client().SetTimeout(50 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) assert.NoError(t, err, "failed to connect to server") @@ -176,7 +178,8 @@ func TestCSOTProse(t *testing.T) { }) // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(10 * time.Second) + cliOptions := options.Client().SetTimeout(10 * time.Second).ApplyURI(mtest.ClusterURI()) + integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) assert.NoError(t, err, "failed to connect to server") From 3ad5a922efaa9ec302c4df333ff713fdbf361553 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Thu, 29 Aug 2024 21:43:51 -0600 Subject: [PATCH 03/24] GODRIVER-3322 Add cluster URI --- internal/integration/csot_prose_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 77d725802a..688936c8d0 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -134,7 +134,7 @@ func TestCSOTProse(t *testing.T) { assert.NoError(t, err, "failed to drop chunks") // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(50 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(100 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) @@ -189,7 +189,7 @@ func TestCSOTProse(t *testing.T) { // If the operation-level context is not respected, then the client-level // timeout will exceed deadline. - ctx, cancel := context.WithTimeout(context.Background(), 75*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) defer cancel() // Upload file and ensure it uploaded correctly. From 420420edbb635481416fcda34760c95daf68f66b Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Thu, 29 Aug 2024 22:12:12 -0600 Subject: [PATCH 04/24] GODRIVER-3322 Incease timeouts --- internal/integration/csot_prose_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 688936c8d0..0abe5801a9 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -134,7 +134,7 @@ func TestCSOTProse(t *testing.T) { assert.NoError(t, err, "failed to drop chunks") // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(100 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(500 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) @@ -189,7 +189,7 @@ func TestCSOTProse(t *testing.T) { // If the operation-level context is not respected, then the client-level // timeout will exceed deadline. - ctx, cancel := context.WithTimeout(context.Background(), 100*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) defer cancel() // Upload file and ensure it uploaded correctly. From 403ad7b9c9ba9a10ba6581af946442fa8a91e7a7 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 30 Aug 2024 18:43:22 -0600 Subject: [PATCH 05/24] GODRIVER-3322 Refactor context cancelation to close --- internal/integration/csot_prose_test.go | 177 +++++++++++++++++++----- mongo/gridfs_bucket.go | 8 +- mongo/gridfs_download_stream.go | 16 ++- mongo/gridfs_upload_stream.go | 15 ++ 4 files changed, 175 insertions(+), 41 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 0abe5801a9..35d5500f3e 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -18,6 +18,7 @@ import ( "go.mongodb.org/mongo-driver/v2/internal/assert" "go.mongodb.org/mongo-driver/v2/internal/integration/mtest" "go.mongodb.org/mongo-driver/v2/internal/integtest" + "go.mongodb.org/mongo-driver/v2/internal/require" "go.mongodb.org/mongo-driver/v2/mongo" "go.mongodb.org/mongo-driver/v2/mongo/options" ) @@ -88,10 +89,10 @@ func TestCSOTProse(t *testing.T) { mt.RunOpts("6. gridfs - upload", mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { // Drop and re-create the db.fs.files and db.fs.chunks collections. err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) - assert.NoError(t, err, "failed to drop files") + assert.NoError(mt, err, "failed to drop files") err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) - assert.NoError(t, err, "failed to drop chunks") + assert.NoError(mt, err, "failed to drop chunks") // Set a blocking "insert" fail point. mt.SetFailPoint(mtest.FailPoint{ @@ -102,57 +103,80 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 15, + BlockTimeMS: 150, }, }) // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(10).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(100 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) - assert.NoError(t, err, "failed to connect to server") + assert.NoError(mt, err, "failed to connect to server") // Create a GridFS bucket that wraps the db database. bucket := client.Database("db").GridFSBucket() - // Note that UploadFromStream accounts for the following steps: - // - Call bucket.open_upload_stream() - // - Using uploadStream, upload a single 0x12 byte - // - Call uploadStream.close() to flush the stream and insert chunks - _, err = bucket.UploadFromStream(context.Background(), "filename", bytes.NewReader([]byte{0x12})) - assert.ErrorIs(t, err, context.DeadlineExceeded) + uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename") + require.NoError(mt, err) + + _, err = uploadStream.Write([]byte{0x12}) + require.NoError(mt, err) + + err = uploadStream.Close() + assert.Error(t, err, context.DeadlineExceeded) }) const test61 = "6.1 gridfs - upload and download with non-expiring client-level timeout" mt.RunOpts(test61, mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { // Drop and re-create the db.fs.files and db.fs.chunks collections. err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) - assert.NoError(t, err, "failed to drop files") + assert.NoError(mt, err, "failed to drop files") err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) - assert.NoError(t, err, "failed to drop chunks") + assert.NoError(mt, err, "failed to drop chunks") // Create a new MongoClient with timeoutMS=10. cliOptions := options.Client().SetTimeout(500 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) - assert.NoError(t, err, "failed to connect to server") + assert.NoError(mt, err, "failed to connect to server") // Create a GridFS bucket that wraps the db database. bucket := client.Database("db").GridFSBucket() - // Upload file and ensure it uploaded correctly. - fileID, err := bucket.UploadFromStream(context.Background(), "filename", bytes.NewReader([]byte{0x12})) - assert.NoError(t, err, "failed to upload stream") + mt.Run("UploadFromStream", func(mt *mtest.T) { + // Upload file and ensure it uploaded correctly. + fileID, err := bucket.UploadFromStream(context.Background(), "filename", bytes.NewReader([]byte{0x12})) + assert.NoError(mt, err, "failed to upload stream") + + buf := bytes.Buffer{} + + _, err = bucket.DownloadToStream(context.Background(), fileID, &buf) + assert.NoError(mt, err, "failed to download stream") + assert.Equal(mt, buf.Len(), 1) + assert.Equal(mt, buf.Bytes(), []byte{0x12}) + }) + + mt.Run("OpenUploadStream", func(mt *mtest.T) { + // Upload file and ensure it uploaded correctly. + uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename2") + require.NoError(mt, err, "failed to open upload stream") + + _, err = uploadStream.Write([]byte{0x13}) + require.NoError(mt, err, "failed to write data to upload stream") + + err = uploadStream.Close() + require.NoError(mt, err, "failed to close upload stream") - buf := bytes.Buffer{} + buf := bytes.Buffer{} - _, err = bucket.DownloadToStream(context.Background(), fileID, &buf) - assert.NoError(t, err, "failed to download stream") - assert.Equal(t, buf.Len(), 1) - assert.Equal(t, buf.Bytes(), []byte{0x12}) + _, err = bucket.DownloadToStream(context.Background(), uploadStream.FileID, &buf) + assert.NoError(mt, err, "failed to download stream") + assert.Equal(mt, buf.Len(), 1) + assert.Equal(mt, buf.Bytes(), []byte{0x13}) + }) }) const test62 = "6.2 gridfs - upload with operation-level timeout" @@ -182,26 +206,109 @@ func TestCSOTProse(t *testing.T) { integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) - assert.NoError(t, err, "failed to connect to server") + assert.NoError(mt, err, "failed to connect to server") + + // Create a GridFS bucket that wraps the db database. + bucket := client.Database("db").GridFSBucket() + + mt.Run("UploadFromStream", func(mt *mtest.T) { + + // If the operation-level context is not respected, then the client-level + // timeout will exceed deadline. + ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) + defer cancel() + + // Upload file and ensure it uploaded correctly. + fileID, err := bucket.UploadFromStream(ctx, "filename", bytes.NewReader([]byte{0x12})) + require.NoError(mt, err, "failed to upload stream") + + buf := bytes.Buffer{} + + _, err = bucket.DownloadToStream(context.Background(), fileID, &buf) + assert.NoError(mt, err, "failed to download stream") + assert.Equal(mt, buf.Len(), 1) + assert.Equal(mt, buf.Bytes(), []byte{0x12}) + }) + + mt.Run("OpenUploadStream", func(mt *mtest.T) { + // If the operation-level context is not respected, then the client-level + // timeout will exceed deadline. + ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) + defer cancel() + + // Upload file and ensure it uploaded correctly. + uploadStream, err := bucket.OpenUploadStream(ctx, "filename2") + require.NoError(mt, err, "failed to open upload stream") + + _, err = uploadStream.Write([]byte{0x13}) + require.NoError(mt, err, "failed to write data to upload stream") + + err = uploadStream.Close() + require.NoError(mt, err, "failed to close upload stream") + + buf := bytes.Buffer{} + + _, err = bucket.DownloadToStream(context.Background(), uploadStream.FileID, &buf) + assert.NoError(mt, err, "failed to download stream") + assert.Equal(mt, buf.Len(), 1) + assert.Equal(mt, buf.Bytes(), []byte{0x13}) + }) + }) + + const test63 = "6.3 gridfs - cancel context mid-stream" + mt.RunOpts(test63, mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { + // Drop and re-create the db.fs.files and db.fs.chunks collections. + err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) + assert.NoError(t, err, "failed to drop files") + + err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) + assert.NoError(t, err, "failed to drop chunks") + + // Create a new MongoClient with timeoutMS=10. + cliOptions := options.Client().ApplyURI(mtest.ClusterURI()) + integtest.AddTestServerAPIVersion(cliOptions) + + client, err := mongo.Connect(cliOptions) + assert.NoError(mt, err, "failed to connect to server") // Create a GridFS bucket that wraps the db database. bucket := client.Database("db").GridFSBucket() - // If the operation-level context is not respected, then the client-level - // timeout will exceed deadline. - ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) - defer cancel() + mt.Run("Upload#Close", func(mt *mtest.T) { + // Upload file and ensure it uploaded correctly. + uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename") + require.NoError(mt, err) + + _ = uploadStream.Close() + + _, err = uploadStream.Write([]byte{0x13}) + assert.Error(t, err, context.Canceled) + }) - // Upload file and ensure it uploaded correctly. - fileID, err := bucket.UploadFromStream(ctx, "filename", bytes.NewReader([]byte{0x12})) - assert.NoError(t, err, "failed to upload stream") + mt.Run("Upload#Abort", func(mt *mtest.T) { + // Upload file and ensure it uploaded correctly. + uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename2") + require.NoError(mt, err) - buf := bytes.Buffer{} + _ = uploadStream.Abort() - _, err = bucket.DownloadToStream(ctx, fileID, &buf) - assert.NoError(t, err, "failed to download stream") - assert.Equal(t, buf.Len(), 1) - assert.Equal(t, buf.Bytes(), []byte{0x12}) + _, err = uploadStream.Write([]byte{0x13}) + assert.Error(t, err, context.Canceled) + }) + + mt.Run("Download#Close", func(mt *mtest.T) { + // Upload file and ensure it uploaded correctly. + fileID, err := bucket.UploadFromStream(context.Background(), "filename3", bytes.NewReader([]byte{0x12})) + require.NoError(mt, err, "failed to upload stream") + + downloadStream, err := bucket.OpenDownloadStream(context.Background(), fileID) + assert.NoError(t, err) + + _ = downloadStream.Close() + + _, err = downloadStream.Read([]byte{}) + assert.Error(t, err, context.Canceled) + }) }) mt.Run("8. server selection", func(mt *mtest.T) { diff --git a/mongo/gridfs_bucket.go b/mongo/gridfs_bucket.go index 0ab92815a2..8bb418ad18 100644 --- a/mongo/gridfs_bucket.go +++ b/mongo/gridfs_bucket.go @@ -85,7 +85,6 @@ func (b *GridFSBucket) OpenUploadStreamWithID( opts ...options.Lister[options.GridFSUploadOptions], ) (*GridFSUploadStream, error) { ctx, cancel := csot.WithTimeout(ctx, b.db.client.timeout) - defer cancel() if err := b.checkFirstWrite(ctx); err != nil { return nil, err @@ -96,7 +95,7 @@ func (b *GridFSBucket) OpenUploadStreamWithID( return nil, err } - return newUploadStream(ctx, upload, fileID, filename, b.chunksColl, b.filesColl), nil + return newUploadStream(ctx, cancel, upload, fileID, filename, b.chunksColl, b.filesColl), nil } // UploadFromStream creates a fileID and uploads a file given a source stream. @@ -353,7 +352,6 @@ func (b *GridFSBucket) openDownloadStream( opts ...options.Lister[options.FindOneOptions], ) (*GridFSDownloadStream, error) { ctx, cancel := csot.WithTimeout(ctx, b.db.client.timeout) - defer cancel() result := b.filesColl.FindOne(ctx, filter, opts...) @@ -372,7 +370,7 @@ func (b *GridFSBucket) openDownloadStream( foundFile := newFileFromResponse(resp) if foundFile.Length == 0 { - return newGridFSDownloadStream(ctx, nil, foundFile.ChunkSize, foundFile), nil + return newGridFSDownloadStream(ctx, cancel, nil, foundFile.ChunkSize, foundFile), nil } // For a file with non-zero length, chunkSize must exist so we know what size to expect when downloading chunks. @@ -387,7 +385,7 @@ func (b *GridFSBucket) openDownloadStream( // The chunk size can be overridden for individual files, so the expected chunk size should be the "chunkSize" // field from the files collection document, not the bucket's chunk size. - return newGridFSDownloadStream(ctx, chunksCursor, foundFile.ChunkSize, foundFile), nil + return newGridFSDownloadStream(ctx, cancel, chunksCursor, foundFile.ChunkSize, foundFile), nil } func (b *GridFSBucket) downloadToStream(ds *GridFSDownloadStream, stream io.Writer) (int64, error) { diff --git a/mongo/gridfs_download_stream.go b/mongo/gridfs_download_stream.go index f33515fe57..1cc9bf65fd 100644 --- a/mongo/gridfs_download_stream.go +++ b/mongo/gridfs_download_stream.go @@ -39,6 +39,7 @@ type GridFSDownloadStream struct { expectedChunk int32 // index of next expected chunk fileLen int64 ctx context.Context + cancel context.CancelFunc // The pointer returned by GetFile. This should not be used in the actual GridFSDownloadStream code outside of the // newGridFSDownloadStream constructor because the values can be mutated by the user after calling GetFile. Instead, @@ -95,7 +96,13 @@ func newFileFromResponse(resp findFileResponse) *GridFSFile { } } -func newGridFSDownloadStream(ctx context.Context, cursor *Cursor, chunkSize int32, file *GridFSFile) *GridFSDownloadStream { +func newGridFSDownloadStream( + ctx context.Context, + cancel context.CancelFunc, + cursor *Cursor, + chunkSize int32, + file *GridFSFile, +) *GridFSDownloadStream { numChunks := int32(math.Ceil(float64(file.Length) / float64(chunkSize))) return &GridFSDownloadStream{ @@ -107,11 +114,18 @@ func newGridFSDownloadStream(ctx context.Context, cursor *Cursor, chunkSize int3 fileLen: file.Length, file: file, ctx: ctx, + cancel: cancel, } } // Close closes this download stream. func (ds *GridFSDownloadStream) Close() error { + defer func() { + if ds.cancel != nil { + ds.cancel() + } + }() + if ds.closed { return ErrStreamClosed } diff --git a/mongo/gridfs_upload_stream.go b/mongo/gridfs_upload_stream.go index 4d0cc5d304..c1f9277412 100644 --- a/mongo/gridfs_upload_stream.go +++ b/mongo/gridfs_upload_stream.go @@ -40,11 +40,13 @@ type GridFSUploadStream struct { bufferIndex int fileLen int64 ctx context.Context + cancel context.CancelFunc } // NewUploadStream creates a new upload stream. func newUploadStream( ctx context.Context, + cancel context.CancelFunc, up *upload, fileID interface{}, filename string, @@ -59,11 +61,18 @@ func newUploadStream( filesColl: files, buffer: make([]byte, uploadBufferSize), ctx: ctx, + cancel: cancel, } } // Close writes file metadata to the files collection and cleans up any resources associated with the UploadStream. func (us *GridFSUploadStream) Close() error { + defer func() { + if us.cancel != nil { + us.cancel() + } + }() + if us.closed { return ErrStreamClosed } @@ -111,6 +120,12 @@ func (us *GridFSUploadStream) Write(p []byte) (int, error) { // Abort closes the stream and deletes all file chunks that have already been written. func (us *GridFSUploadStream) Abort() error { + defer func() { + if us.cancel != nil { + us.cancel() + } + }() + if us.closed { return ErrStreamClosed } From 411d63507e0cd6fb4be43f1fc404cd96b5164c1c Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 30 Aug 2024 18:45:31 -0600 Subject: [PATCH 06/24] GODRIVER-3322 Update time from S to MS --- internal/integration/csot_prose_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 35d5500f3e..3ed3c1c50f 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -202,7 +202,7 @@ func TestCSOTProse(t *testing.T) { }) // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(10 * time.Second).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(10 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) From 5e316f982bbe9730316f57778f452f976a9c22db Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 30 Aug 2024 18:48:13 -0600 Subject: [PATCH 07/24] GODRIVER-3322 Lower from 500 to 10 ms --- internal/integration/csot_prose_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 3ed3c1c50f..145b7eb531 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -137,7 +137,7 @@ func TestCSOTProse(t *testing.T) { assert.NoError(mt, err, "failed to drop chunks") // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(500 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(10 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) From 40f5d474cd963e102822195be888678b02332f97 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 30 Aug 2024 18:59:56 -0600 Subject: [PATCH 08/24] GODRIVER-3322 allow more time for client-specific tests --- internal/integration/csot_prose_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 145b7eb531..c41f4b45b9 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -136,8 +136,8 @@ func TestCSOTProse(t *testing.T) { err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) assert.NoError(mt, err, "failed to drop chunks") - // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(10 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + // Create a new MongoClient with timeoutMS=500. + cliOptions := options.Client().SetTimeout(500 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) From 401fb074f941152c2de91ae259f32ae241c3567b Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 30 Aug 2024 19:03:53 -0600 Subject: [PATCH 09/24] GODRIVER-3322 Update t to mt --- internal/integration/csot_prose_test.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index c41f4b45b9..fe4681061b 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -183,10 +183,10 @@ func TestCSOTProse(t *testing.T) { mt.RunOpts(test62, mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { // Drop and re-create the db.fs.files and db.fs.chunks collections. err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) - assert.NoError(t, err, "failed to drop files") + assert.NoError(mt, err, "failed to drop files") err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) - assert.NoError(t, err, "failed to drop chunks") + assert.NoError(mt, err, "failed to drop chunks") // Set a blocking "insert" fail point. mt.SetFailPoint(mtest.FailPoint{ @@ -259,10 +259,10 @@ func TestCSOTProse(t *testing.T) { mt.RunOpts(test63, mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { // Drop and re-create the db.fs.files and db.fs.chunks collections. err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) - assert.NoError(t, err, "failed to drop files") + assert.NoError(mt, err, "failed to drop files") err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) - assert.NoError(t, err, "failed to drop chunks") + assert.NoError(mt, err, "failed to drop chunks") // Create a new MongoClient with timeoutMS=10. cliOptions := options.Client().ApplyURI(mtest.ClusterURI()) @@ -282,7 +282,7 @@ func TestCSOTProse(t *testing.T) { _ = uploadStream.Close() _, err = uploadStream.Write([]byte{0x13}) - assert.Error(t, err, context.Canceled) + assert.Error(mt, err, context.Canceled) }) mt.Run("Upload#Abort", func(mt *mtest.T) { @@ -293,7 +293,7 @@ func TestCSOTProse(t *testing.T) { _ = uploadStream.Abort() _, err = uploadStream.Write([]byte{0x13}) - assert.Error(t, err, context.Canceled) + assert.Error(mt, err, context.Canceled) }) mt.Run("Download#Close", func(mt *mtest.T) { @@ -302,12 +302,12 @@ func TestCSOTProse(t *testing.T) { require.NoError(mt, err, "failed to upload stream") downloadStream, err := bucket.OpenDownloadStream(context.Background(), fileID) - assert.NoError(t, err) + assert.NoError(mt, err) _ = downloadStream.Close() _, err = downloadStream.Read([]byte{}) - assert.Error(t, err, context.Canceled) + assert.Error(mt, err, context.Canceled) }) }) From a444deb4af8ac24f73266f3c6a333c55cdff117d Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 30 Aug 2024 22:49:00 -0600 Subject: [PATCH 10/24] GODRIVER-3322 Revert timeouts back to prose --- internal/integration/csot_prose_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index fe4681061b..15adbbf4f1 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -103,12 +103,12 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 150, + BlockTimeMS: 15, }, }) // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(100 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(10 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) From b879cb10116069f29ba3e04fd362b5cfada2ae92 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 30 Aug 2024 23:19:47 -0600 Subject: [PATCH 11/24] GODRIVER-3322 Revert timeouts back to prose --- internal/integration/csot_prose_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 15adbbf4f1..ffdfd694de 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -103,12 +103,12 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 15, + BlockTimeMS: 250, }, }) // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(10 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(200 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) From 24a80e5a11c00f9ceefa1575a84db9be9c4c4c08 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Tue, 3 Sep 2024 09:09:07 -0600 Subject: [PATCH 12/24] GODRIVER-3322 Add abort test --- internal/integration/csot_prose_test.go | 110 +++++++++++++++++------- 1 file changed, 78 insertions(+), 32 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index ffdfd694de..55e24d37ed 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -87,44 +87,90 @@ func TestCSOTProse(t *testing.T) { }) mt.RunOpts("6. gridfs - upload", mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { - // Drop and re-create the db.fs.files and db.fs.chunks collections. - err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) - assert.NoError(mt, err, "failed to drop files") - - err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) - assert.NoError(mt, err, "failed to drop chunks") - - // Set a blocking "insert" fail point. - mt.SetFailPoint(mtest.FailPoint{ - ConfigureFailPoint: "failCommand", - Mode: mtest.FailPointMode{ - Times: 1, - }, - Data: mtest.FailPointData{ - FailCommands: []string{"insert"}, - BlockConnection: true, - BlockTimeMS: 250, - }, - }) + mt.Run("uploads via openUploadStream can be timed out", func(mt *mtest.T) { + // Drop and re-create the db.fs.files and db.fs.chunks collections. + err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) + assert.NoError(mt, err, "failed to drop files") + + err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) + assert.NoError(mt, err, "failed to drop chunks") + + // Set a blocking "insert" fail point. + mt.SetFailPoint(mtest.FailPoint{ + ConfigureFailPoint: "failCommand", + Mode: mtest.FailPointMode{ + Times: 1, + }, + Data: mtest.FailPointData{ + FailCommands: []string{"insert"}, + BlockConnection: true, + BlockTimeMS: 250, + }, + }) + + // Create a new MongoClient with timeoutMS=100. + cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + integtest.AddTestServerAPIVersion(cliOptions) + + client, err := mongo.Connect(cliOptions) + assert.NoError(mt, err, "failed to connect to server") + + // Create a GridFS bucket that wraps the db database. + bucket := client.Database("db").GridFSBucket() - // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(200 * time.Millisecond).ApplyURI(mtest.ClusterURI()) - integtest.AddTestServerAPIVersion(cliOptions) + uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename") + require.NoError(mt, err, "failed to open upload stream") - client, err := mongo.Connect(cliOptions) - assert.NoError(mt, err, "failed to connect to server") + _, err = uploadStream.Write([]byte{0x12}) + require.NoError(mt, err, "failed to write to upload stream") - // Create a GridFS bucket that wraps the db database. - bucket := client.Database("db").GridFSBucket() + err = uploadStream.Close() + assert.Error(t, err, context.DeadlineExceeded) + }) - uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename") - require.NoError(mt, err) + mt.Run("Aborting an upload stream can be timed out", func(mt *mtest.T) { + // Drop and re-create the db.fs.files and db.fs.chunks collections. + err := mt.Client.Database("db").Collection("fs.files").Drop(context.Background()) + assert.NoError(mt, err, "failed to drop files") + + err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) + assert.NoError(mt, err, "failed to drop chunks") + + // Set a blocking "delete" fail point. + mt.SetFailPoint(mtest.FailPoint{ + ConfigureFailPoint: "failCommand", + Mode: mtest.FailPointMode{ + Times: 1, + }, + Data: mtest.FailPointData{ + FailCommands: []string{"delete"}, + BlockConnection: true, + BlockTimeMS: 250, + }, + }) + + // Create a new MongoClient with timeoutMS=150. + cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + integtest.AddTestServerAPIVersion(cliOptions) + + client, err := mongo.Connect(cliOptions) + assert.NoError(mt, err, "failed to connect to server") + + // Create a GridFS bucket that wraps the db database. + bucket := client.Database("db").GridFSBucket(options.GridFSBucket().SetChunkSizeBytes(2)) + + // Call bucket.open_upload_stream() with the filename filename to create + // an upload stream (referred to as uploadStream). + uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename") + require.NoError(mt, err) - _, err = uploadStream.Write([]byte{0x12}) - require.NoError(mt, err) + // Using uploadStream, upload the bytes [0x01, 0x02, 0x03, 0x04]. + _, err = uploadStream.Write([]byte{0x01, 0x02, 0x03, 0x04}) + require.NoError(mt, err) - err = uploadStream.Close() - assert.Error(t, err, context.DeadlineExceeded) + err = uploadStream.Abort() + assert.Error(t, err, context.DeadlineExceeded) + }) }) const test61 = "6.1 gridfs - upload and download with non-expiring client-level timeout" From fe97083448d5288496aaaae26770a29916b9b868 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Tue, 3 Sep 2024 09:42:24 -0600 Subject: [PATCH 13/24] GODRIVER-3322 Use large timeouts for test 6 --- internal/integration/csot_prose_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 55e24d37ed..dbd3dc128d 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -104,12 +104,12 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 250, + BlockTimeMS: 500, }, }) - // Create a new MongoClient with timeoutMS=100. - cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + // Create a new MongoClient with timeoutMS=250. + cliOptions := options.Client().SetTimeout(250 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) @@ -145,12 +145,12 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"delete"}, BlockConnection: true, - BlockTimeMS: 250, + BlockTimeMS: 500, }, }) - // Create a new MongoClient with timeoutMS=150. - cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + // Create a new MongoClient with timeoutMS=250. + cliOptions := options.Client().SetTimeout(250 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) From 9b0badb2629892efa4d5441f96fecaff8b7763c1 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Tue, 3 Sep 2024 10:24:30 -0600 Subject: [PATCH 14/24] GODRIVER-3322 Use mt over t --- internal/integration/csot_prose_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index dbd3dc128d..30c1701747 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -169,7 +169,7 @@ func TestCSOTProse(t *testing.T) { require.NoError(mt, err) err = uploadStream.Abort() - assert.Error(t, err, context.DeadlineExceeded) + assert.Error(mt, err, context.DeadlineExceeded) }) }) From b397aa22637403f362a2ca5288a1547104074ba2 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Tue, 3 Sep 2024 10:29:37 -0600 Subject: [PATCH 15/24] GODRIVER-3322 Clean up comments --- internal/integration/csot_prose_test.go | 3 --- 1 file changed, 3 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 30c1701747..0cacb339dc 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -321,7 +321,6 @@ func TestCSOTProse(t *testing.T) { bucket := client.Database("db").GridFSBucket() mt.Run("Upload#Close", func(mt *mtest.T) { - // Upload file and ensure it uploaded correctly. uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename") require.NoError(mt, err) @@ -332,7 +331,6 @@ func TestCSOTProse(t *testing.T) { }) mt.Run("Upload#Abort", func(mt *mtest.T) { - // Upload file and ensure it uploaded correctly. uploadStream, err := bucket.OpenUploadStream(context.Background(), "filename2") require.NoError(mt, err) @@ -343,7 +341,6 @@ func TestCSOTProse(t *testing.T) { }) mt.Run("Download#Close", func(mt *mtest.T) { - // Upload file and ensure it uploaded correctly. fileID, err := bucket.UploadFromStream(context.Background(), "filename3", bytes.NewReader([]byte{0x12})) require.NoError(mt, err, "failed to upload stream") From ee199ea8fd120acd02cc910c42656ab7fe9df1a8 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Tue, 3 Sep 2024 20:20:13 -0600 Subject: [PATCH 16/24] GODRIVER-3322 Use only one mongos --- internal/integration/csot_prose_test.go | 46 ++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 4 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 0cacb339dc..10a517b699 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -18,6 +18,7 @@ import ( "go.mongodb.org/mongo-driver/v2/internal/assert" "go.mongodb.org/mongo-driver/v2/internal/integration/mtest" "go.mongodb.org/mongo-driver/v2/internal/integtest" + "go.mongodb.org/mongo-driver/v2/internal/mongoutil" "go.mongodb.org/mongo-driver/v2/internal/require" "go.mongodb.org/mongo-driver/v2/mongo" "go.mongodb.org/mongo-driver/v2/mongo/options" @@ -95,6 +96,14 @@ func TestCSOTProse(t *testing.T) { err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) assert.NoError(mt, err, "failed to drop chunks") + hosts, err := mongoutil.HostsFromURI(mtest.ClusterURI()) + require.NoError(mt, err) + + failpointHost := hosts[0] + + mt.ResetClient(options.Client(). + SetHosts([]string{failpointHost})) + // Set a blocking "insert" fail point. mt.SetFailPoint(mtest.FailPoint{ ConfigureFailPoint: "failCommand", @@ -104,12 +113,23 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 500, + BlockTimeMS: 1500, }, }) + // The automatic failpoint clearing may not clear failpoints set on + // specific hosts, so manually clear the failpoint we set on the specific + // mongos when the test is done. + defer func() { + mt.ResetClient(options.Client(). + SetHosts([]string{failpointHost})) + mt.ClearFailPoints() + }() + // Create a new MongoClient with timeoutMS=250. - cliOptions := options.Client().SetTimeout(250 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(1000 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + SetHosts([]string{failpointHost}) + integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) @@ -136,6 +156,14 @@ func TestCSOTProse(t *testing.T) { err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) assert.NoError(mt, err, "failed to drop chunks") + hosts, err := mongoutil.HostsFromURI(mtest.ClusterURI()) + require.NoError(mt, err) + + failpointHost := hosts[0] + + mt.ResetClient(options.Client(). + SetHosts([]string{failpointHost})) + // Set a blocking "delete" fail point. mt.SetFailPoint(mtest.FailPoint{ ConfigureFailPoint: "failCommand", @@ -145,12 +173,22 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"delete"}, BlockConnection: true, - BlockTimeMS: 500, + BlockTimeMS: 1500, }, }) + // The automatic failpoint clearing may not clear failpoints set on + // specific hosts, so manually clear the failpoint we set on the specific + // mongos when the test is done. + defer func() { + mt.ResetClient(options.Client(). + SetHosts([]string{failpointHost})) + mt.ClearFailPoints() + }() + // Create a new MongoClient with timeoutMS=250. - cliOptions := options.Client().SetTimeout(250 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(1000 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) From 632a7f7944350fa3e7c2a34025b1de4d1e95b040 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Wed, 4 Sep 2024 09:58:55 -0600 Subject: [PATCH 17/24] GODRIVER-3322 Use prose-specific timeouts --- internal/integration/csot_prose_test.go | 35 ++++++++++++++++++------- 1 file changed, 26 insertions(+), 9 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 10a517b699..09e8578018 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -113,7 +113,7 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 1500, + BlockTimeMS: 200, }, }) @@ -126,8 +126,8 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=250. - cliOptions := options.Client().SetTimeout(1000 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + // Create a new MongoClient with timeoutMS=150. + cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()). SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) @@ -173,7 +173,7 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"delete"}, BlockConnection: true, - BlockTimeMS: 1500, + BlockTimeMS: 200, }, }) @@ -186,8 +186,8 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=250. - cliOptions := options.Client().SetTimeout(1000 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + // Create a new MongoClient with timeoutMS=150. + cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()). SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) @@ -272,6 +272,14 @@ func TestCSOTProse(t *testing.T) { err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) assert.NoError(mt, err, "failed to drop chunks") + hosts, err := mongoutil.HostsFromURI(mtest.ClusterURI()) + require.NoError(mt, err) + + failpointHost := hosts[0] + + mt.ResetClient(options.Client(). + SetHosts([]string{failpointHost})) + // Set a blocking "insert" fail point. mt.SetFailPoint(mtest.FailPoint{ ConfigureFailPoint: "failCommand", @@ -281,12 +289,21 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 15, + BlockTimeMS: 200, }, }) - // Create a new MongoClient with timeoutMS=10. - cliOptions := options.Client().SetTimeout(10 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + // The automatic failpoint clearing may not clear failpoints set on + // specific hosts, so manually clear the failpoint we set on the specific + // mongos when the test is done. + defer func() { + mt.ResetClient(options.Client(). + SetHosts([]string{failpointHost})) + mt.ClearFailPoints() + }() + + // Create a new MongoClient with timeoutMS=150. + cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) From 7c38b9a397bd22ae030c533499e410ee2a0e23d5 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Wed, 4 Sep 2024 16:04:16 -0600 Subject: [PATCH 18/24] GODRIVER-3322 Raise timeout limits --- internal/integration/csot_prose_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 09e8578018..f5f27f37e3 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -113,7 +113,7 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 200, + BlockTimeMS: 250, }, }) @@ -126,8 +126,8 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=150. - cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + // Create a new MongoClient with timeoutMS=200. + cliOptions := options.Client().SetTimeout(200 * time.Millisecond).ApplyURI(mtest.ClusterURI()). SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) @@ -173,7 +173,7 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"delete"}, BlockConnection: true, - BlockTimeMS: 200, + BlockTimeMS: 250, }, }) @@ -186,8 +186,8 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=150. - cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + // Create a new MongoClient with timeoutMS=200. + cliOptions := options.Client().SetTimeout(200 * time.Millisecond).ApplyURI(mtest.ClusterURI()). SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) From 1e1787bcc3c77df37fbe2162413e223b38a47d5a Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Wed, 4 Sep 2024 16:52:11 -0600 Subject: [PATCH 19/24] GODRIVER-3322 increase timeout --- internal/integration/csot_prose_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index f5f27f37e3..081607a3e2 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -113,7 +113,7 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 250, + BlockTimeMS: 750, }, }) @@ -126,8 +126,8 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=200. - cliOptions := options.Client().SetTimeout(200 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + // Create a new MongoClient with timeoutMS=500. + cliOptions := options.Client().SetTimeout(500 * time.Millisecond).ApplyURI(mtest.ClusterURI()). SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) @@ -173,7 +173,7 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"delete"}, BlockConnection: true, - BlockTimeMS: 250, + BlockTimeMS: 750, }, }) @@ -186,8 +186,8 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=200. - cliOptions := options.Client().SetTimeout(200 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + // Create a new MongoClient with timeoutMS=500. + cliOptions := options.Client().SetTimeout(500 * time.Millisecond).ApplyURI(mtest.ClusterURI()). SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) From caa5bfd9cadabb7c38a09a008121a563d1623faa Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Wed, 4 Sep 2024 17:55:20 -0600 Subject: [PATCH 20/24] GODRIVER-3322 increase timeout --- internal/integration/csot_prose_test.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 081607a3e2..9bcfb30ebd 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -113,7 +113,7 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"insert"}, BlockConnection: true, - BlockTimeMS: 750, + BlockTimeMS: 1250, }, }) @@ -126,8 +126,8 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=500. - cliOptions := options.Client().SetTimeout(500 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + // Create a new MongoClient with timeoutMS=1000. + cliOptions := options.Client().SetTimeout(1000 * time.Millisecond).ApplyURI(mtest.ClusterURI()). SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) @@ -173,7 +173,7 @@ func TestCSOTProse(t *testing.T) { Data: mtest.FailPointData{ FailCommands: []string{"delete"}, BlockConnection: true, - BlockTimeMS: 750, + BlockTimeMS: 1250, }, }) @@ -186,8 +186,8 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=500. - cliOptions := options.Client().SetTimeout(500 * time.Millisecond).ApplyURI(mtest.ClusterURI()). + // Create a new MongoClient with timeoutMS=1000. + cliOptions := options.Client().SetTimeout(1000 * time.Millisecond).ApplyURI(mtest.ClusterURI()). SetHosts([]string{failpointHost}) integtest.AddTestServerAPIVersion(cliOptions) From bbd0a16577d4754b0dc3336049da76c82e85048e Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Thu, 5 Sep 2024 08:16:28 -0600 Subject: [PATCH 21/24] GODRIVER-3322 De-parallelize CSOT tests --- internal/integration/csot_prose_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 9bcfb30ebd..00da0e646f 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -433,7 +433,8 @@ func TestCSOTProse(t *testing.T) { cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=100&serverSelectionTimeoutMS=200") mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) mt.RunOpts("timeoutMS honored for server selection if it's lower than serverSelectionTimeoutMS", mtOpts, func(mt *mtest.T) { - mt.Parallel() + // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? + // mt.Parallel() callback := func() bool { err := mt.Client.Ping(context.Background(), nil) @@ -452,7 +453,8 @@ func TestCSOTProse(t *testing.T) { cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=200&serverSelectionTimeoutMS=100") mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) mt.RunOpts("serverSelectionTimeoutMS honored for server selection if it's lower than timeoutMS", mtOpts, func(mt *mtest.T) { - mt.Parallel() + // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? + // mt.Parallel() callback := func() bool { err := mt.Client.Ping(context.Background(), nil) @@ -471,7 +473,8 @@ func TestCSOTProse(t *testing.T) { cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=100") mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) mt.RunOpts("serverSelectionTimeoutMS honored for server selection if timeoutMS=0", mtOpts, func(mt *mtest.T) { - mt.Parallel() + // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? + // mt.Parallel() callback := func() bool { err := mt.Client.Ping(context.Background(), nil) From cf49d4a7770f706757556341fd44430efae2900a Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Thu, 5 Sep 2024 10:02:55 -0600 Subject: [PATCH 22/24] GODRIVER-3322 Increase more timeouts --- internal/integration/csot_prose_test.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 00da0e646f..aafb71f2f0 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -302,8 +302,7 @@ func TestCSOTProse(t *testing.T) { mt.ClearFailPoints() }() - // Create a new MongoClient with timeoutMS=150. - cliOptions := options.Client().SetTimeout(150 * time.Millisecond).ApplyURI(mtest.ClusterURI()) + cliOptions := options.Client().SetTimeout(100 * time.Millisecond).ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions) client, err := mongo.Connect(cliOptions) @@ -316,7 +315,7 @@ func TestCSOTProse(t *testing.T) { // If the operation-level context is not respected, then the client-level // timeout will exceed deadline. - ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 1000*time.Millisecond) defer cancel() // Upload file and ensure it uploaded correctly. @@ -334,7 +333,7 @@ func TestCSOTProse(t *testing.T) { mt.Run("OpenUploadStream", func(mt *mtest.T) { // If the operation-level context is not respected, then the client-level // timeout will exceed deadline. - ctx, cancel := context.WithTimeout(context.Background(), 500*time.Millisecond) + ctx, cancel := context.WithTimeout(context.Background(), 1000*time.Millisecond) defer cancel() // Upload file and ensure it uploaded correctly. From a83b295bec4d65815b4bdec15be2813a1f70edd9 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Thu, 5 Sep 2024 10:55:21 -0600 Subject: [PATCH 23/24] GODRIVER-3322 Make GridFS it's own test --- internal/integration/csot_prose_test.go | 168 ++++++++++++------------ 1 file changed, 86 insertions(+), 82 deletions(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index aafb71f2f0..2ce18bee2d 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -87,6 +87,92 @@ func TestCSOTProse(t *testing.T) { "insert", "expected a second insert event, got %v", started[1].CommandName) }) + mt.Run("8. server selection", func(mt *mtest.T) { + cliOpts := options.Client().ApplyURI("mongodb://invalid/?serverSelectionTimeoutMS=100") + mtOpts := mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) + mt.RunOpts("serverSelectionTimeoutMS honored if timeoutMS is not set", mtOpts, func(mt *mtest.T) { + // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? + // mt.Parallel() + + callback := func() bool { + err := mt.Client.Ping(context.Background(), nil) + assert.Error(mt, err, "expected Ping error, got nil") + return true + } + + // Assert that Ping fails within 150ms due to server selection timeout. + assert.Eventually(t, + callback, + 150*time.Millisecond, + time.Millisecond, + "expected ping to fail within 150ms") + }) + + cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=100&serverSelectionTimeoutMS=200") + mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) + mt.RunOpts("timeoutMS honored for server selection if it's lower than serverSelectionTimeoutMS", mtOpts, func(mt *mtest.T) { + // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? + // mt.Parallel() + + callback := func() bool { + err := mt.Client.Ping(context.Background(), nil) + assert.Error(mt, err, "expected Ping error, got nil") + return true + } + + // Assert that Ping fails within 150ms due to timeout. + assert.Eventually(t, + callback, + 150*time.Millisecond, + time.Millisecond, + "expected ping to fail within 150ms") + }) + + cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=200&serverSelectionTimeoutMS=100") + mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) + mt.RunOpts("serverSelectionTimeoutMS honored for server selection if it's lower than timeoutMS", mtOpts, func(mt *mtest.T) { + // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? + // mt.Parallel() + + callback := func() bool { + err := mt.Client.Ping(context.Background(), nil) + assert.Error(mt, err, "expected Ping error, got nil") + return true + } + + // Assert that Ping fails within 150ms due to server selection timeout. + assert.Eventually(t, + callback, + 150*time.Millisecond, + time.Millisecond, + "expected ping to fail within 150ms") + }) + + cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=100") + mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) + mt.RunOpts("serverSelectionTimeoutMS honored for server selection if timeoutMS=0", mtOpts, func(mt *mtest.T) { + // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? + // mt.Parallel() + + callback := func() bool { + err := mt.Client.Ping(context.Background(), nil) + assert.Error(mt, err, "expected Ping error, got nil") + return true + } + + // Assert that Ping fails within 150ms due to server selection timeout. + assert.Eventually(t, + callback, + 150*time.Millisecond, + time.Millisecond, + "expected ping to fail within 150ms") + }) + }) +} + +func TestCSOTProse_GridFS(t *testing.T) { + mt := mtest.New(t, mtest.NewOptions().CreateClient(false)) + mt.RunOpts("6. gridfs - upload", mtest.NewOptions().MinServerVersion("4.4"), func(mt *mtest.T) { mt.Run("uploads via openUploadStream can be timed out", func(mt *mtest.T) { // Drop and re-create the db.fs.files and db.fs.chunks collections. @@ -407,86 +493,4 @@ func TestCSOTProse(t *testing.T) { assert.Error(mt, err, context.Canceled) }) }) - - mt.Run("8. server selection", func(mt *mtest.T) { - cliOpts := options.Client().ApplyURI("mongodb://invalid/?serverSelectionTimeoutMS=100") - mtOpts := mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) - mt.RunOpts("serverSelectionTimeoutMS honored if timeoutMS is not set", mtOpts, func(mt *mtest.T) { - // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? - // mt.Parallel() - - callback := func() bool { - err := mt.Client.Ping(context.Background(), nil) - assert.Error(mt, err, "expected Ping error, got nil") - return true - } - - // Assert that Ping fails within 150ms due to server selection timeout. - assert.Eventually(t, - callback, - 150*time.Millisecond, - time.Millisecond, - "expected ping to fail within 150ms") - }) - - cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=100&serverSelectionTimeoutMS=200") - mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) - mt.RunOpts("timeoutMS honored for server selection if it's lower than serverSelectionTimeoutMS", mtOpts, func(mt *mtest.T) { - // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? - // mt.Parallel() - - callback := func() bool { - err := mt.Client.Ping(context.Background(), nil) - assert.Error(mt, err, "expected Ping error, got nil") - return true - } - - // Assert that Ping fails within 150ms due to timeout. - assert.Eventually(t, - callback, - 150*time.Millisecond, - time.Millisecond, - "expected ping to fail within 150ms") - }) - - cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=200&serverSelectionTimeoutMS=100") - mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) - mt.RunOpts("serverSelectionTimeoutMS honored for server selection if it's lower than timeoutMS", mtOpts, func(mt *mtest.T) { - // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? - // mt.Parallel() - - callback := func() bool { - err := mt.Client.Ping(context.Background(), nil) - assert.Error(mt, err, "expected Ping error, got nil") - return true - } - - // Assert that Ping fails within 150ms due to server selection timeout. - assert.Eventually(t, - callback, - 150*time.Millisecond, - time.Millisecond, - "expected ping to fail within 150ms") - }) - - cliOpts = options.Client().ApplyURI("mongodb://invalid/?timeoutMS=0&serverSelectionTimeoutMS=100") - mtOpts = mtest.NewOptions().ClientOptions(cliOpts).CreateCollection(false) - mt.RunOpts("serverSelectionTimeoutMS honored for server selection if timeoutMS=0", mtOpts, func(mt *mtest.T) { - // TODO(GODRIVER-3266): Why do parallel tests fail on windows builds? - // mt.Parallel() - - callback := func() bool { - err := mt.Client.Ping(context.Background(), nil) - assert.Error(mt, err, "expected Ping error, got nil") - return true - } - - // Assert that Ping fails within 150ms due to server selection timeout. - assert.Eventually(t, - callback, - 150*time.Millisecond, - time.Millisecond, - "expected ping to fail within 150ms") - }) - }) } From 5230e0163a5c39c70f31f52b26a9f1035dbbecb0 Mon Sep 17 00:00:00 2001 From: Preston Vasquez Date: Fri, 6 Sep 2024 11:05:09 -0600 Subject: [PATCH 24/24] GODRIVER-3322 Clean up test comments --- internal/integration/csot_prose_test.go | 1 - 1 file changed, 1 deletion(-) diff --git a/internal/integration/csot_prose_test.go b/internal/integration/csot_prose_test.go index 2ce18bee2d..3923efd6e7 100644 --- a/internal/integration/csot_prose_test.go +++ b/internal/integration/csot_prose_test.go @@ -450,7 +450,6 @@ func TestCSOTProse_GridFS(t *testing.T) { err = mt.Client.Database("db").Collection("fs.chunks").Drop(context.Background()) assert.NoError(mt, err, "failed to drop chunks") - // Create a new MongoClient with timeoutMS=10. cliOptions := options.Client().ApplyURI(mtest.ClusterURI()) integtest.AddTestServerAPIVersion(cliOptions)