test: ensure no clients are left open after test runs
@@ -23,11 +23,12 @@ const requirements = require('./requirements.helper');
describe('ClientEncryption', function() {
let client;
- beforeEach(function() {
+ function setup() {
if (requirements.SKIP_LIVE_TESTS) {
this.test.skip();
return;
}
+
client = new MongoClient('mongodb://localhost:27017/test', { useNewUrlParser: true });
return client.connect().then(() =>
client
@@ -42,14 +43,15 @@ describe('ClientEncryption', function() {
throw err;
})
);
- });
+ }
- afterEach(() => {
+ function teardown() {
if (requirements.SKIP_LIVE_TESTS) {
return;
}
+
return client.close();
- });
+ }
describe('stubbed stateMachine', function() {
let sandbox = sinon.createSandbox();
@@ -64,6 +66,14 @@ describe('ClientEncryption', function() {
});
});
+ beforeEach(function() {
+ return setup();
+ });
+
+ afterEach(function() {
+ return teardown();
+ });
+
[
{
name: 'local',
@@ -200,6 +210,8 @@ describe('ClientEncryption', function() {
this.skip();
return;
}
+
+ return setup().then(() => {
this.client = client;
this.collection = client.db('client').collection('encryption');
this.encryption = new ClientEncryption(this.client, {
@@ -207,12 +219,15 @@ describe('ClientEncryption', function() {
kmsProviders
});
});
+ });
afterEach(function() {
+ return teardown().then(() => {
this.encryption = undefined;
this.collection = undefined;
this.client = undefined;
});
+ });
function makeOptions(keyAltNames) {
return Object.assign({}, dataKeyOptions, { keyAltNames });
