@@ -6,8 +6,8 @@ import * as path from 'path';
6
6
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
7
7
import { ClientEncryption } from '../../../src/client-side-encryption/client_encryption' ;
8
8
import { type CommandStartedEvent , MongoClient , type MongoClientOptions } from '../../mongodb' ;
9
- import { getEncryptExtraOptions } from '../../tools/utils' ;
10
9
import { dropCollection } from '../shared' ;
10
+ import { TestConfiguration } from '../../tools/runner/config' ;
11
11
12
12
/* REFERENCE: (note commit hash) */
13
13
/* 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(
30
30
)
31
31
) ;
32
32
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
+ }
41
42
42
- super ( url , options ) ;
43
+ const client = configuration . newClient ( undefined , options ) as ReturnType < typeof makeClient > ;
43
44
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 ;
47
51
}
48
52
49
53
function deadlockTest (
@@ -55,7 +59,6 @@ function deadlockTest(
55
59
assertions
56
60
) {
57
61
return async function ( ) {
58
- const url = this . configuration . url ( ) ;
59
62
const clientTest = this . clientTest ;
60
63
const ciphertext = this . ciphertext ;
61
64
@@ -64,17 +67,12 @@ function deadlockTest(
64
67
keyVaultNamespace : 'keyvault.datakeys' ,
65
68
kmsProviders : { local : { key : LOCAL_KEY } } ,
66
69
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
73
71
} ,
74
72
maxPoolSize
75
73
} ;
76
74
77
- const clientEncrypted = new CapturingMongoClient ( url , clientEncryptedOpts ) ;
75
+ const clientEncrypted = makeClient ( this . configuration , clientEncryptedOpts ) ;
78
76
79
77
await clientEncrypted . connect ( ) ;
80
78
@@ -99,30 +97,19 @@ function deadlockTest(
99
97
} ;
100
98
}
101
99
102
- const metadata = {
100
+ const metadata : MongoDBMetadataUI = {
103
101
requires : {
104
102
clientSideEncryption : true ,
105
103
mongodb : '>=4.2.0' ,
106
104
topology : '!load-balanced'
107
105
}
108
106
} ;
109
- describe ( 'Connection Pool Deadlock Prevention' , function ( ) {
107
+ describe . only ( 'Connection Pool Deadlock Prevention' , function ( ) {
110
108
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 , {
123
111
monitorCommands : true ,
124
112
maxPoolSize : 1 ,
125
- ...options
126
113
} ) ;
127
114
128
115
this . clientEncryption = undefined ;
@@ -155,7 +142,7 @@ describe('Connection Pool Deadlock Prevention', function () {
155
142
} ) ;
156
143
157
144
afterEach ( function ( ) {
158
- return Promise . all ( [ this . clientKeyVault . close ( ) , this . clientTest . close ( ) ] ) . then ( ( ) => {
145
+ return Promise . all ( [ this . clientKeyVault ? .close ( ) , this . clientTest ? .close ( ) ] ) . then ( ( ) => {
159
146
this . clientKeyVault = undefined ;
160
147
this . clientTest = undefined ;
161
148
this . clientEncryption = undefined ;
0 commit comments