Skip to content

Commit fd5a174

Browse files
committed
test: ensure transaction test waits for result
1 parent 664cfe9 commit fd5a174

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

test/integration/transactions/transactions.prose.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { expect } from 'chai';
22
import * as semver from 'semver';
33

4-
import { type MongoClient } from '../../mongodb';
4+
import { type MongoClient, type ObjectId } from '../../mongodb';
55

66
const metadata: MongoDBMetadataUI = {
77
requires: {
@@ -51,16 +51,18 @@ describe('Transactions Spec Prose', function () {
5151
'1.0 Write concern not inherited from collection object inside transaction.',
5252
metadata,
5353
async () => {
54+
let _id: ObjectId;
55+
const collection = client.db().collection('txn-test', { writeConcern: { w: 0 } });
56+
5457
await client.withSession(async session => {
5558
session.startTransaction();
56-
57-
const collection = client.db().collection('txn-test', { writeConcern: { w: 0 } });
58-
59-
await collection.insertOne({ n: 1 }, { session });
60-
59+
_id = (await collection.insertOne({ n: 1 }, { session })).insertedId;
6160
await session.commitTransaction();
6261
});
6362

63+
// keep finding until we get a result, otherwise the test will timeout.
64+
while ((await collection.findOne({ _id })) == null);
65+
6466
const insertStarted = started.find(ev => ev.commandName === 'insert');
6567
expect(insertStarted).to.not.have.nested.property('command.writeConcern');
6668

0 commit comments

Comments
 (0)