// private methods private FailPoint ConfigureFailPoint(string failpointCommand) { var cluster = DriverTestConfiguration.Client.Cluster; var session = NoCoreSession.NewHandle(); return(FailPoint.Configure(cluster, session, BsonDocument.Parse(failpointCommand))); }
// private methods private FailPoint ConfigureFailPoint(IMongoClient client, int errorCode) { var session = NoCoreSession.NewHandle(); var args = BsonDocument.Parse($"{{ mode : {{ times : 1 }}, data : {{ failCommands : [\"insert\"], errorCode : {errorCode} }} }}"); return(FailPoint.Configure(client.Cluster, session, "failCommand", args)); }
public void SelectServer_loadbalancing_prose_test([Values(false, true)] bool async) { RequireServer.Check() .Supports(Feature.ShardedTransactions, Feature.FailPointsBlockConnection) .ClusterType(ClusterType.Sharded); RequireMultipleShardRouters(); // temporary disable the test on Win Auth topologies, due to operations timings irregularities if (CoreTestConfiguration.ConnectionString.Tls == true && RequirePlatform.GetCurrentOperatingSystem() == SupportedOperatingSystem.Windows) { throw new SkipException("Win Auth topologies temporary not supported due to timings irregularities."); } const string applicationName = "loadBalancingTest"; const int threadsCount = 10; const int commandsPerThreadCount = 10; const double maxCommandsOnSlowServerRatio = 0.3; // temporary set slow server load to 30% from 25% until find timings are investigated const double operationsCountTolerance = 0.10; var failCommand = BsonDocument.Parse($"{{ configureFailPoint: 'failCommand', mode : {{ times : 10000 }}, data : {{ failCommands : [\"find\"], blockConnection: true, blockTimeMS: 500, appName: '{applicationName}' }} }}"); DropCollection(); var eventCapturer = CreateEventCapturer(); using (var client = CreateDisposableClient(eventCapturer, applicationName)) { var slowServer = client.Cluster.SelectServer(WritableServerSelector.Instance, default); var fastServer = client.Cluster.SelectServer(new DelegateServerSelector((_, servers) => servers.Where(s => s.ServerId != slowServer.ServerId)), default); using var failPoint = FailPoint.Configure(slowServer, NoCoreSession.NewHandle(), failCommand); var database = client.GetDatabase(_databaseName); CreateCollection(); var collection = database.GetCollection <BsonDocument>(_collectionName); // warm up connections var channels = new ConcurrentBag <IChannelHandle>(); ThreadingUtilities.ExecuteOnNewThreads(threadsCount, i => { channels.Add(slowServer.GetChannel(default)); channels.Add(fastServer.GetChannel(default));