@@ -60,24 +60,25 @@ type T struct {
6060 * testing.T
6161
6262 // members for only this T instance
63- createClient * bool
64- createCollection * bool
65- runOn []RunOnBlock
66- mockDeployment * drivertest.MockDeployment // nil if the test is not being run against a mock
67- mockResponses []bson.D
68- createdColls []* Collection // collections created in this test
69- proxyDialer * proxyDialer
70- dbName , collName string
71- failPointNames []string
72- minServerVersion string
73- maxServerVersion string
74- validTopologies []TopologyKind
75- auth * bool
76- enterprise * bool
77- dataLake * bool
78- ssl * bool
79- collCreateOpts * options.CreateCollectionOptionsBuilder
80- requireAPIVersion * bool
63+ createClient * bool
64+ createCollection * bool
65+ runOn []RunOnBlock
66+ mockDeployment * drivertest.MockDeployment // nil if the test is not being run against a mock
67+ mockResponses []bson.D
68+ createdColls []* Collection // collections created in this test
69+ proxyDialer * proxyDialer
70+ dbName , collName string
71+ failPointNames []string
72+ minServerVersion string
73+ maxServerVersion string
74+ validTopologies []TopologyKind
75+ auth * bool
76+ enterprise * bool
77+ dataLake * bool
78+ ssl * bool
79+ collCreateOpts * options.CreateCollectionOptionsBuilder
80+ requireAPIVersion * bool
81+ allowFailPointsOnSharded bool
8182
8283 // options copied to sub-tests
8384 clientType ClientType
@@ -125,6 +126,9 @@ func newT(wrapped *testing.T, opts ...*Options) *T {
125126 if t .shareClient != nil {
126127 t .baseOpts .ShareClient (* t .shareClient )
127128 }
129+ if t .allowFailPointsOnSharded {
130+ t .baseOpts .AllowFailPointsOnSharded ()
131+ }
128132
129133 return t
130134}
@@ -501,6 +505,21 @@ func (t *T) ClearCollections() {
501505// SetFailPoint sets a fail point for the client associated with T. Commands to create the failpoint will appear
502506// in command monitoring channels. The fail point will automatically be disabled after this test has run.
503507func (t * T ) SetFailPoint (fp failpoint.FailPoint ) {
508+ // Do not allow failpoints to be used on sharded topologies unless
509+ // specifically configured to allow it.
510+ //
511+ // On sharded topologies, failpoints are applied to only a single mongoS. If
512+ // the driver is connected to multiple mongoS instances, there's a
513+ // possibility a different mongoS will be selected for a subsequent command.
514+ // In that case, the failpoint is effectively ignored, leading to a test
515+ // failure that is extremely difficult to diagnose.
516+ //
517+ // TODO(GODRIVER-3328): Remove this once we set failpoints on every mongoS
518+ // in sharded topologies.
519+ if testContext .topoKind == Sharded && ! t .allowFailPointsOnSharded {
520+ t .Fatalf ("cannot use failpoints with sharded topologies unless AllowFailPointsOnSharded is set" )
521+ }
522+
504523 // ensure mode fields are int32
505524 if modeMap , ok := fp .Mode .(map [string ]any ); ok {
506525 var key string
0 commit comments