Merge pull request #385 from TwistedLogic/master

Prevent `connect()` from failing when called after `disconnect()`
This commit is contained in:
Diana Lau 2019-05-28 10:34:23 -04:00 committed by GitHub
commit 2ddadc1c81
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 39 additions and 1 deletions

View File

@ -530,7 +530,10 @@ MySQL.prototype.disconnect = function(cb) {
debug('disconnect');
}
if (this.client) {
this.client.end(cb);
this.client.end((err) => {
this.client = null;
cb(err);
});
} else {
process.nextTick(cb);
}

View File

@ -59,6 +59,41 @@ describe('connections', function() {
});
});
it('should disconnect then connect and ORM should work', function() {
var ds = new DataSource(mysqlConnector, config);
var Student = ds.define('Student', {
name: {type: String, length: 255},
age: {type: Number},
}, {
forceId: false,
});
return ds.connect()
.then(function(err) {
should.not.exist(err);
return ds.automigrate(['Student']);
})
.then(function(err) {
should.not.exist(err);
should(ds.connected).be.True();
return ds.disconnect();
})
.then(function(err) {
should.not.exist(err);
should(ds.connected).be.False();
return ds.connect();
})
.then(function(err) {
should.not.exist(err);
should(ds.connected).be.True();
return Student.count();
})
.then(function(count) {
should(count).be.a.Number();
return ds.disconnect();
});
});
it('should use latin1 charset', function(done) {
var test_set = /latin1/;
var test_collo = /latin1_general_ci/;