mirror of
https://github.com/DeNNiiInc/dbgate.git
synced 2026-04-21 23:25:59 +00:00
close connection in finally block
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
const requireEngineDriver = require('dbgate-api/src/utility/requireEngineDriver');
|
||||
const engines = require('../engines');
|
||||
const { connect, randomDbName } = require('../tools');
|
||||
const { connect, randomDbName, testWrapper } = require('../tools');
|
||||
|
||||
const t1Sql = 'CREATE TABLE t1 (id int not null primary key, val varchar(50) null)';
|
||||
const t1Match = expect.objectContaining({
|
||||
@@ -26,33 +26,22 @@ const t1Match = expect.objectContaining({
|
||||
}),
|
||||
});
|
||||
|
||||
|
||||
describe('Table analyse', () => {
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Table structure - full analysis (%s)',
|
||||
async (label, engine) => {
|
||||
const conn = await connect(engine, randomDbName());
|
||||
try {
|
||||
const driver = requireEngineDriver(engine.connection);
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await driver.query(conn, t1Sql);
|
||||
|
||||
await driver.query(conn, t1Sql);
|
||||
const structure = await driver.analyseFull(conn);
|
||||
|
||||
const structure = await driver.analyseFull(conn);
|
||||
|
||||
expect(structure.tables.length).toEqual(1);
|
||||
expect(structure.tables[0]).toEqual(t1Match);
|
||||
} finally {
|
||||
await driver.close(conn);
|
||||
}
|
||||
}
|
||||
expect(structure.tables.length).toEqual(1);
|
||||
expect(structure.tables[0]).toEqual(t1Match);
|
||||
})
|
||||
);
|
||||
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Table add - incremental analysis (%s)',
|
||||
async (label, engine) => {
|
||||
const conn = await connect(engine, randomDbName());
|
||||
const driver = requireEngineDriver(engine.connection);
|
||||
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await driver.query(conn, 'CREATE TABLE t0 (id0 int)');
|
||||
const structure1 = await driver.analyseFull(conn);
|
||||
await driver.query(conn, t1Sql);
|
||||
@@ -60,16 +49,12 @@ describe('Table analyse', () => {
|
||||
|
||||
expect(structure2.tables.length).toEqual(2);
|
||||
expect(structure2.tables.find(x => x.pureName == 't1')).toEqual(t1Match);
|
||||
await driver.close(conn);
|
||||
}
|
||||
})
|
||||
);
|
||||
|
||||
test.each(engines.map(engine => [engine.label, engine]))(
|
||||
'Table remove - incremental analysis (%s)',
|
||||
async (label, engine) => {
|
||||
const conn = await connect(engine, randomDbName());
|
||||
const driver = requireEngineDriver(engine.connection);
|
||||
|
||||
testWrapper(async (conn, driver, engine) => {
|
||||
await driver.query(conn, t1Sql);
|
||||
await driver.query(conn, 'CREATE TABLE t2 (id2 int)');
|
||||
const structure1 = await driver.analyseFull(conn);
|
||||
@@ -78,7 +63,6 @@ describe('Table analyse', () => {
|
||||
|
||||
expect(structure2.tables.length).toEqual(1);
|
||||
expect(structure2.tables[0]).toEqual(t1Match);
|
||||
await driver.close(conn);
|
||||
}
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user