Skip to content

Commit a082436

Browse files
committed
test: fix metadata
1 parent 219b506 commit a082436

File tree

1 file changed

+89
-96
lines changed

1 file changed

+89
-96
lines changed

test/integration/client-side-operations-timeout/client_side_operations_timeout.prose.test.ts

Lines changed: 89 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -598,6 +598,9 @@ describe('CSOT spec prose tests', function () {
598598
});
599599

600600
describe('9. endSession', () => {
601+
const metadata: MongoDBMetadataUI = {
602+
requires: { mongodb: '>=4.4', topology: ['replicaset', 'sharded'] }
603+
};
601604
/**
602605
* This test MUST only be run against replica sets and sharded clusters with server version 4.4 or higher. It MUST be
603606
* run three times: once with the timeout specified via the MongoClient `timeoutMS` option, once with the timeout
@@ -643,15 +646,6 @@ describe('CSOT spec prose tests', function () {
643646
this.skip();
644647
}
645648

646-
if (
647-
!['Sharded', 'ReplicaSetWithPrimary', 'ReplicaSetNoPrimary'].includes(
648-
this.configuration.topologyType
649-
)
650-
) {
651-
this.skipReason = 'Requires replicaset or sharded clusters';
652-
this.skip();
653-
}
654-
655649
const internalClient = this.configuration.newClient();
656650
await internalClient
657651
.db('db')
@@ -674,7 +668,7 @@ describe('CSOT spec prose tests', function () {
674668
});
675669

676670
describe('when timeoutMS is provided to the client', () => {
677-
it('throws a timeout error from endSession', async function () {
671+
it('throws a timeout error from endSession', metadata, async function () {
678672
client = this.configuration.newClient({ timeoutMS: 50, monitorCommands: true });
679673
const coll = client.db('db').collection('coll');
680674
const session = client.startSession();
@@ -686,7 +680,7 @@ describe('CSOT spec prose tests', function () {
686680
});
687681

688682
describe('when defaultTimeoutMS is provided to startSession', () => {
689-
it('throws a timeout error from endSession', async function () {
683+
it('throws a timeout error from endSession', metadata, async function () {
690684
client = this.configuration.newClient();
691685
const coll = client.db('db').collection('coll');
692686
const session = client.startSession({ defaultTimeoutMS: 50 });
@@ -698,7 +692,7 @@ describe('CSOT spec prose tests', function () {
698692
});
699693

700694
describe('when timeoutMS is provided to endSession', () => {
701-
it('throws a timeout error from endSession', async function () {
695+
it('throws a timeout error from endSession', metadata, async function () {
702696
client = this.configuration.newClient();
703697
const coll = client.db('db').collection('coll');
704698
const session = client.startSession();
@@ -710,99 +704,98 @@ describe('CSOT spec prose tests', function () {
710704
});
711705
});
712706

713-
describe(
714-
'10. Convenient Transactions',
715-
{ requires: { topology: ['replicaset', 'sharded', 'load-balanced'] } },
716-
() => {
717-
/** Tests in this section MUST only run against replica sets and sharded clusters with server versions 4.4 or higher. */
707+
describe('10. Convenient Transactions', () => {
708+
/** Tests in this section MUST only run against replica sets and sharded clusters with server versions 4.4 or higher. */
709+
const metadata: MongoDBMetadataUI = {
710+
requires: { topology: ['replicaset', 'sharded', 'load-balanced'] }
711+
};
718712

719-
describe('when an operation fails inside withTransaction callback', () => {
720-
/**
721-
* 1. Using `internalClient`, drop the `db.coll` collection.
722-
* 1. Using `internalClient`, set the following fail point:
723-
* ```js
724-
* {
725-
* configureFailPoint: failCommand,
726-
* mode: { times: 2 },
727-
* data: {
728-
* failCommands: ["insert", "abortTransaction"],
729-
* blockConnection: true,
730-
* blockTimeMS: 15
731-
* }
732-
* }
733-
* ```
734-
* 1. Create a new MongoClient (referred to as `client`) configured with `timeoutMS=10` and an explicit ClientSession derived from that MongoClient (referred to as `session`).
735-
* 1. Using `session`, execute a `withTransaction` operation with the following callback:
736-
* ```js
737-
* function callback() {
738-
* coll = client.database("db").collection("coll")
739-
* coll.insert_one({ _id: 1 }, session=session)
740-
* }
741-
* ```
742-
* 1. Expect the previous `withTransaction` call to fail with a timeout error.
743-
* 1. Verify that the following events were published during the `withTransaction` call:
744-
* 1. `command_started` and `command_failed` events for an `insert` command.
745-
* 1. `command_started` and `command_failed` events for an `abortTransaction` command.
746-
*/
713+
describe('when an operation fails inside withTransaction callback', () => {
714+
/**
715+
* 1. Using `internalClient`, drop the `db.coll` collection.
716+
* 1. Using `internalClient`, set the following fail point:
717+
* ```js
718+
* {
719+
* configureFailPoint: failCommand,
720+
* mode: { times: 2 },
721+
* data: {
722+
* failCommands: ["insert", "abortTransaction"],
723+
* blockConnection: true,
724+
* blockTimeMS: 15
725+
* }
726+
* }
727+
* ```
728+
* 1. Create a new MongoClient (referred to as `client`) configured with `timeoutMS=10` and an explicit ClientSession derived from that MongoClient (referred to as `session`).
729+
* 1. Using `session`, execute a `withTransaction` operation with the following callback:
730+
* ```js
731+
* function callback() {
732+
* coll = client.database("db").collection("coll")
733+
* coll.insert_one({ _id: 1 }, session=session)
734+
* }
735+
* ```
736+
* 1. Expect the previous `withTransaction` call to fail with a timeout error.
737+
* 1. Verify that the following events were published during the `withTransaction` call:
738+
* 1. `command_started` and `command_failed` events for an `insert` command.
739+
* 1. `command_started` and `command_failed` events for an `abortTransaction` command.
740+
*/
747741

748-
const failpoint: FailPoint = {
749-
configureFailPoint: 'failCommand',
750-
mode: { times: 2 },
751-
data: {
752-
failCommands: ['insert', 'abortTransaction'],
753-
blockConnection: true,
754-
blockTimeMS: 60
755-
}
756-
};
742+
const failpoint: FailPoint = {
743+
configureFailPoint: 'failCommand',
744+
mode: { times: 2 },
745+
data: {
746+
failCommands: ['insert', 'abortTransaction'],
747+
blockConnection: true,
748+
blockTimeMS: 60
749+
}
750+
};
751+
752+
beforeEach(async function () {
753+
if (!semver.satisfies(this.configuration.version, '>=4.4')) {
754+
this.skipReason = 'Requires server version 4.4+';
755+
this.skip();
756+
}
757+
const internalClient = this.configuration.newClient();
758+
await internalClient
759+
.db('db')
760+
.collection('coll')
761+
.drop()
762+
.catch(() => null);
763+
await internalClient.db('admin').command(failpoint);
764+
await internalClient.close();
765+
});
757766

758-
beforeEach(async function () {
759-
if (!semver.satisfies(this.configuration.version, '>=4.4')) {
760-
this.skipReason = 'Requires server version 4.4+';
761-
this.skip();
762-
}
767+
let client: MongoClient;
768+
769+
afterEach(async function () {
770+
if (semver.satisfies(this.configuration.version, '>=4.4')) {
763771
const internalClient = this.configuration.newClient();
764-
await internalClient
765-
.db('db')
766-
.collection('coll')
767-
.drop()
768-
.catch(() => null);
769-
await internalClient.db('admin').command(failpoint);
772+
await internalClient.db('admin').command({ ...failpoint, mode: 'off' });
770773
await internalClient.close();
771-
});
772-
773-
let client: MongoClient;
774-
775-
afterEach(async function () {
776-
if (semver.satisfies(this.configuration.version, '>=4.4')) {
777-
const internalClient = this.configuration.newClient();
778-
await internalClient.db('admin').command({ ...failpoint, mode: 'off' });
779-
await internalClient.close();
780-
}
781-
await client?.close();
782-
});
774+
}
775+
await client?.close();
776+
});
783777

784-
it('timeoutMS is refreshed for abortTransaction', async function () {
785-
const commandsFailed = [];
778+
it('timeoutMS is refreshed for abortTransaction', metadata, async function () {
779+
const commandsFailed = [];
786780

787-
client = this.configuration
788-
.newClient({ timeoutMS: 50, monitorCommands: true })
789-
.on('commandFailed', e => commandsFailed.push(e));
781+
client = this.configuration
782+
.newClient({ timeoutMS: 50, monitorCommands: true })
783+
.on('commandFailed', e => commandsFailed.push(e));
790784

791-
const coll = client.db('db').collection('coll');
785+
const coll = client.db('db').collection('coll');
792786

793-
const error = await client
794-
.withSession(async session =>
795-
session.withTransaction(async session => await coll.insertOne({ x: 1 }, { session }))
796-
)
797-
.catch(error => error);
787+
const error = await client
788+
.withSession(async session =>
789+
session.withTransaction(async session => await coll.insertOne({ x: 1 }, { session }))
790+
)
791+
.catch(error => error);
798792

799-
expect(error).to.be.instanceOf(MongoOperationTimeoutError);
800-
expect(commandsFailed.map(e => e.commandName)).to.deep.equal([
801-
'insert',
802-
'abortTransaction'
803-
]);
804-
});
793+
expect(error).to.be.instanceOf(MongoOperationTimeoutError);
794+
expect(commandsFailed.map(e => e.commandName)).to.deep.equal([
795+
'insert',
796+
'abortTransaction'
797+
]);
805798
});
806-
}
807-
);
799+
});
800+
});
808801
});

0 commit comments

Comments
 (0)