Skip to content

Commit f1da72b

Browse files
remove unnecessary tests
1 parent 025d952 commit f1da72b

File tree

1 file changed

+12
-223
lines changed

1 file changed

+12
-223
lines changed

test/explicit-resource-management/main.test.ts

Lines changed: 12 additions & 223 deletions
Original file line numberDiff line numberDiff line change
@@ -35,179 +35,58 @@ describe('explicit resource management feature integration tests', function () {
3535
})
3636
describe('MongoClient', function () {
3737
it('does not crash or error when used with await-using syntax', async function () {
38-
await using client = new MongoClient(process.env.MONGODB_URI!);
39-
await client.connect();
40-
})
41-
42-
it('always cleans up the client, regardless of thrown errors', async function () {
43-
const error = await (async () => {
38+
{
4439
await using client = new MongoClient(process.env.MONGODB_URI!);
4540
await client.connect();
46-
47-
throw new Error('error thrown');
48-
})().catch(e => e);
49-
50-
expect(error).to.match(/error thrown/);
41+
}
5142
expect(clientDisposeSpy.called).to.be.true;
52-
});
53-
54-
it('works if client is explicitly closed', async function () {
55-
const expected = await (async () => {
56-
await using client = new MongoClient(process.env.MONGODB_URI!);
57-
await client.connect();
58-
await client.close();
59-
60-
return 'not error';
61-
})();
62-
63-
expect(expected).to.equal('not error');
6443
})
6544
})
6645

6746
describe('Cursors', function () {
6847
it('does not crash or error when used with await-using syntax', async function () {
69-
await using client = new MongoClient(process.env.MONGODB_URI!);
70-
await client.connect();
71-
72-
const collection = await setUpCollection(client);
73-
74-
await using cursor = collection.find();
75-
await cursor.next();
76-
})
77-
78-
it('always cleans up the cursor, regardless of thrown errors', async function () {
79-
const error = await (async () => {
48+
{
8049
await using client = new MongoClient(process.env.MONGODB_URI!);
8150
await client.connect();
8251

8352
const collection = await setUpCollection(client);
8453

8554
await using cursor = collection.find();
8655
await cursor.next();
87-
88-
throw new Error('error thrown');
89-
})().catch(e => e);
90-
91-
expect(error).to.match(/error thrown/);
56+
}
9257
expect(cursorDisposeSpy.called).to.be.true;
93-
});
94-
95-
it('works if cursor is explicitly closed', async function () {
96-
const expected = await (async () => {
97-
await using client = new MongoClient(process.env.MONGODB_URI!);
98-
await client.connect();
99-
100-
const collection = await setUpCollection(client);
101-
102-
await using cursor = collection.find();
103-
await cursor.next();
104-
105-
await cursor.close();
106-
107-
return 'not error';
108-
})();
109-
110-
expect(expected).to.equal('not error');
11158
})
11259

11360
describe('cursor streams', function () {
11461
it('does not crash or error when used with await-using syntax', async function () {
115-
await using client = new MongoClient(process.env.MONGODB_URI!);
116-
await client.connect();
117-
118-
const collection = await setUpCollection(client);
119-
120-
await using readable = collection.find().stream();
121-
})
122-
123-
it('always cleans up the stream, regardless of thrown errors', async function () {
124-
const error = await (async () => {
62+
{
12563
await using client = new MongoClient(process.env.MONGODB_URI!);
12664
await client.connect();
12765

12866
const collection = await setUpCollection(client);
12967

13068
await using readable = collection.find().stream();
131-
132-
throw new Error('error thrown');
133-
})().catch(e => e);
134-
135-
expect(error).to.match(/error thrown/);
69+
}
13670
expect(readableDisposeSpy.called).to.be.true;
137-
});
138-
139-
it('works if stream is explicitly closed', async function () {
140-
const expected = await (async () => {
141-
await using client = new MongoClient(process.env.MONGODB_URI!);
142-
await client.connect();
143-
144-
const collection = await setUpCollection(client);
145-
146-
await using readable = collection.find().stream();
147-
148-
readable.destroy();
149-
150-
return 'not error';
151-
})();
152-
153-
expect(expected).to.equal('not error');
15471
})
155-
15672
})
15773
})
15874

15975
describe('Sessions', function () {
16076
it('does not crash or error when used with await-using syntax', async function () {
161-
await using client = new MongoClient(process.env.MONGODB_URI!);
162-
await client.connect();
163-
164-
await using session = client.startSession();
165-
})
166-
167-
it('always cleans up the session, regardless of thrown errors', async function () {
168-
const error = await (async () => {
77+
{
16978
await using client = new MongoClient(process.env.MONGODB_URI!);
17079
await client.connect();
17180

17281
await using session = client.startSession();
173-
174-
throw new Error('error thrown');
175-
})().catch(e => e);
176-
177-
expect(error).to.match(/error thrown/);
82+
}
17883
expect(sessionDisposeSpy.called).to.be.true;
179-
});
180-
181-
it('works if session is explicitly closed', async function () {
182-
const expected = await (async () => {
183-
await using client = new MongoClient(process.env.MONGODB_URI!);
184-
await client.connect();
185-
186-
await using session = client.startSession();
187-
188-
await session.endSession();
189-
190-
return 'not error';
191-
})();
192-
193-
expect(expected).to.equal('not error');
19484
})
19585
})
19686

