1919using System . IO ;
2020using System . Linq ;
2121using System . Reflection ;
22- using System . Threading ;
2322using MongoDB . Bson ;
24- using MongoDB . Bson . TestHelpers . XunitExtensions ;
25- using MongoDB . Driver . Core . Clusters ;
2623using MongoDB . Driver . Core . TestHelpers . XunitExtensions ;
24+ using MongoDB . Driver . TestHelpers ;
2725using Xunit ;
2826using Xunit . Abstractions ;
2927
@@ -44,7 +42,7 @@ public void RunTestDefinition(TestCase testCase)
4442 var async = testCase . Async ;
4543
4644 VerifyServerRequirements ( definition ) ;
47- VerifyFields ( definition , "path" , "data" , "minServerVersion" , "maxServerVersion ", "tests" ) ;
45+ VerifyFields ( definition , "path" , "data" , "runOn " , "tests" ) ;
4846
4947 InitializeCollection ( definition ) ;
5048 RunTest ( test , async ) ;
@@ -53,23 +51,14 @@ public void RunTestDefinition(TestCase testCase)
5351 // private methods
5452 private void VerifyServerRequirements ( BsonDocument definition )
5553 {
56- RequireServer . Check ( ) . ClusterType ( ClusterType . ReplicaSet ) ;
57-
58- if ( CoreTestConfiguration . GetStorageEngine ( ) == "mmapv1" )
59- {
60- throw new SkipException ( "Test skipped because mmapv1 does not support retryable writes." ) ;
61- }
62-
63- BsonValue minServerVersion ;
64- if ( definition . TryGetValue ( "minServerVersion" , out minServerVersion ) )
54+ if ( definition . TryGetValue ( "runOn" , out var runOn ) )
6555 {
66- RequireServer . Check ( ) . VersionGreaterThanOrEqualTo ( minServerVersion . AsString ) ;
56+ RequireServer . Check ( ) . RunOn ( runOn . AsBsonArray ) ;
6757 }
6858
69- BsonValue maxServerVersion ;
70- if ( definition . TryGetValue ( "maxServerVersion" , out maxServerVersion ) )
59+ if ( CoreTestConfiguration . GetStorageEngine ( ) == "mmapv1" )
7160 {
72- RequireServer . Check ( ) . VersionLessThanOrEqualTo ( maxServerVersion . AsString ) ;
61+ throw new SkipException ( "Test skipped because mmapv1 does not support retryable writes." ) ;
7362 }
7463 }
7564
@@ -96,35 +85,41 @@ private void InitializeCollection(BsonDocument definition)
9685
9786 private void RunTest ( BsonDocument test , bool async )
9887 {
99- VerifyFields ( test , "description" , "clientOptions" , "failPoint" , "operation" , "outcome" ) ;
100- var clientOptions = ( BsonDocument ) test . GetValue ( "clientOptions" , null ) ;
88+ VerifyFields ( test , "description" , "clientOptions" , "failPoint" , "operation" , "outcome" , "useMultipleMongoses" ) ;
10189 var failPoint = ( BsonDocument ) test . GetValue ( "failPoint" , null ) ;
10290 var operation = test [ "operation" ] . AsBsonDocument ;
10391 var outcome = test [ "outcome" ] . AsBsonDocument ;
10492
105- var client = CreateClient ( clientOptions ) ;
106- var database = client . GetDatabase ( _databaseName ) ;
107- var collection = database . GetCollection < BsonDocument > ( _collectionName ) ;
108- var executableTest = CreateExecutableTest ( operation ) ;
109-
110- using ( ConfigureFailPoint ( client , failPoint ) )
93+ using ( var client = CreateDisposableClient ( test ) )
11194 {
112- executableTest . Execute ( collection , async ) ;
113- }
95+ var database = client . GetDatabase ( _databaseName ) ;
96+ var collection = database . GetCollection < BsonDocument > ( _collectionName ) ;
97+ var executableTest = CreateExecutableTest ( operation ) ;
98+
99+ using ( ConfigureFailPoint ( client , failPoint ) )
100+ {
101+ executableTest . Execute ( collection , async ) ;
102+ }
114103
115- executableTest . VerifyOutcome ( collection , outcome ) ;
104+ executableTest . VerifyOutcome ( collection , outcome ) ;
105+ }
116106 }
117107
118- private IMongoClient CreateClient ( BsonDocument clientOptions )
108+ private DisposableMongoClient CreateDisposableClient ( BsonDocument test )
119109 {
120- var clientSettings = ParseClientOptions ( clientOptions ) ;
121- return new MongoClient ( clientSettings ) ;
110+ var useMultipleShardRouters = test . GetValue ( "useMultipleMongoses" , false ) . AsBoolean ;
111+ var clientOptions = ( BsonDocument ) test . GetValue ( "clientOptions" , null ) ;
112+
113+ return DriverTestConfiguration . CreateDisposableClient (
114+ settings =>
115+ {
116+ ParseClientOptions ( settings , clientOptions ) ;
117+ } ,
118+ useMultipleShardRouters ) ;
122119 }
123120
124- private MongoClientSettings ParseClientOptions ( BsonDocument clientOptions )
121+ private void ParseClientOptions ( MongoClientSettings settings , BsonDocument clientOptions )
125122 {
126- var settings = DriverTestConfiguration . Client . Settings . Clone ( ) ;
127-
128123 if ( clientOptions == null )
129124 {
130125 settings . RetryWrites = true ;
@@ -147,8 +142,6 @@ private MongoClientSettings ParseClientOptions(BsonDocument clientOptions)
147142 }
148143 }
149144 }
150-
151- return settings ;
152145 }
153146
154147 private IRetryableWriteTest CreateExecutableTest ( BsonDocument operation )
@@ -160,13 +153,15 @@ private IRetryableWriteTest CreateExecutableTest(BsonDocument operation)
160153 {
161154 case "bulkWrite" : executableTest = new BulkWriteTest ( ) ; break ;
162155 case "deleteOne" : executableTest = new DeleteOneTest ( ) ; break ;
156+ case "deleteMany" : executableTest = new DeleteManyTest ( ) ; break ;
163157 case "findOneAndDelete" : executableTest = new FindOneAndDeleteTest ( ) ; break ;
164158 case "findOneAndReplace" : executableTest = new FindOneAndReplaceTest ( ) ; break ;
165159 case "findOneAndUpdate" : executableTest = new FindOneAndUpdateTest ( ) ; break ;
166160 case "insertOne" : executableTest = new InsertOneTest ( ) ; break ;
167161 case "insertMany" : executableTest = new InsertManyTest ( ) ; break ;
168162 case "replaceOne" : executableTest = new ReplaceOneTest ( ) ; break ;
169163 case "updateOne" : executableTest = new UpdateOneTest ( ) ; break ;
164+ case "updateMany" : executableTest = new UpdateManyTest ( ) ; break ;
170165 default : throw new ArgumentException ( $ "Unexpected operation name: { operationName } .") ;
171166 }
172167 executableTest . Initialize ( operation ) ;
0 commit comments