-
Notifications
You must be signed in to change notification settings - Fork 470
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
mssql.close() still blocking mocha test suite exit #735
Comments
What about |
I don't quite understand what you mean. I have tried btw,
|
Thanks for the |
My apologies. I have written a sample test like this: const should = require('should');
const mssql = require('mssql');
const config = require('config-lite')(__dirname).mssql;
function execute(sql, callBack) {
const connPool = new mssql.ConnectionPool(config, (err) => {
const ps = new mssql.PreparedStatement(connPool);
ps.prepare(sql, (err) => {
if (err) {
console.log(err);
}
ps.execute({}, (err, recordset) => {
if (err) {
console.log(err);
}
callBack(err, recordset);
ps.unprepare((err) => {
if (err) {
console.log(err);
}
});
});
});
});
}
describe('mssql test', () => {
after(() => {
mssql.close();
console.log('after all run out');
})
it('just return someting and go on', (done) => {
execute('select * from TestForNode', (err, record) => {
done();
})
});
}); Then run the command
It just waiting there forever, it won't exit unless you press Ctrl + C. If I don't call the
|
This is some new Mocha functionality. You can run mocha with In the interim, try something like this: after(async () => {
await mssql.close();
console.log('after all run out');
}) |
Thank you very much. First, I have tried to run Then, I've removed the argument Thanks again. |
@Sondragon OK, great, thanks for the update. I'll amend the issue title and look at putting this somewhere on the backlog to get resolved. |
The problem is that there's no global connection to close (which is what You need to change your code to close the connection pool: const should = require('should');
const mssql = require('mssql');
const config = require('config-lite')(__dirname).mssql;
function execute(sql, callBack) {
const connPool = new mssql.ConnectionPool(config, (err) => {
const ps = new mssql.PreparedStatement(connPool);
ps.prepare(sql, (err) => {
if (err) {
console.log(err);
}
ps.execute({}, (err, recordset) => {
if (err) {
console.log(err);
}
callBack(err, recordset);
ps.unprepare((err) => {
if (err) {
console.log(err);
}
+ connPool.close();
});
});
});
});
}
describe('mssql test', () => {
- after(() => {
- mssql.close();
- console.log('after all run out');
- })
it('just return someting and go on', (done) => {
execute('select * from TestForNode', (err, record) => {
done();
})
});
}); |
You should investigate having a shared pool instead which you pass around to your tests and then close in the |
I have met the same question like this ladjs/supertest#437 (comment),.
So I need to close all the connections after I call a unit test, I have tried
mssql.close()
but it doesn't work.Has anybody met this before and how do you fix it?
the mssql code i use look like this:
The text was updated successfully, but these errors were encountered: