@@ -778,35 +778,16 @@ func TestClient(t *testing.T) {
778
778
mt .RunOpts ("operations don't retry after a context timeout" , opts , func (mt * mtest.T ) {
779
779
testCases := []struct {
780
780
desc string
781
- failPoint mtest.FailPoint
782
781
operation func (context.Context , * mongo.Collection ) error
783
782
}{
784
783
{
785
784
desc : "read op" ,
786
- failPoint : mtest.FailPoint {
787
- ConfigureFailPoint : "failCommand" ,
788
- Mode : "alwaysOn" ,
789
- Data : mtest.FailPointData {
790
- FailCommands : []string {"find" },
791
- BlockConnection : true ,
792
- BlockTimeMS : 500 ,
793
- },
794
- },
795
785
operation : func (ctx context.Context , coll * mongo.Collection ) error {
796
786
return coll .FindOne (ctx , bson.D {}).Err ()
797
787
},
798
788
},
799
789
{
800
790
desc : "write op" ,
801
- failPoint : mtest.FailPoint {
802
- ConfigureFailPoint : "failCommand" ,
803
- Mode : "alwaysOn" ,
804
- Data : mtest.FailPointData {
805
- FailCommands : []string {"insert" },
806
- BlockConnection : true ,
807
- BlockTimeMS : 500 ,
808
- },
809
- },
810
791
operation : func (ctx context.Context , coll * mongo.Collection ) error {
811
792
_ , err := coll .InsertOne (ctx , bson.D {})
812
793
return err
@@ -815,11 +796,19 @@ func TestClient(t *testing.T) {
815
796
}
816
797
817
798
for _ , tc := range testCases {
818
- mt .Run (tc .desc , func (t * mtest.T ) {
799
+ mt .Run (tc .desc , func (mt * mtest.T ) {
819
800
_ , err := mt .Coll .InsertOne (context .Background (), bson.D {})
820
801
require .NoError (mt , err )
821
802
822
- mt .SetFailPoint (tc .failPoint )
803
+ mt .SetFailPoint (mtest.FailPoint {
804
+ ConfigureFailPoint : "failCommand" ,
805
+ Mode : "alwaysOn" ,
806
+ Data : mtest.FailPointData {
807
+ FailCommands : []string {"find" , "insert" },
808
+ BlockConnection : true ,
809
+ BlockTimeMS : 500 ,
810
+ },
811
+ })
823
812
824
813
mt .ClearEvents ()
825
814
@@ -830,8 +819,8 @@ func TestClient(t *testing.T) {
830
819
// probability that an operation will time out in a way that
831
820
// can cause a retry.
832
821
ctx , cancel := context .WithTimeout (context .Background (), 50 * time .Millisecond )
833
- defer cancel ()
834
822
err = tc .operation (ctx , mt .Coll )
823
+ cancel ()
835
824
assert .ErrorIs (mt , err , context .DeadlineExceeded )
836
825
assert .True (mt , mongo .IsTimeout (err ), "expected mongo.IsTimeout(err) to be true" )
837
826
0 commit comments