@@ -8,6 +8,7 @@ import { pipeline } from 'stream/promises';
8
8
9
9
import { type CommandStartedEvent } from '../../../mongodb' ;
10
10
import {
11
+ type AnyClientBulkWriteModel ,
11
12
type CommandSucceededEvent ,
12
13
GridFSBucket ,
13
14
MongoBulkWriteError ,
@@ -19,6 +20,7 @@ import {
19
20
promiseWithResolvers
20
21
} from '../../mongodb' ;
21
22
import { type FailPoint } from '../../tools/utils' ;
23
+ import { filterForCommands } from '../shared' ;
22
24
23
25
// TODO(NODE-5824): Implement CSOT prose tests
24
26
describe ( 'CSOT spec prose tests' , function ( ) {
@@ -1106,7 +1108,7 @@ describe('CSOT spec prose tests', function () {
1106
1108
1107
1109
describe (
1108
1110
'11. Multi-batch bulkWrites' ,
1109
- { requires : { mongodb : '>=8.0' , serverless : 'forbid' } } ,
1111
+ { requires : { mongodb : '>=8.0' , serverless : 'forbid' , topology : 'single' } } ,
1110
1112
function ( ) {
1111
1113
/**
1112
1114
* ### 11. Multi-batch bulkWrites
@@ -1154,47 +1156,42 @@ describe('CSOT spec prose tests', function () {
1154
1156
*
1155
1157
* 7. Verify that two `bulkWrite` commands were executed as part of the `MongoClient.bulkWrite` call.
1156
1158
*/
1157
- const failpoint : FailPoint = {
1158
- configureFailPoint : 'failCommand' ,
1159
- mode : {
1160
- times : 2
1161
- } ,
1162
- data : {
1163
- failCommands : [ 'bulkWrite' ] ,
1164
- blockConnection : true ,
1165
- blockTimeMS : 1010
1166
- }
1167
- } ;
1168
1159
1169
- let maxBsonObjectSize : number ;
1170
- let maxMessageSizeBytes : number ;
1160
+ let models : AnyClientBulkWriteModel [ ] ;
1161
+ const writes : CommandStartedEvent [ ] = [ ] ;
1171
1162
1172
1163
beforeEach ( async function ( ) {
1173
1164
await internalClient
1174
1165
. db ( 'db' )
1175
1166
. collection ( 'coll' )
1176
1167
. drop ( )
1177
1168
. catch ( ( ) => null ) ;
1178
- await internalClient . db ( 'admin' ) . command ( failpoint ) ;
1179
-
1180
- const hello = await internalClient . db ( 'admin' ) . command ( { hello : 1 } ) ;
1181
- maxBsonObjectSize = hello . maxBsonObjectSize ;
1182
- maxMessageSizeBytes = hello . maxMessageSizeBytes ;
1183
-
1184
- client = this . configuration . newClient ( { timeoutMS : 2000 , monitorCommands : true } ) ;
1185
- } ) ;
1169
+ await internalClient . db ( 'admin' ) . command ( < FailPoint > {
1170
+ configureFailPoint : 'failCommand' ,
1171
+ mode : {
1172
+ times : 2
1173
+ } ,
1174
+ data : {
1175
+ failCommands : [ 'bulkWrite' ] ,
1176
+ blockConnection : true ,
1177
+ blockTimeMS : 1010
1178
+ }
1179
+ } ) ;
1186
1180
1187
- it ( 'performs two bulkWrites which fail to complete before 2000 ms' , async function ( ) {
1188
- const writes = [ ] ;
1189
- client . on ( 'commandStarted' , ev => writes . push ( ev ) ) ;
1181
+ const { maxBsonObjectSize, maxMessageSizeBytes } = await this . configuration . hello ( ) ;
1190
1182
1191
1183
const length = maxMessageSizeBytes / maxBsonObjectSize + 1 ;
1192
- const models = Array . from ( { length } , ( ) => ( {
1184
+ models = Array . from ( { length } , ( ) => ( {
1193
1185
namespace : 'db.coll' ,
1194
1186
name : 'insertOne' as const ,
1195
1187
document : { a : 'b' . repeat ( maxBsonObjectSize - 500 ) }
1196
1188
} ) ) ;
1197
1189
1190
+ client = this . configuration . newClient ( { timeoutMS : 2000 , monitorCommands : true } ) ;
1191
+ client . on ( 'commandStarted' , filterForCommands ( 'bulkWrite' , writes ) ) ;
1192
+ } ) ;
1193
+
1194
+ it ( 'performs two bulkWrites which fail to complete before 2000 ms' , async function ( ) {
1198
1195
const error = await client . bulkWrite ( models ) . catch ( error => error ) ;
1199
1196
1200
1197
expect ( error , error . stack ) . to . be . instanceOf ( MongoOperationTimeoutError ) ;
0 commit comments