19787
describe('ChangeStreams', function () {
19888
it('does not crash or error when used with await-using syntax', async function () {
199-
await using client = new MongoClient(process.env.MONGODB_URI!);
200-
await client.connect();
201-
202-
const collection = await setUpCollection(client);
203-
await using cs = collection.watch();
204-
205-
setTimeout(1000).then(() => collection.insertOne({ name: 'bailey' }));
206-
await cs.next();
207-
})
208-
209-
it('always cleans up the change stream, regardless of thrown errors', async function () {
210-
const error = await (async () => {
89+
{
21190
await using client = new MongoClient(process.env.MONGODB_URI!);
21291
await client.connect();
21392

@@ -216,47 +95,14 @@ describe('explicit resource management feature integration tests', function () {
21695

21796
setTimeout(1000).then(() => collection.insertOne({ name: 'bailey' }));
21897
await cs.next();
219-
220-
throw new Error('error thrown');
221-
})().catch(e => e);
222-
223-
expect(error).to.match(/error thrown/);
98+
}
22499
expect(changeStreamDisposeSpy.called).to.be.true;
225-
});
226-
227-
it('works if change stream is explicitly closed', async function () {
228-
const expected = await (async () => {
229-
await using client = new MongoClient(process.env.MONGODB_URI!);
230-
await client.connect();
231-
232-
const collection = await setUpCollection(client);
233-
await using cs = collection.watch();
234-
235-
setTimeout(1000).then(() => collection.insertOne({ name: 'bailey' }));
236-
await cs.next();
237-
await cs.close();
238-
239-
return 'not error';
240-
})();
241-
242-
expect(expected).to.equal('not error');
243100
})
244101
});
245102

246103
describe('GridFSDownloadStream', function () {
247104
it('does not crash or error when used with await-using syntax', async function () {
248-
await using client = new MongoClient(process.env.MONGODB_URI!);
249-
await client.connect();
250-
251-
const bucket = new GridFSBucket(client.db('foo'));
252-
const uploadStream = bucket.openUploadStream('foo.txt')
253-
await pipeline(Readable.from("AAAAAAA".split('')), uploadStream);
254-
255-
await using downloadStream = bucket.openDownloadStreamByName('foo.txt');
256-
})
257-
258-
it('always cleans up the stream, regardless of thrown errors', async function () {
259-
const error = await (async () => {
105+
{
260106
await using client = new MongoClient(process.env.MONGODB_URI!);
261107
await client.connect();
262108

@@ -265,66 +111,9 @@ describe('explicit resource management feature integration tests', function () {
265111
await pipeline(Readable.from("AAAAAAA".split('')), uploadStream);
266112

267113
await using downloadStream = bucket.openDownloadStreamByName('foo.txt');
114+
}
268115

269-
throw new Error('error thrown');
270-
})().catch(e => e);
271-
272-
expect(error).to.match(/error thrown/);
273116
expect(readableDisposeSpy.called).to.be.true;
274-
});
275-
276-
it('works if stream is explicitly closed', async function () {
277-
const expected = await (async () => {
278-
await using client = new MongoClient(process.env.MONGODB_URI!);
279-
await client.connect();
280-
281-
const bucket = new GridFSBucket(client.db('foo'));
282-
const uploadStream = bucket.openUploadStream('foo.txt')
283-
await pipeline(Readable.from("AAAAAAA".split('')), uploadStream);
284-
285-
await using downloadStream = bucket.openDownloadStreamByName('foo.txt');
286-
287-
await downloadStream.abort();
288-
289-
return 'not error';
290-
})();
291-
292-
expect(expected).to.equal('not error');
293-
})
294-
295-
it('throws premature close error if explicitly destroyed early', async function () {
296-
// Gridfs streams inherit their _destroy() and Symbol.asyncDispose implementations from
297-
// Nodejs' readable implementation. This behavior matches the behavior for other readable streams
298-
// (see the below test).
299-
const expected = await (async () => {
300-
await using client = new MongoClient(process.env.MONGODB_URI!);
301-
await client.connect();
302-
303-
const bucket = new GridFSBucket(client.db('foo'));
304-
const uploadStream = bucket.openUploadStream('foo.txt')
305-
await pipeline(Readable.from("AAAAAAA".split('')), uploadStream);
306-
307-
await using downloadStream = bucket.openDownloadStreamByName('foo.txt');
308-
309-
downloadStream.destroy();
310-
311-
return 'not error';
312-
})().catch(e => e);
313-
314-
expect(expected).to.match(/Premature close/);
315-
})
316-
317-
it('throws premature close error if explicitly destroyed early (builtin stream)', async function () {
318-
// Gridfs streams inherit their _destroy() and Symbol.asyncDispose implementations from
319-
// Nodejs' readable implementation. This behavior matches the behavior for other readable streams (ie - ReadFileStream)
320-
const expected = await (async () => {
321-
await using readStream = createReadStream(join(__dirname, 'main.test.ts'));
322-
readStream.destroy();
323-
324-
return 'not error';
325-
})().catch(e => e);
326-
327-
expect(expected).to.match(/Premature close/);
328117
})
329118
});
330119
})

0 commit comments

Comments
 (0)