Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion test/integration/transactions/transactions.prose.test.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { type ObjectId } from 'bson';
import { expect } from 'chai';

import { type MongoClient, type ObjectId } from '../../mongodb';
import { type MongoClient } from '../../../src/mongo_client';

const metadata: MongoDBMetadataUI = {
requires: {
Expand Down
48 changes: 19 additions & 29 deletions test/integration/transactions/transactions.test.ts
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import { expect } from 'chai';

import {
ClientSession,
type Collection,
type CommandStartedEvent,
type MongoClient,
MongoInvalidArgumentError,
MongoNetworkError,
type ServerSessionPool
} from '../../mongodb';
import { type CommandStartedEvent } from '../../../src/cmap/command_monitoring_events';
import { type Collection } from '../../../src/collection';
import { MongoInvalidArgumentError, MongoNetworkError } from '../../../src/error';
import { type MongoClient } from '../../../src/mongo_client';
import { ClientSession, type ServerSessionPool } from '../../../src/sessions';
import { type FailCommandFailPoint } from '../../tools/utils';

describe('Transactions', function () {
Expand Down Expand Up @@ -55,18 +51,14 @@ describe('Transactions', function () {
metadata: {
requires: { topology: ['replicaset', 'sharded'] }
},
test: function (done) {
test: async function () {
function fnThatReturnsBadPromise() {
return Promise.reject();
}

session
.withTransaction(fnThatReturnsBadPromise)
.then(() => done(Error('Expected error')))
.catch(err => {
expect(err).to.equal(undefined);
session.endSession(done);
});
const err = await session.withTransaction(fnThatReturnsBadPromise).catch(err => err);
expect(err).to.equal(undefined);
await session.endSession();
}
});

Expand Down Expand Up @@ -179,23 +171,21 @@ describe('Transactions', function () {
describe('startTransaction', function () {
it('should not error if transactions are supported', {
metadata: { requires: { topology: ['sharded'] } },
test: function (done) {
test: async function () {
const configuration = this.configuration;
const client = configuration.newClient(configuration.url());

client.connect(err => {
expect(err).to.not.exist;
await client.connect();

const session = client.startSession();
const db = client.db(configuration.db);
const coll = db.collection('transaction_error_test');
coll.insertOne({ a: 1 }, err => {
expect(err).to.not.exist;
expect(() => session.startTransaction()).to.not.throw();
const session = client.startSession();
const db = client.db(configuration.db);
const coll = db.collection('transaction_error_test');
await coll.insertOne({ a: 1 });
session.startTransaction();

session.abortTransaction(() => session.endSession(() => client.close(done)));
});
});
await session.abortTransaction();
await session.endSession();
await client.close();
}
});
});
Expand Down