Skip to content

Commit 2f51ecc

Browse files
committed
CSHARP-3306: Set different appname in sync and async tests variations
1 parent 5f4dafd commit 2f51ecc

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

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

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ namespace MongoDB.Driver.Tests.Specifications.Runner
3737
public abstract class MongoClientJsonDrivenTestRunnerBase
3838
{
3939
// private fields
40+
private bool _async;
4041
private readonly string _collectionNameKey = "collection_name";
4142
private readonly string _databaseNameKey = "database_name";
4243
private readonly string _dataKey = "data";
@@ -321,7 +322,7 @@ protected virtual bool TryConfigureClientOption(MongoClientSettings settings, Bs
321322
break;
322323

323324
case "appname":
324-
settings.ApplicationName = option.Value.ToString();
325+
settings.ApplicationName = $"{option.Value}_async_{_async}";
325326
break;
326327

327328
case "connectTimeoutMS":
@@ -375,10 +376,24 @@ protected virtual void VerifyCollectionOutcome(BsonDocument outcome)
375376
}
376377
}
377378

379+
protected void ConfigureFailPointCommand(BsonDocument failPointCommand)
380+
{
381+
if (failPointCommand.TryGetValue("data", out var dataBsonValue))
382+
{
383+
var dataDocument = dataBsonValue.AsBsonDocument;
384+
if (dataDocument.TryGetValue("appName", out var appName))
385+
{
386+
dataDocument["appName"] = $"{appName}_async_{_async}";
387+
}
388+
}
389+
}
390+
378391
protected FailPoint ConfigureFailPoint(BsonDocument test, IMongoClient client)
379392
{
380393
if (test.TryGetValue(FailPointKey, out var failPoint))
381394
{
395+
ConfigureFailPointCommand(failPoint.AsBsonDocument);
396+
382397
var cluster = client.Cluster;
383398
var server = cluster.SelectServer(WritableServerSelector.Instance, CancellationToken.None);
384399
var session = NoCoreSession.NewHandle();
@@ -477,6 +492,7 @@ private void SetupAndRunTest(BsonDocument shared, BsonDocument test)
477492
Ensure.IsNotNullOrEmpty(DatabaseNameKey, nameof(DatabaseNameKey));
478493
Ensure.IsNotNullOrEmpty(CollectionNameKey, nameof(CollectionNameKey));
479494

495+
_async = test["async"].AsBoolean;
480496
CustomDataValidation(shared, test);
481497

482498
DatabaseName = GetDatabaseName(shared);

tests/MongoDB.Driver.Tests/Specifications/server-discovery-and-monitoring/ServerDiscoveryAndMonitoringIntegrationTestRunner.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ public class ServerDiscoveryAndMonitoringIntegrationTestRunner : DisposableJsonD
4040
// public methods
4141
public void ConfigureFailPoint(IServer server, ICoreSessionHandle session, BsonDocument failCommand)
4242
{
43+
ConfigureFailPointCommand(failCommand);
4344
var failPoint = FailPoint.Configure(server, session, failCommand);
4445
AddDisposable(failPoint);
4546
}
4647

4748
public async Task ConfigureFailPointAsync(IServer server, ICoreSessionHandle session, BsonDocument failCommand)
4849
{
50+
ConfigureFailPointCommand(failCommand);
4951
var failPoint = await Task.Run(() => FailPoint.Configure(server, session, failCommand)).ConfigureAwait(false);
5052
AddDisposable(failPoint);
5153
}

0 commit comments

Comments
 (0)