|
1 | 1 | import { expect } from 'chai'; |
2 | 2 |
|
3 | | -import { |
4 | | - ClientSession, |
5 | | - type Collection, |
6 | | - type CommandStartedEvent, |
7 | | - type MongoClient, |
8 | | - MongoInvalidArgumentError, |
9 | | - MongoNetworkError, |
10 | | - type ServerSessionPool |
11 | | -} from '../../mongodb'; |
| 3 | +import { type CommandStartedEvent } from '../../../src/cmap/command_monitoring_events'; |
| 4 | +import { type Collection } from '../../../src/collection'; |
| 5 | +import { MongoInvalidArgumentError, MongoNetworkError } from '../../../src/error'; |
| 6 | +import { type MongoClient } from '../../../src/mongo_client'; |
| 7 | +import { ClientSession, type ServerSessionPool } from '../../../src/sessions'; |
12 | 8 | import { type FailCommandFailPoint } from '../../tools/utils'; |
13 | 9 |
|
14 | 10 | describe('Transactions', function () { |
@@ -55,18 +51,14 @@ describe('Transactions', function () { |
55 | 51 | metadata: { |
56 | 52 | requires: { topology: ['replicaset', 'sharded'] } |
57 | 53 | }, |
58 | | - test: function (done) { |
| 54 | + test: async function () { |
59 | 55 | function fnThatReturnsBadPromise() { |
60 | 56 | return Promise.reject(); |
61 | 57 | } |
62 | 58 |
|
63 | | - session |
64 | | - .withTransaction(fnThatReturnsBadPromise) |
65 | | - .then(() => done(Error('Expected error'))) |
66 | | - .catch(err => { |
67 | | - expect(err).to.equal(undefined); |
68 | | - session.endSession(done); |
69 | | - }); |
| 59 | + const err = await session.withTransaction(fnThatReturnsBadPromise).catch(err => err); |
| 60 | + expect(err).to.equal(undefined); |
| 61 | + await session.endSession(); |
70 | 62 | } |
71 | 63 | }); |
72 | 64 |
|
@@ -179,23 +171,21 @@ describe('Transactions', function () { |
179 | 171 | describe('startTransaction', function () { |
180 | 172 | it('should not error if transactions are supported', { |
181 | 173 | metadata: { requires: { topology: ['sharded'] } }, |
182 | | - test: function (done) { |
| 174 | + test: async function () { |
183 | 175 | const configuration = this.configuration; |
184 | 176 | const client = configuration.newClient(configuration.url()); |
185 | 177 |
|
186 | | - client.connect(err => { |
187 | | - expect(err).to.not.exist; |
| 178 | + await client.connect(); |
188 | 179 |
|
189 | | - const session = client.startSession(); |
190 | | - const db = client.db(configuration.db); |
191 | | - const coll = db.collection('transaction_error_test'); |
192 | | - coll.insertOne({ a: 1 }, err => { |
193 | | - expect(err).to.not.exist; |
194 | | - expect(() => session.startTransaction()).to.not.throw(); |
| 180 | + const session = client.startSession(); |
| 181 | + const db = client.db(configuration.db); |
| 182 | + const coll = db.collection('transaction_error_test'); |
| 183 | + await coll.insertOne({ a: 1 }); |
| 184 | + session.startTransaction(); |
195 | 185 |
|
196 | | - session.abortTransaction(() => session.endSession(() => client.close(done))); |
197 | | - }); |
198 | | - }); |
| 186 | + await session.abortTransaction(); |
| 187 | + await session.endSession(); |
| 188 | + await client.close(); |
199 | 189 | } |
200 | 190 | }); |
201 | 191 | }); |
|
0 commit comments