1
- /* eslint-disable @typescript-eslint/no-unused-vars */
2
1
/* eslint-disable @typescript-eslint/no-non-null-assertion */
3
2
4
3
import { Readable } from 'node:stream' ;
@@ -7,16 +6,13 @@ import { pipeline } from 'node:stream/promises';
7
6
import { AssertionError , expect } from 'chai' ;
8
7
9
8
import {
10
- AbstractCursor ,
11
9
type ChangeStream ,
12
10
Collection ,
13
11
CommandStartedEvent ,
14
12
Db ,
15
13
type Document ,
16
- type GridFSFile ,
17
14
type MongoClient ,
18
15
MongoError ,
19
- type ObjectId ,
20
16
ReadConcern ,
21
17
ReadPreference ,
22
18
SERVER_DESCRIPTION_CHANGED ,
@@ -25,7 +21,7 @@ import {
25
21
type TopologyType ,
26
22
WriteConcern
27
23
} from '../../mongodb' ;
28
- import { getSymbolFrom , sleep } from '../../tools/utils' ;
24
+ import { sleep } from '../../tools/utils' ;
29
25
import { type TestConfiguration } from '../runner/config' ;
30
26
import { EntitiesMap } from './entities' ;
31
27
import { expectErrorCheck , resultCheck } from './match' ;
@@ -153,27 +149,27 @@ operations.set('assertSameLsidOnLastTwoCommands', async ({ entities, operation }
153
149
expect ( last . command . lsid . id . buffer . equals ( secondLast . command . lsid . id . buffer ) ) . to . be . true ;
154
150
} ) ;
155
151
156
- operations . set ( 'assertSessionDirty' , async ( { entities , operation } ) => {
152
+ operations . set ( 'assertSessionDirty' , async ( { operation } ) => {
157
153
const session = operation . arguments ! . session ;
158
154
expect ( session . serverSession . isDirty ) . to . be . true ;
159
155
} ) ;
160
156
161
- operations . set ( 'assertSessionNotDirty' , async ( { entities , operation } ) => {
157
+ operations . set ( 'assertSessionNotDirty' , async ( { operation } ) => {
162
158
const session = operation . arguments ! . session ;
163
159
expect ( session . serverSession . isDirty ) . to . be . false ;
164
160
} ) ;
165
161
166
- operations . set ( 'assertSessionPinned' , async ( { entities , operation } ) => {
162
+ operations . set ( 'assertSessionPinned' , async ( { operation } ) => {
167
163
const session = operation . arguments ! . session ;
168
164
expect ( session . isPinned , 'session should be pinned' ) . to . be . true ;
169
165
} ) ;
170
166
171
- operations . set ( 'assertSessionUnpinned' , async ( { entities , operation } ) => {
167
+ operations . set ( 'assertSessionUnpinned' , async ( { operation } ) => {
172
168
const session = operation . arguments ! . session ;
173
169
expect ( session . isPinned , 'session should be unpinned' ) . to . be . false ;
174
170
} ) ;
175
171
176
- operations . set ( 'assertSessionTransactionState' , async ( { entities , operation } ) => {
172
+ operations . set ( 'assertSessionTransactionState' , async ( { operation } ) => {
177
173
const session = operation . arguments ! . session ;
178
174
179
175
const transactionStateTranslation = {
@@ -240,7 +236,7 @@ operations.set('commitTransaction', async ({ entities, operation }) => {
240
236
241
237
operations . set ( 'createChangeStream' , async ( { entities, operation } ) => {
242
238
const watchable = entities . get ( operation . object ) ;
243
- if ( watchable == null || ! ( 'watch' in watchable ) ) {
239
+ if ( watchable == null || typeof watchable !== 'object' || ! ( 'watch' in watchable ) ) {
244
240
throw new AssertionError ( `Entity ${ operation . object } must be watchable` ) ;
245
241
}
246
242
@@ -292,7 +288,7 @@ operations.set('dropCollection', async ({ entities, operation }) => {
292
288
293
289
// TODO(NODE-4243): dropCollection should suppress namespace not found errors
294
290
try {
295
- return await db . dropCollection ( collection , opts ) ;
291
+ await db . dropCollection ( collection , opts ) ;
296
292
} catch ( err ) {
297
293
if ( ! / n s n o t f o u n d / . test ( err . message ) ) {
298
294
throw err ;
@@ -544,10 +540,10 @@ operations.set('upload', async ({ entities, operation }) => {
544
540
const bucket = entities . getEntity ( 'bucket' , operation . object ) ;
545
541
const { filename, source, ...options } = operation . arguments ?? { } ;
546
542
547
- const stream = bucket . openUploadStream ( operation . arguments ! . filename , options ) ;
548
- const filestream = Readable . from ( Buffer . from ( operation . arguments ! . source . $$hexBytes , 'hex' ) ) ;
543
+ const stream = bucket . openUploadStream ( filename , options ) ;
544
+ const fileStream = Readable . from ( Buffer . from ( source . $$hexBytes , 'hex' ) ) ;
549
545
550
- await pipeline ( filestream , stream ) ;
546
+ await pipeline ( fileStream , stream ) ;
551
547
return stream . gridFSFile ?. _id ;
552
548
} ) ;
553
549
@@ -720,7 +716,7 @@ operations.set('withTransaction', async ({ entities, operation, client, testConf
720
716
721
717
await session . withTransaction ( async ( ) => {
722
718
for ( const callbackOperation of operation . arguments ! . callback ) {
723
- await executeOperationAndCheck ( callbackOperation , entities , client , testConfig ) ;
719
+ await executeOperationAndCheck ( callbackOperation , entities , client , testConfig , true ) ;
724
720
}
725
721
} , options ) ;
726
722
} ) ;
@@ -935,7 +931,8 @@ export async function executeOperationAndCheck(
935
931
operation : OperationDescription ,
936
932
entities : EntitiesMap ,
937
933
client : MongoClient ,
938
- testConfig : TestConfiguration
934
+ testConfig : TestConfiguration ,
935
+ rethrow = false
939
936
) : Promise < void > {
940
937
const opFunc = operations . get ( operation . name ) ;
941
938
expect ( opFunc , `Unknown operation: ${ operation . name } ` ) . to . exist ;
@@ -956,10 +953,12 @@ export async function executeOperationAndCheck(
956
953
} catch ( error ) {
957
954
if ( operation . expectError ) {
958
955
expectErrorCheck ( error , operation . expectError , entities ) ;
956
+ if ( rethrow ) throw error ;
959
957
return ;
960
958
} else if ( ! operation . ignoreResultAndError || error instanceof MalformedOperationError ) {
961
959
throw error ;
962
960
}
961
+ if ( rethrow ) throw error ;
963
962
}
964
963
965
964
// We check the positive outcome here so the try-catch above doesn't catch our chai assertions
0 commit comments