Skip to content

Commit

Permalink
[misc] test improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed May 29, 2023
1 parent fa7d42e commit a0762e7
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 20 deletions.
4 changes: 3 additions & 1 deletion test/integration/test-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ describe('debug', () => {
//ensure that debug from previous test are written to console
afterEach((done) => {
logger.close();
fs.unlinkSync(tmpLogFile);
try {
fs.unlinkSync(tmpLogFile);
} catch (e) {}
setTimeout(() => {
done();
}, 1000);
Expand Down
56 changes: 37 additions & 19 deletions test/integration/test-file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ describe('sql file import', () => {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
await shareConn.query('DROP DATABASE IF EXISTS fimp');
await shareConn.query('CREATE DATABASE IF NOT EXISTS fimp');
await shareConn.query('FLUSH TABLES');
});

afterEach(async function () {
Expand All @@ -24,7 +25,7 @@ describe('sql file import', () => {
describe('base promise', () => {
it('simple file import with direct connection options', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
await basePromise.importFile(
Object.assign({}, Conf.baseConfig, { file: __dirname + '/../tools/data-dump.sql', database: 'fimp' })
);
Expand All @@ -33,7 +34,7 @@ describe('sql file import', () => {

it('big file import with direct connection options', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha' || isXpand()) this.skip();
this.timeout(10000);
this.timeout(300000);
await basePromise.importFile(
Object.assign({}, Conf.baseConfig, { file: __dirname + '/../tools/data-dump2.sql', database: 'fimp' })
);
Expand All @@ -42,7 +43,7 @@ describe('sql file import', () => {

it('no database selected', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
try {
await basePromise.importFile(
Object.assign({}, Conf.baseConfig, { file: __dirname + '/../tools/data-dump.sql', database: null })
Expand All @@ -61,7 +62,7 @@ describe('sql file import', () => {
describe('base connection', () => {
it('missing options', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
try {
await shareConn.importFile();
throw new Error('expected to throw an error');
Expand All @@ -76,7 +77,7 @@ describe('sql file import', () => {

it('wrong file options', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
try {
await shareConn.importFile({ file: '/tt' });
throw new Error('expected to throw an error');
Expand All @@ -85,13 +86,12 @@ describe('sql file import', () => {
assert.equal(err.sqlState, 'HY000');
assert.equal(err.code, 'ER_MISSING_SQL_FILE');
assert.isTrue(!err.fatal);
console.log(err);
assert.ok(err.message.includes("SQL file parameter '/tt' doesn't exists"));
}
});
it('simple file import', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
await shareConn.importFile({ file: __dirname + '/../tools/data-dump.sql', database: 'fimp' });
const res = await shareConn.query('SELECT DATABASE() as db');
assert.equal(res[0].db, Conf.baseConfig.database);
Expand All @@ -102,7 +102,7 @@ describe('sql file import', () => {
describe('base pool', () => {
it('pool import', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
const pool = base.createPool({
connectionLimit: 1
});
Expand All @@ -113,7 +113,7 @@ describe('sql file import', () => {

it('no database selected', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
const pool = base.createPool({
connectionLimit: 1,
database: null
Expand All @@ -136,15 +136,33 @@ describe('sql file import', () => {

describe('callback', () => {
describe('base callback', () => {
it('simple file import without callback', function () {
it('simple file import without callback', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(30000);
baseCallback.importFile(
Object.assign({}, Conf.baseConfig, { file: __dirname + '/../tools/data-dump.sql', database: 'fimp' })
);
const conn = base.createCallbackConnection();
conn.connect((err) => {
if (err) {
done(err);
} else {
const inter = setInterval(function () {
conn.query('select count(*) as c from fimp.post', (err, res) => {
if (res[0].c == 3) {
clearInterval(inter);
conn.end();
done();
}
});
}, 100);
}
});
});

it('simple file import with direct connection options', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
baseCallback.importFile(
Object.assign({}, Conf.baseConfig, { file: __dirname + '/../tools/data-dump.sql', database: 'fimp' }),
(err) => {
Expand All @@ -158,9 +176,9 @@ describe('sql file import', () => {
});

it('big file import with direct connection options', function (done) {
// skipping if takes too long
// skipping if it takes too long
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha' || isXpand()) this.skip();
this.timeout(10000);
this.timeout(300000);
baseCallback.importFile(
Object.assign({}, Conf.baseConfig, { file: __dirname + '/../tools/data-dump2.sql', database: 'fimp' }),
(err) => {
Expand All @@ -175,7 +193,7 @@ describe('sql file import', () => {

it('no database selected', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
baseCallback.importFile(
Object.assign({}, Conf.baseConfig, { file: __dirname + '/../tools/data-dump.sql', database: null }),
(err) => {
Expand All @@ -197,7 +215,7 @@ describe('sql file import', () => {
describe('base connection', () => {
it('missing options', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
const conn = base.createCallbackConnection();
conn.connect((err) => {
conn.importFile({}, (err) => {
Expand All @@ -218,7 +236,7 @@ describe('sql file import', () => {

it('wrong file options', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
const conn = base.createCallbackConnection();
conn.connect((err) => {
conn.importFile({ file: '/tt' }, (err) => {
Expand All @@ -239,7 +257,7 @@ describe('sql file import', () => {

it('simple file import', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
const conn = base.createCallbackConnection();
conn.connect((err) => {
conn.importFile({ file: __dirname + '/../tools/data-dump.sql', database: 'fimp' }, (err) => {
Expand All @@ -266,7 +284,7 @@ describe('sql file import', () => {
describe('base pool', () => {
it('pool import', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
const pool = base.createPoolCallback({
connectionLimit: 1
});
Expand All @@ -284,7 +302,7 @@ describe('sql file import', () => {

it('no database selected', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha') this.skip();
this.timeout(10000);
this.timeout(30000);
const pool = base.createPoolCallback({
connectionLimit: 1,
database: null
Expand Down

0 comments on commit a0762e7

Please sign in to comment.