Skip to content

Commit c693a7c

Browse files
authored
CSHARP-5014: Failed test: MongoDB.Driver.Tests.Specifications.transactions_convenient_api.tests.transaction-options.json_withTransaction_explicit_transaction_options_override_client_options (#1367)
1 parent 28f1513 commit c693a7c

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenSessionsTestRunner.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,12 @@ protected void KillAllSessions()
103103
protected IClientSessionHandle StartSession(IMongoClient client, BsonDocument test, string sessionKey)
104104
{
105105
var options = ParseSessionOptions(test, sessionKey);
106-
return client.StartSession(options);
106+
var session = client.StartSession(options);
107+
if (LastKnownClusterTime != null)
108+
{
109+
session.WrappedCoreSession.AdvanceClusterTime(LastKnownClusterTime);
110+
}
111+
return session;
107112
}
108113

109114
// private methods

tests/MongoDB.Driver.Tests/Specifications/Runner/MongoClientJsonDrivenTestRunnerBase.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ public abstract class MongoClientJsonDrivenTestRunnerBase : LoggableTestClass
7474

7575
protected IServer _failPointServer = null;
7676

77+
protected BsonDocument LastKnownClusterTime { get; set; }
78+
7779
// public constructors
7880
public MongoClientJsonDrivenTestRunnerBase(ITestOutputHelper testOutputHelper)
7981
: base(testOutputHelper)
@@ -218,8 +220,11 @@ protected virtual void CreateCollection(IMongoClient client, string databaseName
218220
{
219221
Logger.LogDebug("Creating collection {0} in {1} db", databaseName, collectionName);
220222

223+
var session = client.StartSession();
221224
var database = client.GetDatabase(databaseName).WithWriteConcern(WriteConcern.WMajority);
222-
database.CreateCollection(collectionName);
225+
database.CreateCollection(session, collectionName);
226+
227+
LastKnownClusterTime = session.ClusterTime;
223228
}
224229

225230
protected virtual MongoClient CreateClientForTestSetup()
@@ -288,13 +293,21 @@ protected virtual void InsertData(IMongoClient client, string databaseName, stri
288293

289294
if (shared.Contains(DataKey))
290295
{
296+
BsonDocument lastServerTime = null;
291297
var documents = shared[DataKey].AsBsonArray.Cast<BsonDocument>().ToList();
298+
292299
if (documents.Count > 0)
293300
{
301+
var session = client.StartSession();
302+
294303
var database = client.GetDatabase(databaseName);
295304
var collection = database.GetCollection<BsonDocument>(collectionName).WithWriteConcern(WriteConcern.WMajority);
296-
collection.InsertMany(documents);
305+
collection.InsertMany(session, documents);
306+
307+
lastServerTime = session.ClusterTime;
297308
}
309+
310+
LastKnownClusterTime = lastServerTime ?? LastKnownClusterTime;
298311
}
299312
}
300313

0 commit comments

Comments
 (0)