@@ -6,8 +6,8 @@ import * as path from 'path';
66// eslint-disable-next-line @typescript-eslint/no-restricted-imports
77import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption' ;
88import { type CommandStartedEvent , MongoClient , type MongoClientOptions } from '../../mongodb' ;
9- import { getEncryptExtraOptions } from '../../tools/utils' ;
109import { dropCollection } from '../shared' ;
10+ import { TestConfiguration } from '../../tools/runner/config' ;
1111
1212/* REFERENCE: (note commit hash) */
1313/* https://github.com/mongodb/specifications/blob/b3beada 72ae1c992294ae6a8eea572003a274c35/source/client-side-encryption/tests/README.rst#deadlock-tests */
@@ -30,20 +30,24 @@ const $jsonSchema = BSON.EJSON.parse(
3030 )
3131) ;
3232
33- class CapturingMongoClient extends MongoClient {
34- commandStartedEvents : Array < CommandStartedEvent > = [ ] ;
35- clientsCreated = 0 ;
36- constructor ( url : string , options : MongoClientOptions = { } ) {
37- options = { ...options , monitorCommands : true , __skipPingOnConnect : true } ;
38- if ( process . env . MONGODB_API_VERSION ) {
39- options . serverApi = process . env . MONGODB_API_VERSION as MongoClientOptions [ 'serverApi' ] ;
40- }
33+ function makeClient ( configuration : TestConfiguration , options : MongoClientOptions = { } ) : MongoClient &
34+ {
35+ commandStartedEvents : Array < CommandStartedEvent > ,
36+ clientsCreated : number
37+ } {
38+ options = { ...options , monitorCommands : true , __skipPingOnConnect : true } ;
39+ if ( process . env . MONGODB_API_VERSION ) {
40+ options . serverApi = process . env . MONGODB_API_VERSION as MongoClientOptions [ 'serverApi' ] ;
41+ }
4142
42- super ( url , options ) ;
43+ const client = configuration . newClient ( undefined , options ) as ReturnType < typeof makeClient > ;
4344
44- this . on ( 'commandStarted' , ev => this . commandStartedEvents . push ( ev ) ) ;
45- this . on ( 'topologyOpening' , ( ) => this . clientsCreated ++ ) ;
46- }
45+ client . commandStartedEvents = [ ] ;
46+ client . clientsCreated = 0 ;
47+ client . on ( 'commandStarted' , ev => client . commandStartedEvents . push ( ev ) ) ;
48+ client . on ( 'topologyOpening' , ( ) => client . clientsCreated ++ ) ;
49+
50+ return client ;
4751}
4852
4953function deadlockTest (
@@ -55,7 +59,6 @@ function deadlockTest(
5559 assertions
5660) {
5761 return async function ( ) {
58- const url = this . configuration . url ( ) ;
5962 const clientTest = this . clientTest ;
6063 const ciphertext = this . ciphertext ;
6164
@@ -64,17 +67,12 @@ function deadlockTest(
6467 keyVaultNamespace : 'keyvault.datakeys' ,
6568 kmsProviders : { local : { key : LOCAL_KEY } } ,
6669 bypassAutoEncryption,
67- keyVaultClient : useKeyVaultClient ? this . clientKeyVault : undefined ,
68- extraOptions : {
69- // ...getEncryptExtraOptions(),
70- mongocryptdBypassSpawn : true ,
71- mongocryptdURI : 'mongodb://localhost:3000'
72- }
70+ keyVaultClient : useKeyVaultClient ? this . clientKeyVault : undefined
7371 } ,
7472 maxPoolSize
7573 } ;
7674
77- const clientEncrypted = new CapturingMongoClient ( url , clientEncryptedOpts ) ;
75+ const clientEncrypted = makeClient ( this . configuration , clientEncryptedOpts ) ;
7876
7977 await clientEncrypted . connect ( ) ;
8078
@@ -99,30 +97,19 @@ function deadlockTest(
9997 } ;
10098}
10199
102- const metadata = {
100+ const metadata : MongoDBMetadataUI = {
103101 requires : {
104102 clientSideEncryption : true ,
105103 mongodb : '>=4.2.0' ,
106104 topology : '!load-balanced'
107105 }
108106} ;
109- describe ( 'Connection Pool Deadlock Prevention' , function ( ) {
107+ describe . only ( 'Connection Pool Deadlock Prevention' , function ( ) {
110108 beforeEach ( async function ( ) {
111- const url : string = this . configuration . url ( ) ;
112-
113- const options = process . env . ALPINE ? {
114- autoEncryption : {
115- extraOptions : {
116- mongocryptdBypassSpawn : true ,
117- mongocryptdURI : 'mongodb://localhost:3000'
118- }
119- }
120- } : { } ;
121- this . clientTest = new CapturingMongoClient ( url , options ) ;
122- this . clientKeyVault = new CapturingMongoClient ( url , {
109+ this . clientTest = makeClient ( this . configuration ) ;
110+ this . clientKeyVault = makeClient ( this . configuration , {
123111 monitorCommands : true ,
124112 maxPoolSize : 1 ,
125- ...options
126113 } ) ;
127114
128115 this . clientEncryption = undefined ;
@@ -155,7 +142,7 @@ describe('Connection Pool Deadlock Prevention', function () {
155142 } ) ;
156143
157144 afterEach ( function ( ) {
158- return Promise . all ( [ this . clientKeyVault . close ( ) , this . clientTest . close ( ) ] ) . then ( ( ) => {
145+ return Promise . all ( [ this . clientKeyVault ? .close ( ) , this . clientTest ? .close ( ) ] ) . then ( ( ) => {
159146 this . clientKeyVault = undefined ;
160147 this . clientTest = undefined ;
161148 this . clientEncryption = undefined ;
0 commit comments