Skip to content

Commit 0abee49

Browse files
authored
CSHARP-5358: Dispose client cluster in LibmongocryptTests.cs (#1516)
1 parent f9f76d9 commit 0abee49

File tree

1 file changed

+15
-8
lines changed

1 file changed

+15
-8
lines changed

tests/SmokeTests/MongoDB.Driver.SmokeTests.Sdk/LibmongocryptTests.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,9 @@ public void Explicit_encryption_with_libmongocrypt_package_works()
6262
keyVaultNamespace,
6363
kmsProviders);
6464

65-
var clientEncryption = new ClientEncryption(clientEncryptionSettings);
65+
using var clientEncryption = new ClientEncryption(clientEncryptionSettings);
6666
var dataKeyId = clientEncryption.CreateDataKey("local", new DataKeyOptions(), CancellationToken.None);
6767
var base64DataKeyId = Convert.ToBase64String(GuidConverter.ToBytes(dataKeyId, GuidRepresentation.Standard));
68-
clientEncryption.Dispose();
6968

7069
var collectionNamespace = CollectionNamespace.FromFullName("test.coll");
7170

@@ -100,14 +99,22 @@ public void Explicit_encryption_with_libmongocrypt_package_works()
10099
clientSettings.LoggingSettings = new LoggingSettings(loggerFactory);
101100

102101
var client = new MongoClient(clientSettings);
103-
var database = client.GetDatabase("test");
104-
database.DropCollection("coll");
105-
var collection = database.GetCollection<BsonDocument>("coll");
106102

107-
collection.InsertOne(new BsonDocument("encryptedField", "123456789"));
103+
try
104+
{
105+
var database = client.GetDatabase("test");
106+
database.DropCollection("coll");
107+
var collection = database.GetCollection<BsonDocument>("coll");
108+
109+
collection.InsertOne(new BsonDocument("encryptedField", "123456789"));
108110

109-
var result = collection.Find(FilterDefinition<BsonDocument>.Empty).First();
110-
_output.WriteLine(result.ToJson());
111+
var result = collection.Find(FilterDefinition<BsonDocument>.Empty).First();
112+
_output.WriteLine(result.ToJson());
113+
}
114+
finally
115+
{
116+
ClusterRegistry.Instance.UnregisterAndDisposeCluster(client.Cluster);
117+
}
111118
}
112119

113120
var expectedLogs = new[]

0 commit comments

Comments
 (0)