1+ import { BSON , Int32 , Long , serialize } from 'bson' ;
12import { expect } from 'chai' ;
23import { EventEmitter , once } from 'events' ;
34import * as fs from 'fs/promises' ;
45import { type MongoCryptKMSRequest } from 'mongodb-client-encryption' ;
56import * as net from 'net' ;
67import * as sinon from 'sinon' ;
7- import { setTimeout } from 'timers' ;
88import { setTimeout as setTimeoutAsync } from 'timers/promises' ;
99import * as tls from 'tls' ;
1010
1111import { StateMachine } from '../../../src/client-side-encryption/state_machine' ;
12+ import { Collection } from '../../../src/collection' ;
13+ import { CursorTimeoutContext } from '../../../src/cursor/abstract_cursor' ;
1214import { Db } from '../../../src/db' ;
13- import {
14- BSON ,
15- Collection ,
16- CSOTTimeoutContext ,
17- CursorTimeoutContext ,
18- type FindOptions ,
19- Int32 ,
20- Long ,
21- MongoClient ,
22- serialize ,
23- squashError
24- } from '../../mongodb' ;
15+ import { MongoClient } from '../../../src/mongo_client' ;
16+ import { type FindOptions } from '../../../src/operations/find' ;
17+ import { CSOTTimeoutContext } from '../../../src/timeout' ;
18+ import { squashError } from '../../../src/utils' ;
2519import { sleep } from '../../tools/utils' ;
2620
2721describe ( 'StateMachine' , function ( ) {
@@ -129,7 +123,7 @@ describe('StateMachine', function () {
129123 } ) ;
130124 } ) ;
131125
132- it ( 'should only resolve once bytesNeeded drops to zero' , function ( done ) {
126+ it ( 'should only resolve once bytesNeeded drops to zero' , async function ( ) {
133127 const stateMachine = new StateMachine ( { } as any ) ;
134128 const request = new MockRequest ( Buffer . from ( 'foobar' ) , 500 ) ;
135129 let status = 'pending' ;
@@ -143,22 +137,21 @@ describe('StateMachine', function () {
143137 . catch ( ( ) => { } ) ;
144138
145139 this . fakeSocket . emit ( 'connect' ) ;
146- setTimeout ( ( ) => {
147- expect ( status ) . to . equal ( 'pending' ) ;
148- expect ( request . bytesNeeded ) . to . equal ( 500 ) ;
149- expect ( request . kmsProvider ) . to . equal ( 'aws' ) ;
150- this . fakeSocket . emit ( 'data' , Buffer . alloc ( 300 ) ) ;
151- setTimeout ( ( ) => {
152- expect ( status ) . to . equal ( 'pending' ) ;
153- expect ( request . bytesNeeded ) . to . equal ( 200 ) ;
154- this . fakeSocket . emit ( 'data' , Buffer . alloc ( 200 ) ) ;
155- setTimeout ( ( ) => {
156- expect ( status ) . to . equal ( 'resolved' ) ;
157- expect ( request . bytesNeeded ) . to . equal ( 0 ) ;
158- done ( ) ;
159- } ) ;
160- } ) ;
161- } ) ;
140+ await sleep ( ) ;
141+
142+ expect ( status ) . to . equal ( 'pending' ) ;
143+ expect ( request . bytesNeeded ) . to . equal ( 500 ) ;
144+ expect ( request . kmsProvider ) . to . equal ( 'aws' ) ;
145+ this . fakeSocket . emit ( 'data' , Buffer . alloc ( 300 ) ) ;
146+ await sleep ( ) ;
147+
148+ expect ( status ) . to . equal ( 'pending' ) ;
149+ expect ( request . bytesNeeded ) . to . equal ( 200 ) ;
150+ this . fakeSocket . emit ( 'data' , Buffer . alloc ( 200 ) ) ;
151+ await sleep ( ) ;
152+
153+ expect ( status ) . to . equal ( 'resolved' ) ;
154+ expect ( request . bytesNeeded ) . to . equal ( 0 ) ;
162155 } ) ;
163156 } ) ;
164157
@@ -196,13 +189,9 @@ describe('StateMachine', function () {
196189 } as any ) ;
197190 const request = new MockRequest ( Buffer . from ( 'foobar' ) , 500 ) ;
198191
199- it ( 'rejects with the validation error' , function ( done ) {
200- stateMachine . kmsRequest ( request ) . catch ( err => {
201- expect ( err . message ) . to . equal (
202- `Insecure TLS options prohibited for aws: ${ option } `
203- ) ;
204- done ( ) ;
205- } ) ;
192+ it ( 'rejects with the validation error' , async function ( ) {
193+ const err = await stateMachine . kmsRequest ( request ) . catch ( e => e ) ;
194+ expect ( err . message ) . to . equal ( `Insecure TLS options prohibited for aws: ${ option } ` ) ;
206195 } ) ;
207196 } ) ;
208197 }
0 commit comments