@@ -1433,7 +1433,8 @@ public void ExternalKeyVaultTest(
1433
1433
[ ParameterAttributeData ]
1434
1434
public async Task KmsRetryTest(
1435
1435
[ Values ( "aws" , "azure" , "gcp" ) ] string kmsProvider,
1436
- [ Values ( "network" , "http" ) ] string failureType)
1436
+ [ Values ( "network" , "http" ) ] string failureType,
1437
+ [ Values ( false , true ) ] bool async)
1437
1438
{
1438
1439
RequireServer . Check ( ) . Supports ( Feature . ClientSideEncryption ) ;
1439
1440
RequireEnvironment. Check ( ) . EnvironmentVariable ( "KMS_MOCK_SERVERS_ENABLED" , isDefined : true ) ;
@@ -1478,22 +1479,49 @@ public async Task KmsRetryTest(
1478
1479
await SetFailure( failureType , 1 ) ;
1479
1480
1480
1481
Guid dataKey = default ;
1481
- var ex = await Record. ExceptionAsync ( async ( ) => dataKey = await clientEncryption
1482
- . CreateDataKeyAsync ( kmsProvider , dataKeyOptions , CancellationToken . None ) ) ;
1482
+ Exception ex;
1483
+ if ( async)
1484
+ {
1485
+ ex = await Record . ExceptionAsync ( async ( ) => dataKey = await clientEncryption
1486
+ . CreateDataKeyAsync ( kmsProvider , dataKeyOptions , CancellationToken . None ) ) ;
1487
+ }
1488
+ else
1489
+ {
1490
+ ex = Record . Exception ( ( ) => dataKey = clientEncryption
1491
+ . CreateDataKey ( kmsProvider , dataKeyOptions , CancellationToken . None ) ) ;
1492
+ }
1483
1493
ex . Should ( ) . BeNull ( ) ;
1484
1494
1485
1495
await SetFailure ( failureType , 1 ) ;
1486
1496
1487
- var ex2 = await Record. ExceptionAsync ( async ( ) => await clientEncryption . EncryptAsync ( new BsonInt32 ( 123 ) ,
1488
- new EncryptOptions ( "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" , keyId : dataKey ) ) ) ;
1497
+ Exception ex2 ;
1498
+ if ( async )
1499
+ {
1500
+ ex2 = await Record . ExceptionAsync ( async ( ) => await clientEncryption . EncryptAsync ( new BsonInt32 ( 123 ) ,
1501
+ new EncryptOptions ( "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" , keyId : dataKey ) ) ) ;
1502
+ }
1503
+ else
1504
+ {
1505
+ ex2 = Record . Exception ( ( ) => clientEncryption . Encrypt ( new BsonInt32 ( 123 ) ,
1506
+ new EncryptOptions ( "AEAD_AES_256_CBC_HMAC_SHA_512-Deterministic" , keyId : dataKey ) ) ) ;
1507
+ }
1489
1508
ex2 . Should ( ) . BeNull ( ) ;
1490
1509
1491
1510
if ( failureType == "network" )
1492
1511
{
1493
1512
await SetFailure ( "network" , 4 ) ;
1494
1513
1495
- var ex3 = await Record. ExceptionAsync ( async ( ) => await clientEncryption
1496
- . CreateDataKeyAsync ( kmsProvider , dataKeyOptions , CancellationToken . None ) ) ;
1514
+ Exception ex3;
1515
+ if ( async)
1516
+ {
1517
+ ex3 = await Record . ExceptionAsync ( async ( ) => dataKey = await clientEncryption
1518
+ . CreateDataKeyAsync ( kmsProvider , dataKeyOptions , CancellationToken . None ) ) ;
1519
+ }
1520
+ else
1521
+ {
1522
+ ex3 = Record . Exception ( ( ) => dataKey = clientEncryption
1523
+ . CreateDataKey ( kmsProvider , dataKeyOptions , CancellationToken . None ) ) ;
1524
+ }
1497
1525
ex3 . Should ( ) . NotBeNull ( ) ;
1498
1526
}
1499
1527
0 commit comments