From 4b8393b2ee977edb7841a9e7d9ce6a0fe1238f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 4 Dec 2018 09:52:36 +0200 Subject: [PATCH] MXS-2196: Fix most NPM unit test failures The REST API and MaxCtrl tests relied upon the implicit sessions that were created by the listeners. This can be corrected and improved by creating an actual connection to MaxScale to check that a client session is indeed created. --- maxctrl/test/diagnostics.js | 2 +- server/core/test/rest-api/package.json | 1 + .../test/rest-api/test/schema_validation.js | 18 ++++++++++++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/maxctrl/test/diagnostics.js b/maxctrl/test/diagnostics.js index 1ca3ae672..58a7f88c1 100644 --- a/maxctrl/test/diagnostics.js +++ b/maxctrl/test/diagnostics.js @@ -24,7 +24,7 @@ var tests = [ 'show server server1', 'show service RW-Split-Router', 'show monitor MariaDB-Monitor', - 'show session 5', + 'show sessions', 'show filter Hint', 'show module readwritesplit', 'show maxscale', diff --git a/server/core/test/rest-api/package.json b/server/core/test/rest-api/package.json index 633c0e5f5..57e50d498 100644 --- a/server/core/test/rest-api/package.json +++ b/server/core/test/rest-api/package.json @@ -12,6 +12,7 @@ "ajv": "^5.5.2", "chai": "^3.5.0", "chai-as-promised": "^6.0.0", + "mariadb": "^2.0.1-beta", "mocha": "^5.2.0", "request": "^2.87.0", "request-promise-native": "^1.0.5" diff --git a/server/core/test/rest-api/test/schema_validation.js b/server/core/test/rest-api/test/schema_validation.js index 968ded380..772f7f03d 100644 --- a/server/core/test/rest-api/test/schema_validation.js +++ b/server/core/test/rest-api/test/schema_validation.js @@ -1,6 +1,20 @@ // These tests use the server/test/maxscale_test.cnf configuration require("../utils.js")() +const mariadb = require('mariadb'); +var conn + +function createConnection() { + return mariadb.createConnection({host: '127.0.0.1', port: 4006, user: 'maxuser', password: 'maxpwd'}) + .then(c => { + conn = c + }) +} + +function closeConnection() { + conn.end() + conn = null +} describe("Resource Collections", function() { before(startMaxScale) @@ -36,6 +50,7 @@ describe("Resource Collections", function() { describe("Individual Resources", function() { before(startMaxScale) + before(createConnection) var tests = [ "/servers/server1", @@ -63,11 +78,13 @@ describe("Individual Resources", function() { }); }) + after(closeConnection) after(stopMaxScale) }); describe("Resource Self Links", function() { before(startMaxScale) + before(createConnection) var tests = [ "/servers", @@ -108,5 +125,6 @@ describe("Resource Self Links", function() { }); }) + after(closeConnection) after(stopMaxScale) });