Skip to content

Commit

Permalink
[misc] correcting test for maxscale
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Jan 11, 2024
1 parent 714f302 commit 0e8e8ad
Show file tree
Hide file tree
Showing 24 changed files with 250 additions and 235 deletions.
6 changes: 5 additions & 1 deletion lib/cmd/handshake/authentication.js
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2015-2023 MariaDB Corporation Ab
// Copyright (c) 2015-2024 MariaDB Corporation Ab

'use strict';

Expand Down Expand Up @@ -102,6 +102,10 @@ class Authentication extends Command {
info.redirect(value, this.successEnd);
break;

case 'maxscale':
info.maxscaleVersion = value;
break;

case 'connection_id':
info.threadId = parseInt(value);
break;
Expand Down
12 changes: 7 additions & 5 deletions lib/config/connection-options.js
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2015-2023 MariaDB Corporation Ab
// Copyright (c) 2015-2024 MariaDB Corporation Ab

'use strict';

Expand Down Expand Up @@ -55,10 +55,12 @@ class ConnectionOptions {
if (opts.logger.logParam !== undefined) this.logParam = opts.logger.logParam;
}
} else {
this.logger = { network: null, query: null, error: null, warning: console.log };
if ((this.debug || this.debugCompress) && !this.logger.network) {
this.logger.network = console.log;
}
this.logger = {
network: this.debug || this.debugCompress ? console.log : null,
query: null,
error: null,
warning: console.log
};
}
this.debug = !!this.logger.network;

Expand Down
64 changes: 63 additions & 1 deletion test/base.js
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2015-2023 MariaDB Corporation Ab
// Copyright (c) 2015-2024 MariaDB Corporation Ab

'use strict';

Expand Down Expand Up @@ -43,6 +43,68 @@ module.exports.createConnection = function createConnection(opts) {
return basePromise.createConnection(connOptionTemp);
};

module.exports.isMaxscale = function isMaxscale() {
if (!global.maxscaleVersion) {
const maxscaleVersion = global.shareConn.info.maxscaleVersion;
if (!maxscaleVersion) {
// maxscale before 23.08
return process.env.srv === 'maxscale';
}
}
return true;
};

module.exports.isMaxscaleMinVersion = function isMaxscaleMinVersion(major, minor, patch) {
if (!global.maxscaleVersion) {
const maxscaleVersion = global.shareConn.info.maxscaleVersion;
if (!maxscaleVersion) {
// maxscale before 23.08
return false;
}
let car;
let offset = 0;
let type = 0;
let val = 0;
let maxscaleMajor = 0;
let maxscaleMinor = 0;
let maxscalePatch = 0;
for (; offset < maxscaleVersion.length; offset++) {
car = maxscaleVersion.charCodeAt(offset);
if (car < 48 || car > 57) {
switch (type) {
case 0:
maxscaleMajor = val;
break;
case 1:
maxscaleMinor = val;
break;
case 2:
maxscalePatch = val;
return;
}
type++;
val = 0;
} else {
val = val * 10 + car - 48;
}
}
//serverVersion finished by number like "5.5.57", assign patchVersion
if (type === 2) maxscalePatch = val;
global.maxscaleVersion = {
major: maxscaleMajor,
minor: maxscaleMinor,
patch: maxscalePatch
};
}

let ver = this.maxscaleVersion;
return (
ver.major > major ||
(ver.major === major && ver.minor > minor) ||
(ver.major === major && ver.minor === minor && ver.patch >= patch)
);
};

