Skip to content

Commit 7c746f4

Browse files
test: fix existing openHandles issues (#534)
1 parent 2e6e78f commit 7c746f4

5 files changed

Lines changed: 1227 additions & 725 deletions

File tree

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
script: commitlint-travis
1919
- script: yarn lint
2020
name: Lint JavaScript
21-
- script: sleep 20; yarn test:coverage --forceExit
21+
- script: sleep 20; yarn test:coverage
2222
name: Tests
2323
# NOTICE: Handles code coverage reporting to Code Climate
2424
before_install:

test/adapters/sequelize.test.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ function getField(schema, name) {
66
return schema.fields.find((field) => field.field === name);
77
}
88

9-
[sequelizePostgres, sequelizeMySQLMin, sequelizeMySQLMax].forEach((sequelize) => {
9+
[sequelizePostgres, sequelizeMySQLMin, sequelizeMySQLMax].forEach((connectionManager) => {
10+
const sequelize = connectionManager.createConnection();
1011
const models = {};
1112
const sequelizeOptions = {
1213
sequelize: Sequelize,
@@ -24,7 +25,7 @@ function getField(schema, name) {
2425
},
2526
});
2627

27-
describe(`with dialect ${sequelize.options.dialect} (port: ${sequelize.options.port})`, () => {
28+
describe(`with dialect ${connectionManager.getDialect()} (port: ${connectionManager.getPort()})`, () => {
2829
describe('with model `users`', () => {
2930
it('should set name correctly', async () => {
3031
expect.assertions(1);

test/databases.js

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,40 @@
11
const Sequelize = require('sequelize');
22

3-
const databaseOptions = {
4-
logging: false,
5-
pool: { maxConnections: 10, minConnections: 1 },
6-
};
3+
class ConnectionManager {
4+
constructor(connectionString) {
5+
this.connectionString = connectionString;
6+
this.databaseOptions = {
7+
logging: false,
8+
pool: { maxConnections: 10, minConnections: 1 },
9+
};
10+
this.connection = null;
11+
}
12+
13+
getDialect() {
14+
return this.connection && this.connection.options && this.connection.options.dialect;
15+
}
716

8-
const sequelizePostgres = new Sequelize(
9-
'postgres://forest:secret@localhost:5436/forest-express-sequelize-test',
10-
databaseOptions,
11-
);
17+
getPort() {
18+
return this.connection && this.connection.options && this.connection.options.port;
19+
}
1220

13-
const sequelizeMySQLMin = new Sequelize(
14-
'mysql://forest:secret@localhost:8998/forest-express-sequelize-test',
15-
databaseOptions,
16-
);
21+
createConnection() {
22+
if (!this.connection) {
23+
this.connection = new Sequelize(this.connectionString, this.databaseOptions);
24+
}
25+
return this.connection;
26+
}
1727

18-
const sequelizeMySQLMax = new Sequelize(
19-
'mysql://forest:secret@localhost:8999/forest-express-sequelize-test',
20-
databaseOptions,
21-
);
28+
closeConnection() {
29+
if (this.connection) {
30+
this.connection.close();
31+
this.connection = null;
32+
}
33+
}
34+
}
2235

2336
module.exports = {
24-
sequelizePostgres,
25-
sequelizeMySQLMin,
26-
sequelizeMySQLMax,
37+
sequelizePostgres: new ConnectionManager('postgres://forest:secret@localhost:5436/forest-express-sequelize-test'),
38+
sequelizeMySQLMin: new ConnectionManager('mysql://forest:secret@localhost:8998/forest-express-sequelize-test'),
39+
sequelizeMySQLMax: new ConnectionManager('mysql://forest:secret@localhost:8999/forest-express-sequelize-test'),
2740
};

0 commit comments

Comments
 (0)