Skip to content

Commit 4cfcd12

Browse files
committed
Simplify context timeout retry test.
1 parent a135db3 commit 4cfcd12

File tree

1 file changed

+11
-22
lines changed

1 file changed

+11
-22
lines changed

mongo/integration/client_test.go

+11-22
Original file line numberDiff line numberDiff line change
@@ -778,35 +778,16 @@ func TestClient(t *testing.T) {
778778
mt.RunOpts("operations don't retry after a context timeout", opts, func(mt *mtest.T) {
779779
testCases := []struct {
780780
desc string
781-
failPoint mtest.FailPoint
782781
operation func(context.Context, *mongo.Collection) error
783782
}{
784783
{
785784
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-
},
795785
operation: func(ctx context.Context, coll *mongo.Collection) error {
796786
return coll.FindOne(ctx, bson.D{}).Err()
797787
},
798788
},
799789
{
800790
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-
},
810791
operation: func(ctx context.Context, coll *mongo.Collection) error {
811792
_, err := coll.InsertOne(ctx, bson.D{})
812793
return err
@@ -815,11 +796,19 @@ func TestClient(t *testing.T) {
815796
}
816797

817798
for _, tc := range testCases {
818-
mt.Run(tc.desc, func(t *mtest.T) {
799+
mt.Run(tc.desc, func(mt *mtest.T) {
819800
_, err := mt.Coll.InsertOne(context.Background(), bson.D{})
820801
require.NoError(mt, err)
821802

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+
})
823812

824813
mt.ClearEvents()
825814

@@ -830,8 +819,8 @@ func TestClient(t *testing.T) {
830819
// probability that an operation will time out in a way that
831820
// can cause a retry.
832821
ctx, cancel := context.WithTimeout(context.Background(), 50*time.Millisecond)
833-
defer cancel()
834822
err = tc.operation(ctx, mt.Coll)
823+
cancel()
835824
assert.ErrorIs(mt, err, context.DeadlineExceeded)
836825
assert.True(mt, mongo.IsTimeout(err), "expected mongo.IsTimeout(err) to be true")
837826

0 commit comments

Comments
 (0)