Merge pull request #385 from TwistedLogic/master
Prevent `connect()` from failing when called after `disconnect()`
This commit is contained in:
commit
2ddadc1c81
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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/;
|
||||
|
|
Loading…
Reference in New Issue