module.exports.createPool = (opts) => {
const poolOptionTemp = Object.assign({}, Conf.baseConfig, opts);
return basePromise.createPool(poolOptionTemp);
Expand Down
6 changes: 3 additions & 3 deletions test/integration/datatype/test-datetime.js
@@ -1,12 +1,12 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2015-2023 MariaDB Corporation Ab
// Copyright (c) 2015-2024 MariaDB Corporation Ab

'use strict';

const base = require('../../base');
const { assert } = require('chai');
const Conf = require('../../conf');
const { isXpand } = require('../../base');
const { isXpand, isMaxscale } = require('../../base');

describe('datetime', () => {
const date = new Date('2001-12-31 00:00:00');
Expand Down Expand Up @@ -49,7 +49,7 @@ describe('datetime', () => {
if (!process.env.LOCAL_SOCKET_AVAILABLE) this.skip();
if (
(Conf.baseConfig.host !== 'localhost' && Conf.baseConfig.host !== 'mariadb.example.com') ||
process.env.srv === 'maxscale' ||
isMaxscale() ||
process.env.srv === 'skysql-ha'
)
this.skip();
Expand Down
10 changes: 3 additions & 7 deletions test/integration/test-additional-server-info.js
@@ -1,19 +1,15 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2015-2023 MariaDB Corporation Ab
// Copyright (c) 2015-2024 MariaDB Corporation Ab

'use strict';

const base = require('../base.js');
const { assert } = require('chai');
const { isMaxscale } = require('../base');

describe('server additional information API', () => {
it('server version', async function () {
if (
process.env.srv === 'skysql' ||
process.env.srv === 'skysql-ha' ||
process.env.srv === 'maxscale' ||
process.env.srv === 'build'
)
if (process.env.srv === 'skysql' || process.env.srv === 'skysql-ha' || isMaxscale() || process.env.srv === 'build')
this.skip();

const res = await shareConn.query('SELECT VERSION() a');
Expand Down
11 changes: 6 additions & 5 deletions test/integration/test-auth-plugin.js
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2015-2023 MariaDB Corporation Ab
// Copyright (c) 2015-2024 MariaDB Corporation Ab

'use strict';

Expand All @@ -9,6 +9,7 @@ const Conf = require('../conf');
const fs = require('fs');
const os = require('os');
const path = require('path');
const { isMaxscale } = require('../base');

describe('authentication plugin', () => {
let rsaPublicKey = process.env.TEST_RSA_PUBLIC_KEY;
Expand Down Expand Up @@ -65,14 +66,14 @@ describe('authentication plugin', () => {
} else {
await shareConn.query("CREATE USER 'sha256User'@'%'");
await shareConn.query(
"GRANT ALL PRIVILEGES ON *.* TO 'sha256User'@'%' IDENTIFIED WITH " + "sha256_password BY 'password'"
"GRANT ALL PRIVILEGES ON *.* TO 'sha256User'@'%' IDENTIFIED WITH sha256_password BY 'password'"
);
}
}
});

it('ed25519 authentication plugin', async function () {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql-ha' || process.env.srv === 'skysql') this.skip();
if (isMaxscale() || process.env.srv === 'skysql-ha' || process.env.srv === 'skysql') this.skip();
const self = this;
if (!shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(10, 1, 22)) this.skip();

Expand Down Expand Up @@ -135,7 +136,7 @@ describe('authentication plugin', () => {

it('name pipe authentication plugin', function (done) {
if (process.platform !== 'win32') this.skip();
if (process.env.srv === 'maxscale') this.skip();
if (isMaxscale()) this.skip();
if (!shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(10, 1, 11)) this.skip();
if (Conf.baseConfig.host !== 'localhost' && Conf.baseConfig.host !== 'mariadb.example.com') this.skip();
const windowsUser = process.env.USERNAME;
Expand Down Expand Up @@ -288,7 +289,7 @@ describe('authentication plugin', () => {
});

it('multi authentication plugin', function (done) {
if (process.env.srv === 'maxscale' || process.env.srv === 'skysql' || process.env.srv === 'skysql-ha') this.skip();
if (isMaxscale() || process.env.srv === 'skysql' || process.env.srv === 'skysql-ha') this.skip();
if (!shareConn.info.isMariaDB() || !shareConn.info.hasMinVersion(10, 4, 3)) this.skip();
shareConn.query("drop user IF EXISTS mysqltest1@'%'").catch((err) => {});
shareConn
Expand Down
43 changes: 13 additions & 30 deletions test/integration/test-batch-geometry-type.js
@@ -1,5 +1,5 @@
// SPDX-License-Identifier: LGPL-2.1-or-later
// Copyright (c) 2015-2023 MariaDB Corporation Ab
// Copyright (c) 2015-2024 MariaDB Corporation Ab

'use strict';

Expand All @@ -11,18 +11,19 @@ const { isXpand } = require('../base');

describe('batch geometry type', () => {
let supportBulk;
let serverPermitExtendedInfos;
before(function () {
supportBulk = (Conf.baseConfig.bulk === undefined ? true : Conf.baseConfig.bulk)
? (shareConn.info.serverCapabilities & Capabilities.MARIADB_CLIENT_STMT_BULK_OPERATIONS) > 0
: false;
serverPermitExtendedInfos =
(shareConn.info.serverCapabilities & Capabilities.MARIADB_CLIENT_EXTENDED_TYPE_INFO) > 0;
});

it('Point format', async function () {
// xpand doesn't support geometry
// https://jira.mariadb.org/browse/XPT-12
if (!shareConn.info.isMariaDB() || isXpand()) this.skip();
const serverPermitExtendedInfos =
(shareConn.info.serverCapabilities & Capabilities.MARIADB_CLIENT_EXTENDED_TYPE_INFO) > 0;

await shareConn.query('DROP TABLE IF EXISTS gis_point_batch');
await shareConn.query('CREATE TABLE gis_point_batch (g POINT)');
Expand Down Expand Up @@ -430,9 +431,7 @@ describe('batch geometry type', () => {
type: 'MultiPoint',
coordinates: []
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiPoint' }
: null
},
Expand All @@ -442,9 +441,7 @@ describe('batch geometry type', () => {
type: 'MultiPoint',
coordinates: []
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiPoint' }
: null
}
Expand Down Expand Up @@ -559,9 +556,7 @@ describe('batch geometry type', () => {
type: 'MultiLineString',
coordinates: [[]]
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiLineString' }
: null
},
Expand All @@ -571,9 +566,7 @@ describe('batch geometry type', () => {
type: 'MultiLineString',
coordinates: []
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiLineString' }
: null
},
Expand All @@ -583,9 +576,7 @@ describe('batch geometry type', () => {
type: 'MultiLineString',
coordinates: []
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiLineString' }
: null
}
Expand Down Expand Up @@ -787,9 +778,7 @@ describe('batch geometry type', () => {
type: 'MultiPolygon',
coordinates: [[[]]]
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiPolygon' }
: null
},
Expand All @@ -799,9 +788,7 @@ describe('batch geometry type', () => {
type: 'MultiPolygon',
coordinates: [[]]
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiPolygon' }
: null
},
Expand All @@ -811,9 +798,7 @@ describe('batch geometry type', () => {
type: 'MultiPolygon',
coordinates: []
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiPolygon' }
: null
},
Expand All @@ -823,9 +808,7 @@ describe('batch geometry type', () => {
type: 'MultiPolygon',
coordinates: []
}
: shareConn.info.hasMinVersion(10, 5, 2) &&
process.env.srv !== 'maxscale' &&
process.env.srv !== 'skysql-ha'
: serverPermitExtendedInfos
? { type: 'MultiPolygon' }
: null
}
Expand Down

0 comments on commit 0e8e8ad

Please sign in to comment.