Handle shutdown on grid adapters (#5943)

* Handle shutdown on grid adapters

* Add tests

* Fix postgres test
This commit is contained in:
Antonio Davi Macedo Coelho de Castro
2019-08-19 00:35:06 -07:00
committed by Diamond Lewis
parent f5ac94ddb2
commit c951e08f63
6 changed files with 81 additions and 21 deletions

View File

@@ -32,7 +32,10 @@ export class GridFSBucketAdapter extends FilesAdapter {
this._connectionPromise = MongoClient.connect(
this._databaseURI,
this._mongoOptions
).then(client => client.db(client.s.options.dbName));
).then(client => {
this._client = client;
return client.db(client.s.options.dbName);
});
}
return this._connectionPromise;
}
@@ -98,6 +101,13 @@ export class GridFSBucketAdapter extends FilesAdapter {
const bucket = await this._getBucket();
return bucket.openDownloadStreamByName(filename);
}
handleShutdown() {
if (!this._client) {
return Promise.resolve();
}
return this._client.close(false);
}
}
export default GridFSBucketAdapter;

View File

@@ -33,7 +33,10 @@ export class GridStoreAdapter extends FilesAdapter {
this._connectionPromise = MongoClient.connect(
this._databaseURI,
this._mongoOptions
).then(client => client.db(client.s.options.dbName));
).then(client => {
this._client = client;
return client.db(client.s.options.dbName);
});
}
return this._connectionPromise;
}
@@ -99,6 +102,13 @@ export class GridStoreAdapter extends FilesAdapter {
});
});
}
handleShutdown() {
if (!this._client) {
return Promise.resolve();
}
return this._client.close(false);
}
}
export default GridStoreAdapter;