Skip to content

Commit efffb50

Browse files
authored
chore: use return await syntax in UTR to jump to throwing operation (#4514)
1 parent 0d7f464 commit efffb50

File tree

1 file changed

+52
-47
lines changed

1 file changed

+52
-47
lines changed

test/tools/unified-spec-runner/operations.ts

+52-47
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ operations.set('aggregate', async ({ entities, operation }) => {
5858
}
5959
const { pipeline, ...opts } = operation.arguments!;
6060
const cursor = dbOrCollection.aggregate(pipeline, opts);
61-
return cursor.toArray();
61+
return await cursor.toArray();
6262
});
6363

6464
operations.set('assertCollectionExists', async ({ operation, client }) => {
@@ -196,7 +196,7 @@ operations.set('assertNumberConnectionsCheckedOut', async ({ entities, operation
196196
operations.set('bulkWrite', async ({ entities, operation }) => {
197197
const collection = entities.getEntity('collection', operation.object);
198198
const { requests, ...opts } = operation.arguments!;
199-
return collection.bulkWrite(requests, opts);
199+
return await collection.bulkWrite(requests, opts);
200200
});
201201

202202
operations.set('clientBulkWrite', async ({ entities, operation }) => {
@@ -206,7 +206,7 @@ operations.set('clientBulkWrite', async ({ entities, operation }) => {
206206
const name = Object.keys(model)[0];
207207
return { name: name, ...model[name] };
208208
});
209-
return client.bulkWrite(bulkWriteModels, opts);
209+
return await client.bulkWrite(bulkWriteModels, opts);
210210
});
211211

212212
// The entity exists for the name but can potentially have the wrong
@@ -303,7 +303,7 @@ operations.set('dropIndex', async ({ entities, operation }) => {
303303
operations.set('deleteOne', async ({ entities, operation }) => {
304304
const collection = entities.getEntity('collection', operation.object);
305305
const { filter, ...options } = operation.arguments!;
306-
return collection.deleteOne(filter, options);
306+
return await collection.deleteOne(filter, options);
307307
});
308308

309309
operations.set('dropCollection', async ({ entities, operation }) => {
@@ -323,17 +323,17 @@ operations.set('dropCollection', async ({ entities, operation }) => {
323323

324324
operations.set('drop', async ({ entities, operation }) => {
325325
const bucket = entities.getEntity('bucket', operation.object);
326-
return bucket.drop(operation.arguments);
326+
return await bucket.drop(operation.arguments);
327327
});
328328

329329
operations.set('dropIndexes', async ({ entities, operation }) => {
330330
const collection = entities.getEntity('collection', operation.object);
331-
return collection.dropIndexes(operation.arguments);
331+
return await collection.dropIndexes(operation.arguments);
332332
});
333333

334334
operations.set('endSession', async ({ entities, operation }) => {
335335
const session = entities.getEntity('session', operation.object);
336-
return session.endSession();
336+
return await session.endSession();
337337
});
338338

339339
operations.set('find', async ({ entities, operation }) => {
@@ -355,36 +355,36 @@ operations.set('find', async ({ entities, operation }) => {
355355
default:
356356
break;
357357
}
358-
return queryable.find(filter, opts).toArray();
358+
return await queryable.find(filter, opts).toArray();
359359
});
360360

361361
operations.set('findOne', async ({ entities, operation }) => {
362362
const collection = entities.getEntity('collection', operation.object);
363363
const { filter, ...opts } = operation.arguments!;
364-
return collection.findOne(filter, opts);
364+
return await collection.findOne(filter, opts);
365365
});
366366

367367
operations.set('findOneAndReplace', async ({ entities, operation }) => {
368368
const collection = entities.getEntity('collection', operation.object);
369369
const { filter, replacement, ...opts } = operation.arguments!;
370-
return collection.findOneAndReplace(filter, replacement, translateOptions(opts));
370+
return await collection.findOneAndReplace(filter, replacement, translateOptions(opts));
371371
});
372372

373373
operations.set('findOneAndUpdate', async ({ entities, operation }) => {
374374
const collection = entities.getEntity('collection', operation.object);
375375
const { filter, update, ...opts } = operation.arguments!;
376-
return collection.findOneAndUpdate(filter, update, translateOptions(opts));
376+
return await collection.findOneAndUpdate(filter, update, translateOptions(opts));
377377
});
378378

379379
operations.set('findOneAndDelete', async ({ entities, operation }) => {
380380
const collection = entities.getEntity('collection', operation.object);
381381
const { filter, ...opts } = operation.arguments!;
382-
return collection.findOneAndDelete(filter, opts);
382+
return await collection.findOneAndDelete(filter, opts);
383383
});
384384

385385
operations.set('failPoint', async ({ entities, operation }) => {
386386
const client = entities.getEntity('client', operation.arguments!.client);
387-
return entities.failPoints.enableFailPoint(client, operation.arguments!.failPoint);
387+
return await entities.failPoints.enableFailPoint(client, operation.arguments!.failPoint);
388388
});
389389

390390
operations.set('insertOne', async ({ entities, operation }) => {
@@ -408,23 +408,23 @@ operations.set('insertMany', async ({ entities, operation }) => {
408408
const clonedDocuments = documents.map(doc => {
409409
return { ...doc };
410410
});
411-
return collection.insertMany(clonedDocuments, opts);
411+
return await collection.insertMany(clonedDocuments, opts);
412412
});
413413

414414
operations.set('iterateUntilDocumentOrError', async ({ entities, operation }) => {
415415
const iterable = entities.getChangeStreamOrCursor(operation.object);
416-
return iterable.next();
416+
return await iterable.next();
417417
});
418418

419419
operations.set('iterateOnce', async ({ entities, operation }) => {
420420
const iterable = entities.getChangeStreamOrCursor(operation.object);
421-
return iterable.tryNext();
421+
return await iterable.tryNext();
422422
});
423423

424424
operations.set('listCollections', async ({ entities, operation }) => {
425425
const db = entities.getEntity('db', operation.object);
426426
const { filter, ...opts } = operation.arguments ?? { filter: {} };
427-
return db.listCollections(filter, opts).toArray();
427+
return await db.listCollections(filter, opts).toArray();
428428
});
429429

430430
operations.set('listCollectionNames', async ({ entities, operation }) => {
@@ -436,7 +436,7 @@ operations.set('listCollectionNames', async ({ entities, operation }) => {
436436

437437
operations.set('listDatabases', async ({ entities, operation }) => {
438438
const client = entities.getEntity('client', operation.object);
439-
return client.db().admin().listDatabases(operation.arguments!);
439+
return await client.db().admin().listDatabases(operation.arguments!);
440440
});
441441

442442
operations.set('listDatabaseNames', async ({ entities, operation }) => {
@@ -447,7 +447,7 @@ operations.set('listDatabaseNames', async ({ entities, operation }) => {
447447

448448
operations.set('listIndexes', async ({ entities, operation }) => {
449449
const collection = entities.getEntity('collection', operation.object);
450-
return collection.listIndexes(operation.arguments!).toArray();
450+
return await collection.listIndexes(operation.arguments!).toArray();
451451
});
452452

453453
operations.set('listIndexNames', async ({ entities, operation }) => {
@@ -532,7 +532,7 @@ operations.set('loop', async ({ entities, operation, client, testConfig }) => {
532532
operations.set('replaceOne', async ({ entities, operation }) => {
533533
const collection = entities.getEntity('collection', operation.object);
534534
const { filter, replacement, ...opts } = operation.arguments!;
535-
return collection.replaceOne(filter, replacement, opts);
535+
return await collection.replaceOne(filter, replacement, opts);
536536
});
537537

538538
operations.set('startTransaction', async ({ entities, operation }) => {
@@ -553,7 +553,7 @@ operations.set('targetedFailPoint', async ({ entities, operation }) => {
553553
operations.set('delete', async ({ entities, operation }) => {
554554
const bucket = entities.getEntity('bucket', operation.object);
555555
const { id, ...opts } = operation.arguments;
556-
return bucket.delete(id, opts);
556+
return await bucket.delete(id, opts);
557557
});
558558

559559
operations.set('download', async ({ entities, operation }) => {
@@ -765,30 +765,30 @@ operations.set('withTransaction', async ({ entities, operation, client, testConf
765765
operations.set('count', async ({ entities, operation }) => {
766766
const collection = entities.getEntity('collection', operation.object);
767767
const { filter, ...opts } = operation.arguments!;
768-
return collection.count(filter, opts);
768+
return await collection.count(filter, opts);
769769
});
770770

771771
operations.set('countDocuments', async ({ entities, operation }) => {
772772
const collection = entities.getEntity('collection', operation.object);
773773
const { filter, ...opts } = operation.arguments!;
774-
return collection.countDocuments(filter, opts);
774+
return await collection.countDocuments(filter, opts);
775775
});
776776

777777
operations.set('deleteMany', async ({ entities, operation }) => {
778778
const collection = entities.getEntity('collection', operation.object);
779779
const { filter, ...opts } = operation.arguments!;
780-
return collection.deleteMany(filter, opts);
780+
return await collection.deleteMany(filter, opts);
781781
});
782782

783783
operations.set('distinct', async ({ entities, operation }) => {
784784
const collection = entities.getEntity('collection', operation.object);
785785
const { fieldName, filter, ...opts } = operation.arguments!;
786-
return collection.distinct(fieldName, filter, opts);
786+
return await collection.distinct(fieldName, filter, opts);
787787
});
788788

789789
operations.set('estimatedDocumentCount', async ({ entities, operation }) => {
790790
const collection = entities.getEntity('collection', operation.object);
791-
return collection.estimatedDocumentCount(operation.arguments!);
791+
return await collection.estimatedDocumentCount(operation.arguments!);
792792
});
793793

794794
operations.set('runCommand', async ({ entities, operation }: OperationFunctionParams) => {
@@ -804,7 +804,7 @@ operations.set('runCommand', async ({ entities, operation }: OperationFunctionPa
804804
timeoutMS: operation.arguments.timeoutMS
805805
};
806806

807-
return db.command(command, options);
807+
return await db.command(command, options);
808808
});
809809

810810
operations.set('runCursorCommand', async ({ entities, operation }: OperationFunctionParams) => {
@@ -821,7 +821,7 @@ operations.set('runCursorCommand', async ({ entities, operation }: OperationFunc
821821
if (!Number.isNaN(+opts.maxTimeMS)) cursor.setMaxTimeMS(+opts.maxTimeMS);
822822
if (opts.comment !== undefined) cursor.setComment(opts.comment);
823823

824-
return cursor.toArray();
824+
return await cursor.toArray();
825825
});
826826

827827
operations.set('createCommandCursor', async ({ entities, operation }: OperationFunctionParams) => {
@@ -861,13 +861,13 @@ operations.set('createCommandCursor', async ({ entities, operation }: OperationF
861861
operations.set('updateMany', async ({ entities, operation }) => {
862862
const collection = entities.getEntity('collection', operation.object);
863863
const { filter, update, ...options } = operation.arguments!;
864-
return collection.updateMany(filter, update, options);
864+
return await collection.updateMany(filter, update, options);
865865
});
866866

867867
operations.set('updateOne', async ({ entities, operation }) => {
868868
const collection = entities.getEntity('collection', operation.object);
869869
const { filter, update, ...options } = operation.arguments!;
870-
return collection.updateOne(filter, update, options);
870+
return await collection.updateOne(filter, update, options);
871871
});
872872

873873
operations.set('rename', async ({ entities, operation }) => {
@@ -880,7 +880,7 @@ operations.set('rename', async ({ entities, operation }) => {
880880

881881
if (entity instanceof Collection) {
882882
const { to, ...options } = operation.arguments!;
883-
return entity.rename(to, options);
883+
return await entity.rename(to, options);
884884
}
885885

886886
try {
@@ -891,7 +891,7 @@ operations.set('rename', async ({ entities, operation }) => {
891891

892892
if (entity instanceof GridFSBucket) {
893893
const { id, newFilename, ...opts } = operation.arguments!;
894-
return entity.rename(id, newFilename, opts as any);
894+
return await entity.rename(id, newFilename, opts as any);
895895
}
896896

897897
expect.fail(`No collection or bucket with name '${operation.object}' found`);
@@ -901,7 +901,7 @@ operations.set('createDataKey', async ({ entities, operation }) => {
901901
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
902902
const { kmsProvider, opts } = operation.arguments!;
903903

904-
return clientEncryption.createDataKey(kmsProvider, opts);
904+
return await clientEncryption.createDataKey(kmsProvider, opts);
905905
});
906906

907907
operations.set('rewrapManyDataKey', async ({ entities, operation }) => {
@@ -915,85 +915,85 @@ operations.set('deleteKey', async ({ entities, operation }) => {
915915
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
916916
const { id } = operation.arguments!;
917917

918-
return clientEncryption.deleteKey(id);
918+
return await clientEncryption.deleteKey(id);
919919
});
920920

921921
operations.set('getKey', async ({ entities, operation }) => {
922922
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
923923
const { id } = operation.arguments!;
924924

925-
return clientEncryption.getKey(id);
925+
return await clientEncryption.getKey(id);
926926
});
927927

928928
operations.set('getKeys', async ({ entities, operation }) => {
929929
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
930930

931-
return clientEncryption.getKeys().toArray();
931+
return await clientEncryption.getKeys().toArray();
932932
});
933933

934934
operations.set('addKeyAltName', async ({ entities, operation }) => {
935935
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
936936
const { id, keyAltName } = operation.arguments!;
937937

938-
return clientEncryption.addKeyAltName(id, keyAltName);
938+
return await clientEncryption.addKeyAltName(id, keyAltName);
939939
});
940940

941941
operations.set('removeKeyAltName', async ({ entities, operation }) => {
942942
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
943943
const { id, keyAltName } = operation.arguments!;
944944

945-
return clientEncryption.removeKeyAltName(id, keyAltName);
945+
return await clientEncryption.removeKeyAltName(id, keyAltName);
946946
});
947947

948948
operations.set('getKeyByAltName', async ({ entities, operation }) => {
949949
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
950950
const { keyAltName } = operation.arguments ?? {};
951951

952-
return clientEncryption.getKeyByAltName(keyAltName);
952+
return await clientEncryption.getKeyByAltName(keyAltName);
953953
});
954954

955955
operations.set('encrypt', async ({ entities, operation }) => {
956956
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
957957
const { value, opts } = operation.arguments ?? {};
958958

959-
return clientEncryption.encrypt(value, opts);
959+
return await clientEncryption.encrypt(value, opts);
960960
});
961961

962962
operations.set('decrypt', async ({ entities, operation }) => {
963963
const clientEncryption = entities.getEntity('clientEncryption', operation.object);
964964
const { value } = operation.arguments ?? {};
965965

966-
return clientEncryption.decrypt(value);
966+
return await clientEncryption.decrypt(value);
967967
});
968968

969969
operations.set('listSearchIndexes', async ({ entities, operation }) => {
970970
const collection: Collection<any> = entities.getEntity('collection', operation.object);
971971
const { name, aggregationOptions } = operation.arguments ?? {};
972-
return collection.listSearchIndexes(name, aggregationOptions).toArray();
972+
return await collection.listSearchIndexes(name, aggregationOptions).toArray();
973973
});
974974

975975
operations.set('dropSearchIndex', async ({ entities, operation }) => {
976976
const collection: Collection<any> = entities.getEntity('collection', operation.object);
977977
const { name } = operation.arguments ?? {};
978-
return collection.dropSearchIndex(name);
978+
return await collection.dropSearchIndex(name);
979979
});
980980

981981
operations.set('updateSearchIndex', async ({ entities, operation }) => {
982982
const collection: Collection<any> = entities.getEntity('collection', operation.object);
983983
const { name, definition } = operation.arguments ?? {};
984-
return collection.updateSearchIndex(name, definition);
984+
return await collection.updateSearchIndex(name, definition);
985985
});
986986

987987
operations.set('createSearchIndex', async ({ entities, operation }) => {
988988
const collection: Collection<any> = entities.getEntity('collection', operation.object);
989989
const { model } = operation.arguments ?? {};
990-
return collection.createSearchIndex(model);
990+
return await collection.createSearchIndex(model);
991991
});
992992

993993
operations.set('createSearchIndexes', async ({ entities, operation }) => {
994994
const collection: Collection<any> = entities.getEntity('collection', operation.object);
995995
const { models } = operation.arguments ?? {};
996-
return collection.createSearchIndexes(models);
996+
return await collection.createSearchIndexes(models);
997997
});
998998

999999
operations.set('modifyCollection', async ({ entities, operation }) => {
@@ -1002,9 +1002,14 @@ operations.set('modifyCollection', async ({ entities, operation }) => {
10021002
collMod: operation.arguments?.collection,
10031003
validator: operation.arguments?.validator
10041004
};
1005-
return db.command(command, {});
1005+
return await db.command(command, {});
10061006
});
10071007

1008+
// make function name appear in stack trace
1009+
operations.forEach((fn, name) =>
1010+
Object.defineProperty(fn, 'name', { value: name, configurable: true })
1011+
);
1012+
10081013
export async function executeOperationAndCheck(
10091014
operation: OperationDescription,
10101015
entities: EntitiesMap,

0 commit comments

Comments
 (0)