不要怂,就是干,撸起袖子干!

Commit 342e18fb by Sushant Committed by GitHub

fix(sqlite): close connection properly and cleanup files (#9851)

1 parent 2d499acc
......@@ -33,6 +33,15 @@ class ConnectionManager extends AbstractConnectionManager {
this.refreshTypeParser(dataTypes);
}
_onProcessExit() {
const promises = Object.getOwnPropertyNames(this.connections)
.map(connection => Promise.fromCallback(callback => this.connections[connection].close(callback)));
return Promise
.all(promises)
.then(() => super._onProcessExit.call(this));
}
// Expose this as a method so that the parsing may be updated when the user has added additional, custom types
_refreshTypeParser(dataType) {
parserStore.refresh(dataType);
......
'use strict';
const chai = require('chai');
const fs = require('fs');
const path = require('path');
const expect = chai.expect;
const Support = require(__dirname + '/../../support');
const dialect = Support.getTestDialect();
const DataTypes = require(__dirname + '/../../../../lib/data-types');
const fileName = Math.random() + '_test.sqlite';
if (dialect === 'sqlite') {
describe('[SQLITE Specific] Connection Manager', () => {
after(() => {
fs.unlinkSync(path.join(__dirname, fileName));
});
it('close connection and remove journal and wal files', function() {
const sequelize = Support.createSequelizeInstance({
storage: path.join(__dirname, fileName)
});
const User = sequelize.define('User', { username: DataTypes.STRING });
return User
.sync({ force: true })
.then(() => sequelize.query('PRAGMA journal_mode = WAL'))
.then(() => User.create({ username: 'user1' }))
.then(() => {
return sequelize.transaction(transaction => {
return User.create({ username: 'user2' }, { transaction });
});
})
.then(() => {
expect(fs.existsSync(path.join(__dirname, fileName))).to.be.true;
expect(fs.existsSync(path.join(__dirname, `${fileName}-shm`)), 'shm file should exists').to.be.true;
expect(fs.existsSync(path.join(__dirname, `${fileName}-wal`)), 'wal file should exists').to.be.true;
return sequelize.close();
})
.then(() => {
expect(fs.existsSync(path.join(__dirname, fileName))).to.be.true;
expect(fs.existsSync(path.join(__dirname, `${fileName}-shm`)), 'shm file exists').to.be.false;
expect(fs.existsSync(path.join(__dirname, `${fileName}-wal`)), 'wal file exists').to.be.false;
return this.sequelize.query('PRAGMA journal_mode = DELETE');
});
});
});
}
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!