@@ -20,13 +20,10 @@ const EmbeddedDocument = mongoose.Types.Subdocument;
2020const MongooseError = mongoose . Error ;
2121
2222describe ( 'Model' , function ( ) {
23-
2423 let db ;
2524 let Comments ;
2625 let BlogPost ;
2726
28- const connectionsToClose = [ ] ;
29-
3027 beforeEach ( ( ) => db . deleteModel ( / .* / ) ) ;
3128
3229 beforeEach ( function ( ) {
@@ -84,7 +81,6 @@ describe('Model', function() {
8481
8582 after ( async function ( ) {
8683 await db . close ( ) ;
87- await Promise . all ( connectionsToClose . map ( async ( v ) => /* v instanceof Promise ? (await v).close() : */ v . close ( ) ) ) ;
8884 } ) ;
8985
9086 afterEach ( ( ) => util . clearTestData ( db ) ) ;
@@ -3722,9 +3718,6 @@ describe('Model', function() {
37223718 } ) ;
37233719
37243720 it ( 'with positional notation on path not existing in schema (gh-1048)' , function ( done ) {
3725- const db = start ( ) ;
3726- connectionsToClose . push ( db ) ;
3727-
37283721 const M = db . model ( 'Test' , Schema ( { name : 'string' } ) ) ;
37293722 db . on ( 'open' , function ( ) {
37303723 const o = {
@@ -4336,7 +4329,6 @@ describe('Model', function() {
43364329 it ( 'save max bson size error with buffering (gh-3906)' , async function ( ) {
43374330 this . timeout ( 10000 ) ;
43384331 const db = start ( { noErrorListener : true } ) ;
4339- connectionsToClose . push ( db ) ;
43404332 const Test = db . model ( 'Test' , { name : Object } ) ;
43414333
43424334 const test = new Test ( {
@@ -4355,7 +4347,6 @@ describe('Model', function() {
43554347 it ( 'reports max bson size error in save (gh-3906)' , async function ( ) {
43564348 this . timeout ( 10000 ) ;
43574349 const db = await start ( { noErrorListener : true } ) ;
4358- connectionsToClose . push ( db ) ;
43594350 const Test = db . model ( 'Test' , { name : Object } ) ;
43604351
43614352 const test = new Test ( {
@@ -5339,63 +5330,6 @@ describe('Model', function() {
53395330 assert . equal ( changeData . operationType , 'insert' ) ;
53405331 assert . equal ( changeData . fullDocument . name , 'Child' ) ;
53415332 } ) ;
5342-
5343- it ( 'watch() before connecting (gh-5964)' , async function ( ) {
5344- const db = start ( ) ;
5345- connectionsToClose . push ( db ) ;
5346-
5347- const MyModel = db . model ( 'Test5964' , new Schema ( { name : String } ) ) ;
5348-
5349- // Synchronous, before connection happens
5350- const changeStream = MyModel . watch ( ) ;
5351- const changed = new global . Promise ( resolve => {
5352- changeStream . once ( 'change' , data => resolve ( data ) ) ;
5353- } ) ;
5354-
5355- await db ;
5356- await MyModel . create ( { name : 'Ned Stark' } ) ;
5357-
5358- const changeData = await changed ;
5359- assert . equal ( changeData . operationType , 'insert' ) ;
5360- assert . equal ( changeData . fullDocument . name , 'Ned Stark' ) ;
5361- } ) ;
5362-
5363- it ( 'watch() close() prevents buffered watch op from running (gh-7022)' , async function ( ) {
5364- const db = start ( ) ;
5365- connectionsToClose . push ( db ) ;
5366- const MyModel = db . model ( 'Test' , new Schema ( { } ) ) ;
5367- const changeStream = MyModel . watch ( ) ;
5368- const ready = new global . Promise ( resolve => {
5369- changeStream . once ( 'data' , ( ) => {
5370- resolve ( true ) ;
5371- } ) ;
5372- setTimeout ( resolve , 500 , false ) ;
5373- } ) ;
5374-
5375- changeStream . close ( ) ;
5376- await db ;
5377- const readyCalled = await ready ;
5378- assert . strictEqual ( readyCalled , false ) ;
5379- } ) ;
5380-
5381- it ( 'watch() close() closes the stream (gh-7022)' , async function ( ) {
5382- const db = await start ( ) ;
5383- connectionsToClose . push ( db ) ;
5384- const MyModel = db . model ( 'Test' , new Schema ( { name : String } ) ) ;
5385-
5386- await MyModel . init ( ) ;
5387-
5388- const changeStream = MyModel . watch ( ) ;
5389- const closed = new global . Promise ( resolve => {
5390- changeStream . once ( 'close' , ( ) => resolve ( true ) ) ;
5391- } ) ;
5392-
5393- await MyModel . create ( { name : 'Hodor' } ) ;
5394-
5395- changeStream . close ( ) ;
5396- const closedData = await closed ;
5397- assert . strictEqual ( closedData , true ) ;
5398- } ) ;
53995333 } ) ;
54005334
54015335 describe ( 'sessions (gh-6362)' , function ( ) {
@@ -5429,9 +5363,7 @@ describe('Model', function() {
54295363 } ) ;
54305364
54315365 it ( 'startSession() before connecting' , async function ( ) {
5432-
54335366 const db = start ( ) ;
5434- connectionsToClose . push ( db ) ;
54355367
54365368 const MyModel = db . model ( 'Test' , new Schema ( { name : String } ) ) ;
54375369
@@ -5446,6 +5378,7 @@ describe('Model', function() {
54465378
54475379 session . endSession ( ) ;
54485380
5381+ await db . close ( ) ;
54495382 } ) ;
54505383
54515384 it ( 'sets session when pulling a document from db' , async function ( ) {
0 commit comments