|
1 |
| -/* eslint-disable @typescript-eslint/no-empty-function */ |
2 | 1 | /* Anything javascript specific relating to timeouts */
|
| 2 | +import { expect } from 'chai'; |
| 3 | +import * as sinon from 'sinon'; |
3 | 4 |
|
4 |
| -describe.skip('CSOT driver tests', () => {}); |
| 5 | +import { |
| 6 | + type ClientSession, |
| 7 | + type Collection, |
| 8 | + type Db, |
| 9 | + type FindCursor, |
| 10 | + type MongoClient |
| 11 | +} from '../../mongodb'; |
| 12 | + |
| 13 | +describe('CSOT driver tests', () => { |
| 14 | + afterEach(() => { |
| 15 | + sinon.restore(); |
| 16 | + }); |
| 17 | + |
| 18 | + describe('timeoutMS inheritance', () => { |
| 19 | + let client: MongoClient; |
| 20 | + let db: Db; |
| 21 | + let coll: Collection; |
| 22 | + |
| 23 | + beforeEach(async function () { |
| 24 | + client = this.configuration.newClient(undefined, { timeoutMS: 100 }); |
| 25 | + db = client.db('test', { timeoutMS: 200 }); |
| 26 | + }); |
| 27 | + |
| 28 | + afterEach(async () => { |
| 29 | + await client?.close(); |
| 30 | + }); |
| 31 | + |
| 32 | + describe('when timeoutMS is provided on an operation', () => { |
| 33 | + beforeEach(() => { |
| 34 | + coll = db.collection('test', { timeoutMS: 300 }); |
| 35 | + }); |
| 36 | + |
| 37 | + describe('when in a session', () => { |
| 38 | + let cursor: FindCursor; |
| 39 | + let session: ClientSession; |
| 40 | + |
| 41 | + beforeEach(() => { |
| 42 | + session = client.startSession({ defaultTimeoutMS: 400 }); |
| 43 | + cursor = coll.find({}, { session, timeoutMS: 500 }); |
| 44 | + }); |
| 45 | + |
| 46 | + afterEach(async () => { |
| 47 | + await cursor?.close(); |
| 48 | + await session?.endSession(); |
| 49 | + await session.endSession(); |
| 50 | + }); |
| 51 | + |
| 52 | + it('throws an error', async () => { |
| 53 | + expect(cursor.cursorOptions).to.have.property('timeoutMS', 500); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('when not in a session', () => { |
| 58 | + let cursor: FindCursor; |
| 59 | + |
| 60 | + beforeEach(() => { |
| 61 | + db = client.db('test', { timeoutMS: 200 }); |
| 62 | + coll = db.collection('test', { timeoutMS: 300 }); |
| 63 | + cursor = coll.find({}, { timeoutMS: 400 }); |
| 64 | + }); |
| 65 | + |
| 66 | + afterEach(async () => { |
| 67 | + await cursor?.close(); |
| 68 | + }); |
| 69 | + |
| 70 | + it('overrides the value provided on the db', async () => { |
| 71 | + expect(cursor.cursorOptions).to.have.property('timeoutMS', 400); |
| 72 | + }); |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
| 76 | + describe('when timeoutMS is provided on a collection', () => { |
| 77 | + beforeEach(() => { |
| 78 | + db = client.db('test', { timeoutMS: 200 }); |
| 79 | + coll = db.collection('test', { timeoutMS: 300 }); |
| 80 | + }); |
| 81 | + |
| 82 | + it('overrides the value provided on the db', () => { |
| 83 | + expect(coll.s.options).to.have.property('timeoutMS', 300); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('when timeoutMS is provided on a db', () => { |
| 87 | + beforeEach(() => { |
| 88 | + db = client.db('test', { timeoutMS: 200 }); |
| 89 | + }); |
| 90 | + |
| 91 | + it('overrides the value provided on the client', () => { |
| 92 | + expect(db.s.options).to.have.property('timeoutMS', 200); |
| 93 | + }); |
| 94 | + }); |
| 95 | + }); |
| 96 | + }); |
| 97 | +}); |
0 commit comments