Skip to content

Commit

Permalink
comments pt 2
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Jul 30, 2024
1 parent 8c75a58 commit d66d248
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .evergreen/config.in.yml
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ functions:
args:
- "${PROJECT_DIRECTORY}/.evergreen/run-resource-management.sh"

"check resource management smoke tests":
"check resource management feature integration":
- command: subprocess.exec
type: test
params:
Expand Down
6 changes: 3 additions & 3 deletions .evergreen/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ functions:
binary: bash
args:
- ${PROJECT_DIRECTORY}/.evergreen/run-resource-management.sh
check resource management smoke tests:
check resource management feature integration:
- command: subprocess.exec
type: test
params:
Expand Down Expand Up @@ -3508,7 +3508,7 @@ tasks:
- {key: NPM_VERSION, value: '9'}
- func: install dependencies
- func: check resource management
- name: test-explicit-resource-management-smoke-tests
- name: test-explicit-resource-management-feature-integration
tags:
- resource-management
commands:
Expand All @@ -3521,7 +3521,7 @@ tasks:
- {key: NODE_LTS_VERSION, value: latest}
- func: install dependencies
- func: bootstrap mongo-orchestration
- func: check resource management smoke tests
- func: check resource management feature integration
- name: check-types-typescript-next-node-types-20.14.10
tags:
- check-types-typescript-next
Expand Down
4 changes: 2 additions & 2 deletions .evergreen/generate_evergreen_tasks.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ SINGLETON_TASKS.push(
]
},
{
name: 'test-explicit-resource-management-smoke-tests',
name: 'test-explicit-resource-management-feature-integration',
tags: ['resource-management'],
commands: [
updateExpansions({
Expand All @@ -527,7 +527,7 @@ SINGLETON_TASKS.push(
}),
{ func: 'install dependencies' },
{ func: 'bootstrap mongo-orchestration' },
{ func: 'check resource management smoke tests' }
{ func: 'check resource management feature integration' }
]
},
...Array.from(makeTypescriptTasks())
Expand Down
116 changes: 40 additions & 76 deletions test/explicit-resource-management/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@

import { expect } from 'chai';
import { describe, it } from 'mocha';
import { AbstractCursor, ChangeStream, ClientSession, GridFSBucket, MongoClient } from 'mongodb/lib/beta';
import * as sinon from 'sinon';
import { GridFSBucket, MongoClient } from 'mongodb/lib/beta';
import { Readable } from 'stream';
import { pipeline } from 'stream/promises';
import { setTimeout } from 'timers/promises';
Expand All @@ -17,104 +15,70 @@ async function setUpCollection(client: MongoClient) {
}

describe('explicit resource management smoke tests', function () {
const clientSpy = sinon.spy(MongoClient.prototype, Symbol.asyncDispose);
const cursorSpy = sinon.spy(AbstractCursor.prototype, Symbol.asyncDispose);
const endSessionSpy = sinon.spy(ClientSession.prototype, Symbol.asyncDispose);
const changeStreamSpy = sinon.spy(ChangeStream.prototype, Symbol.asyncDispose);
const readableSpy = sinon.spy(Readable.prototype, Symbol.asyncDispose);

afterEach(function () {
clientSpy.resetHistory();
cursorSpy.resetHistory();
endSessionSpy.resetHistory();
changeStreamSpy.resetHistory();
readableSpy.resetHistory();
});

describe('MongoClient', function () {
it('can be used with await-using syntax', async function () {
{
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();
}
expect(clientSpy.called).to.be.true;
expect(clientSpy.callCount).to.equal(1);
it('does not crash or error when used with await-using syntax', async function () {
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();
})
})

describe('Cursors', function () {
it('can be used with await-using syntax', async function () {
{
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

const collection = await setUpCollection(client);

await using cursor = collection.find();
await cursor.next();
await cursor.next();
await cursor.next();
}
expect(cursorSpy.callCount).to.equal(1);
it('does not crash or error when used with await-using syntax', async function () {
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

const collection = await setUpCollection(client);

await using cursor = collection.find();
await cursor.next();
await cursor.next();
await cursor.next();
})

describe('cursor streams', function() {
it('can be used with await-using syntax', async function() {
{
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();
it('does not crash or error when used with await-using syntax', async function() {
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

const collection = await setUpCollection(client);
const collection = await setUpCollection(client);

await using readable = collection.find().stream();
}
expect(readableSpy.callCount).to.equal(1);
await using readable = collection.find().stream();
})
})
})

describe('Sessions', function () {
it('can be used with await-using syntax', async function () {
{
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

await using session = client.startSession();
}
expect(endSessionSpy.callCount).to.equal(1);
it('does not crash or error when used with await-using syntax', async function () {
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

await using session = client.startSession();
})
})

describe('ChangeStreams', function () {
it('can be used with await-using syntax', async function () {
{
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

const collection = await setUpCollection(client);
await using cs = collection.watch();

setTimeout(1000).then(() => collection.insertOne({ name: 'bailey' }));
await cs.next();
}
expect(changeStreamSpy.callCount).to.equal(1);
it('does not crash or error when used with await-using syntax', async function () {
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

const collection = await setUpCollection(client);
await using cs = collection.watch();

setTimeout(1000).then(() => collection.insertOne({ name: 'bailey' }));
await cs.next();
})
});

describe('GridFSDownloadStream', function () {
it('can be used with await-using syntax', async function () {
{
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

const bucket = new GridFSBucket(client.db('foo'));
const uploadStream = bucket.openUploadStream('foo.txt')
await pipeline(Readable.from("AAAAAAA".split('')), uploadStream);
it('does not crash or error when used with await-using syntax', async function () {
await using client = new MongoClient(process.env.MONGODB_URI!);
await client.connect();

await using downloadStream = bucket.openDownloadStreamByName('foo.txt');
const bucket = new GridFSBucket(client.db('foo'));
const uploadStream = bucket.openUploadStream('foo.txt')
await pipeline(Readable.from("AAAAAAA".split('')), uploadStream);

}
expect(readableSpy.callCount).to.equal(1);
await using downloadStream = bucket.openDownloadStreamByName('foo.txt');
})
});
})
2 changes: 1 addition & 1 deletion test/manual/resource_management.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import * as sinon from 'sinon';

import { AbstractCursor, ChangeStream, ClientSession, MongoClient } from '../mongodb';

describe('Explicit Resource Management Tests', function () {
describe('Symbol.asyncDispose implementation tests', function () {
let client: MongoClient;

afterEach(async function () {
Expand Down

0 comments on commit d66d248

Please sign in to comment.