@@ -20,7 +20,6 @@ import (
2020 "go.mongodb.org/mongo-driver/v2/event"
2121 "go.mongodb.org/mongo-driver/v2/internal/assert"
2222 "go.mongodb.org/mongo-driver/v2/internal/eventtest"
23- "go.mongodb.org/mongo-driver/v2/internal/failpoint"
2423 "go.mongodb.org/mongo-driver/v2/internal/handshake"
2524 "go.mongodb.org/mongo-driver/v2/internal/integration/mtest"
2625 "go.mongodb.org/mongo-driver/v2/internal/integtest"
@@ -648,76 +647,76 @@ func TestClient(t *testing.T) {
648647 }
649648 })
650649
651- opts := mtest .NewOptions ().
652- // Blocking failpoints don't work on pre-4.2 and sharded clusters.
653- Topologies (mtest .Single , mtest .ReplicaSet ).
654- MinServerVersion ("4.2" ).
655- // Expliticly enable retryable reads and retryable writes.
656- ClientOptions (options .Client ().SetRetryReads (true ).SetRetryWrites (true ))
657- mt .RunOpts ("operations don't retry after a context timeout" , opts , func (mt * mtest.T ) {
658- testCases := []struct {
659- desc string
660- operation func (context.Context , * mongo.Collection ) error
661- }{
662- {
663- desc : "read op" ,
664- operation : func (ctx context.Context , coll * mongo.Collection ) error {
665- return coll .FindOne (ctx , bson.D {}).Err ()
666- },
667- },
668- {
669- desc : "write op" ,
670- operation : func (ctx context.Context , coll * mongo.Collection ) error {
671- _ , err := coll .InsertOne (ctx , bson.D {})
672- return err
673- },
674- },
675- }
676-
677- for _ , tc := range testCases {
678- mt .Run (tc .desc , func (mt * mtest.T ) {
679- _ , err := mt .Coll .InsertOne (context .Background (), bson.D {})
680- require .NoError (mt , err )
681-
682- mt .SetFailPoint (failpoint.FailPoint {
683- ConfigureFailPoint : "failCommand" ,
684- Mode : failpoint .ModeAlwaysOn ,
685- Data : failpoint.Data {
686- FailCommands : []string {"find" , "insert" },
687- BlockConnection : true ,
688- BlockTimeMS : 500 ,
689- },
690- })
691-
692- mt .ClearEvents ()
693-
694- for i := 0 ; i < 50 ; i ++ {
695- // Run 50 operations, each with a timeout of 50ms. Expect
696- // them to all return a timeout error because the failpoint
697- // blocks find operations for 500ms. Run 50 to increase the
698- // probability that an operation will time out in a way that
699- // can cause a retry.
700- ctx , cancel := context .WithTimeout (context .Background (), 50 * time .Millisecond )
701- err = tc .operation (ctx , mt .Coll )
702- cancel ()
703- assert .ErrorIs (mt , err , context .DeadlineExceeded )
704- assert .True (mt , mongo .IsTimeout (err ), "expected mongo.IsTimeout(err) to be true" )
705-
706- // Assert that each operation reported exactly one command
707- // started events, which means the operation did not retry
708- // after the context timeout.
709- evts := mt .GetAllStartedEvents ()
710- require .Len (mt ,
711- mt .GetAllStartedEvents (),
712- 1 ,
713- "expected exactly 1 command started event per operation, but got %d after %d iterations" ,
714- len (evts ),
715- i )
716- mt .ClearEvents ()
717- }
718- })
719- }
720- })
650+ // opts := mtest.NewOptions().
651+ // // Blocking failpoints don't work on pre-4.2 and sharded clusters.
652+ // Topologies(mtest.Single, mtest.ReplicaSet).
653+ // MinServerVersion("4.2").
654+ // // Expliticly enable retryable reads and retryable writes.
655+ // ClientOptions(options.Client().SetRetryReads(true).SetRetryWrites(true))
656+ // mt.RunOpts("operations don't retry after a context timeout", opts, func(mt *mtest.T) {
657+ // testCases := []struct {
658+ // desc string
659+ // operation func(context.Context, *mongo.Collection) error
660+ // }{
661+ // {
662+ // desc: "read op",
663+ // operation: func(ctx context.Context, coll *mongo.Collection) error {
664+ // return coll.FindOne(ctx, bson.D{}).Err()
665+ // },
666+ // },
667+ // {
668+ // desc: "write op",
669+ // operation: func(ctx context.Context, coll *mongo.Collection) error {
670+ // _, err := coll.InsertOne(ctx, bson.D{})
671+ // return err
672+ // },
673+ // },
674+ // }
675+
676+ // for _, tc := range testCases {
677+ // mt.Run(tc.desc, func(mt *mtest.T) {
678+ // _, err := mt.Coll.InsertOne(context.Background(), bson.D{})
679+ // require.NoError(mt, err)
680+
681+ // mt.SetFailPoint(failpoint.FailPoint{
682+ // ConfigureFailPoint: "failCommand",
683+ // Mode: failpoint.ModeAlwaysOn,
684+ // Data: failpoint.Data{
685+ // FailCommands: []string{"find", "insert"},
686+ // BlockConnection: true,
687+ // BlockTimeMS: 500,
688+ // },
689+ // })
690+
691+ // mt.ClearEvents()
692+ // //i := 0
693+ // for i := 0; i < 2 ; i++ {
694+ // // Run 50 operations, each with a timeout of 50ms. Expect
695+ // // them to all return a timeout error because the failpoint
696+ // // blocks find operations for 500ms. Run 50 to increase the
697+ // // probability that an operation will time out in a way that
698+ // // can cause a retry.
699+ // ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
700+ // err = tc.operation(ctx, mt.Coll)
701+ // cancel()
702+ // assert.ErrorIs(mt, err, context.DeadlineExceeded)
703+ // assert.True(mt, mongo.IsTimeout(err), "expected mongo.IsTimeout(err) to be true")
704+
705+ // // Assert that each operation reported exactly one command
706+ // // started events, which means the operation did not retry
707+ // // after the context timeout.
708+ // evts := mt.GetAllStartedEvents()
709+ // require.Len(mt,
710+ // mt.GetAllStartedEvents(),
711+ // 1,
712+ // "expected exactly 1 command started event per operation, but got %d after %d iterations",
713+ // len(evts),
714+ // i)
715+ // mt.ClearEvents()
716+ // }
717+ // })
718+ // }
719+ // })
721720}
722721
723722func TestClient_BSONOptions (t * testing.T ) {
0 commit comments