From e62b90070de6b43abf32a55e788b8f4b2b8dbe46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Thu, 14 Oct 2010 15:31:05 +0200 Subject: [PATCH 01/19] Update Readme --- Readme.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Readme.md b/Readme.md index ee7ef8efe..c011c262e 100644 --- a/Readme.md +++ b/Readme.md @@ -212,7 +212,6 @@ parameter is provided which contains the information from the mysql OK packet. At this point the module is ready to be tried out, but a lot of things are yet to be done: -* Handle timeouts / reconnect * Pause / resume * Remaining mysql commands * Prepared Statements @@ -220,7 +219,7 @@ At this point the module is ready to be tried out, but a lot of things are yet t * Compression * Performance profiling * Handle re-connect after bad credential error (should query queue be kept?) -* ? +* Deal with stale connections / other potential network issues ## License From c7547e17e37f811a75e239e08c79d3d0b9319203 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sat, 23 Oct 2010 14:10:53 +0200 Subject: [PATCH 02/19] Make the Makefile more portable For some reason the bash magic doesn't work properly on all platforms. --- Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 14c43a5ad..171ba8af0 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,6 @@ test: - @find test/{simple,system}/test-*.js | xargs -n 1 -t node + @find test/simple/test-*.js | xargs -n 1 -t node + @find test/system/test-*.js | xargs -n 1 -t node test-all: test @find test/system/slow/test-*.js | xargs -n 1 -t node benchmark-node-mysql: From 9dd305754794d2766895f0405fbb5da3ed93ba9c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 24 Oct 2010 16:17:24 +0200 Subject: [PATCH 03/19] Add instructions for installing without npm See: http://groups.google.com/group/nodejs/browse_thread/thread/be7d01c3950b2e64 --- Readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Readme.md b/Readme.md index c011c262e..8946f7c65 100644 --- a/Readme.md +++ b/Readme.md @@ -37,6 +37,11 @@ testing. npm install mysql +Or if you don't want to use npm / run the latest source: + + cd ~/.node_libraries + git clone git://github.com/felixge/node-mysql.git mysql + ## Design Goals * TDD: All code is written using test driven development, code coverage should approach 100% From ab90020662e8abc30da8bc11060d2dd7614499c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sun, 24 Oct 2010 16:21:20 +0200 Subject: [PATCH 04/19] Add note about compatibility --- Readme.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Readme.md b/Readme.md index 8946f7c65..77ec3b1c1 100644 --- a/Readme.md +++ b/Readme.md @@ -42,6 +42,11 @@ Or if you don't want to use npm / run the latest source: cd ~/.node_libraries git clone git://github.com/felixge/node-mysql.git mysql +## Compatibility + +This module should run in any node version >= v0.1.102 (July 26, 2010). +However, using a current version of node is encouraged. + ## Design Goals * TDD: All code is written using test driven development, code coverage should approach 100% From 82b74297acb649adeb704c6c6caabaff6a3c3037 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Mon, 25 Oct 2010 19:10:37 +0200 Subject: [PATCH 05/19] Fix parser test for node HEAD Seems like something in casting of strings to buffers has changed. Will need to investigate on older node versions. --- test/simple/test-parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/simple/test-parser.js b/test/simple/test-parser.js index 83564bd45..46fcba733 100644 --- a/test/simple/test-parser.js +++ b/test/simple/test-parser.js @@ -58,7 +58,7 @@ test(function write() { assert.equal(parser.state, Parser.GREETING_SERVER_VERSION); var VERSION = 'MySql 5.1'; - parser.write(new Buffer(VERSION+'\0')); + parser.write(new Buffer(VERSION+'\0\0')); assert.equal(packet.serverVersion, VERSION); assert.equal(parser.state, Parser.GREETING_THREAD_ID); From 0f4cdc62d05d8d17a9e1405aca658feac7a57d36 Mon Sep 17 00:00:00 2001 From: "frankgrimm@gmail.com" Date: Mon, 25 Oct 2010 16:37:54 +0200 Subject: [PATCH 06/19] Fix typo. --- Readme.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Readme.md b/Readme.md index 77ec3b1c1..90bc5ead2 100644 --- a/Readme.md +++ b/Readme.md @@ -162,7 +162,7 @@ data. Sends a ping command to the server. -### client.useDatbase(database, [cb]) +### client.useDatabase(database, [cb]) Same as issuing a `'USE '` query. From 2599dce7ee8cfc8f4230006d03af91d686cc7e70 Mon Sep 17 00:00:00 2001 From: "frankgrimm@gmail.com" Date: Mon, 25 Oct 2010 16:51:05 +0200 Subject: [PATCH 07/19] Add ENOTFOUND handling to connect function and test. --- lib/mysql/client.js | 2 +- test/system/test-client-connection-error.js | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/lib/mysql/client.js b/lib/mysql/client.js index ed01e2750..fd0bd1416 100644 --- a/lib/mysql/client.js +++ b/lib/mysql/client.js @@ -51,7 +51,7 @@ Client.prototype.connect = function(cb) { connection.connect(self.port, self.host); connection .on('error', function(err) { - if (err.errno == netBinding.ECONNREFUSED) { + if (err.errno & (netBinding.ECONNREFUSED | netBinding.ENOTFOUND)) { if (cb) { cb(err); } diff --git a/test/system/test-client-connection-error.js b/test/system/test-client-connection-error.js index c26f0f064..b61f48fdc 100644 --- a/test/system/test-client-connection-error.js +++ b/test/system/test-client-connection-error.js @@ -3,9 +3,10 @@ var Client = require('mysql').Client, client = Client(TEST_CONFIG), gently = new Gently(), ECONNREFUSED = process.binding('net').ECONNREFUSED; + ENOTFOUND = process.binding('net').ENOTFOUND; client.host = 'BADHOST'; client.connect(gently.expect(function connectCb(err, result) { - assert.equal(err.errno, ECONNREFUSED); + assert.ok(err.errno & (ECONNREFUSED | ENOTFOUND)); })); From 3ff75d8d957ca86f4ea1069830381e71ca1fb9a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Mon, 25 Oct 2010 19:13:58 +0200 Subject: [PATCH 08/19] Update contributors --- Readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/Readme.md b/Readme.md index 90bc5ead2..6e2b4bd02 100644 --- a/Readme.md +++ b/Readme.md @@ -11,6 +11,7 @@ A node.js module implementing the * Alan Gutierrez ([bigeasy](http://github.com/felixge/node-mysql/commits/master?author=bigeasy)) * Brian ([mscdex](http://github.com/felixge/node-mysql/commits/master?author=mscdex)) * Cal Henderson ([iamcal](http://github.com/felixge/node-mysql/commits/master?author=iamcal)) +* Frank Grimm ([FrankGrimm](http://github.com/felixge/node-mysql/commits/master?author=FrankGrimm)) ## Sponsors From 60789758d490caf45cbd9d02d096f823b7da2ff0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Thu, 28 Oct 2010 21:34:22 +0200 Subject: [PATCH 09/19] Apply isaac's suggestion to package.json See: http://groups.google.com/group/nodejs/browse_thread/thread/8a4563cac244456d --- package.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index 596970239..b70e41410 100644 --- a/package.json +++ b/package.json @@ -1,5 +1,6 @@ { "name" : "mysql" , "version": "0.7.0" -, "dependencies": {"gently": ">=0.8.0"} +, "devDependencies": {"gently": ">=0.8.0"} , "main" : "./lib/mysql" +, "scripts" : { "test" : "make test-all" } } From eb46be92dacac32bf3aada4dfadfc3ecdc906d8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 29 Oct 2010 16:09:58 +0200 Subject: [PATCH 10/19] Move system test config into own file This makes it easier for people to have their own database config for system tests. --- .gitignore | 1 + test/common.js | 16 +++++++++------- test/config.template.js | 8 ++++++++ 3 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 test/config.template.js diff --git a/.gitignore b/.gitignore index 7f7017231..fbceb944c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ +/test/config.js *.swo *.un~ diff --git a/test/common.js b/test/common.js index d89624c52..ce9e43a8e 100644 --- a/test/common.js +++ b/test/common.js @@ -2,14 +2,16 @@ var path = require('path'); require.paths.unshift(path.dirname(__dirname)+'/lib'); var sys = require('mysql/sys'); -global.TEST_DB = 'node_mysql_test'; -global.TEST_CONFIG = { - host: 'localhost', - port: 3306, - user: 'root', - password: 'root' -}; +if (module.parent.filename.match(/test\/system/)) { + try { + global.TEST_CONFIG = require('./config.js'); + } catch (e) { + console.log('Skipping. See test/config.template.js for more information.'); + process.exit(0); + } +} +global.TEST_DB = 'node_mysql_test'; global.TEST_TABLE = 'posts'; global.TEST_FIXTURES = path.join(__dirname, 'fixture'); diff --git a/test/config.template.js b/test/config.template.js new file mode 100644 index 000000000..e927ab8d8 --- /dev/null +++ b/test/config.template.js @@ -0,0 +1,8 @@ +// Copy this file to test/config.js and fill in your own credentials in order +// to run the system test suite. +module.exports = { + host: 'localhost', + port: 3306, + user: 'root', + password: 'root' +}; From dbaec6d78c221b9085e6edc0df2ee1549356b030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Mon, 25 Oct 2010 19:59:17 +0200 Subject: [PATCH 11/19] Fixed parser test on all node-versions In the past we were relying on the fact that invalid utf8 sequences would not effect the length of the new buffer. We need to explictely declare the binary string type if we want to create a buffer with a 0 byte. --- test/simple/test-parser.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/simple/test-parser.js b/test/simple/test-parser.js index 46fcba733..e2e7f4eb6 100644 --- a/test/simple/test-parser.js +++ b/test/simple/test-parser.js @@ -58,7 +58,7 @@ test(function write() { assert.equal(parser.state, Parser.GREETING_SERVER_VERSION); var VERSION = 'MySql 5.1'; - parser.write(new Buffer(VERSION+'\0\0')); + parser.write(new Buffer(VERSION+'\0', 'binary')); assert.equal(packet.serverVersion, VERSION); assert.equal(parser.state, Parser.GREETING_THREAD_ID); From e724fd54b18668a2e050a7fa4dd4b672900fc5d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Mon, 25 Oct 2010 20:00:21 +0200 Subject: [PATCH 12/19] Allow running test suites individually --- Makefile | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 171ba8af0..2ea8b48d1 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ -test: +test-simple: @find test/simple/test-*.js | xargs -n 1 -t node +test-system: @find test/system/test-*.js | xargs -n 1 -t node +test: test-simple test-system test-all: test @find test/system/slow/test-*.js | xargs -n 1 -t node benchmark-node-mysql: From 0bf10a7dab9431c1f77c4d2302e172fb9f8eaad2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 29 Oct 2010 16:40:27 +0200 Subject: [PATCH 13/19] Fix module include --- test/common.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/common.js b/test/common.js index ce9e43a8e..47c8e88da 100644 --- a/test/common.js +++ b/test/common.js @@ -4,7 +4,7 @@ var sys = require('mysql/sys'); if (module.parent.filename.match(/test\/system/)) { try { - global.TEST_CONFIG = require('./config.js'); + global.TEST_CONFIG = require('./config'); } catch (e) { console.log('Skipping. See test/config.template.js for more information.'); process.exit(0); From a107dc6623ea639de64237e4a11a2694eb6d162e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 29 Oct 2010 20:22:09 +0200 Subject: [PATCH 14/19] Fix bad handling of null values Null values were causing problems in columns when typecasting them. This patch makes sure null values are never typecasted. --- lib/mysql/query.js | 2 +- test/system/test-client-query.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/mysql/query.js b/lib/mysql/query.js index 33fcabc66..983bc8c4f 100644 --- a/lib/mysql/query.js +++ b/lib/mysql/query.js @@ -67,7 +67,7 @@ Query.prototype._handlePacket = function(packet) { if (remaining == 0) { self._rowIndex++; - if (self.typeCast) { + if (self.typeCast && buffer !== null) { switch (field.fieldType) { case Query.FIELD_TYPE_TIMESTAMP: case Query.FIELD_TYPE_DATE: diff --git a/test/system/test-client-query.js b/test/system/test-client-query.js index 6a055de00..93bea5748 100644 --- a/test/system/test-client-query.js +++ b/test/system/test-client-query.js @@ -47,7 +47,7 @@ client.query( var query = client.query( 'INSERT INTO '+TEST_TABLE+' '+ 'SET title = ?, text = ?, created = ?', - ['another entry', 'because 2 entries make a better test', '2010-08-16 12:42:15'] + ['another entry', 'because 2 entries make a better test', null] ); query.on('end', gently.expect(function insertOkCb(packet) { @@ -63,7 +63,8 @@ var query = client.query( assert.equal(results.length, 2); assert.equal(results[1].title, 'another entry'); assert.ok(typeof results[1].id == 'number'); - assert.ok(results[1].created instanceof Date); + assert.ok(results[0].created instanceof Date); + assert.strictEqual(results[1].created, null); client.end(); }) ); From 99cad60434dd8b5d8174881e7ed866ac1b7b8f16 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Fri, 29 Oct 2010 20:25:22 +0200 Subject: [PATCH 15/19] Missing test for previous patch --- test/simple/test-query.js | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/test/simple/test-query.js b/test/simple/test-query.js index a23acfb98..7a64cccd2 100644 --- a/test/simple/test-query.js +++ b/test/simple/test-query.js @@ -117,7 +117,11 @@ test(function _handlePacket() { r = row.my_field; }); - fn(new Buffer(strValue), 0); + var val = (strValue === null) + ? null + : new Buffer(strValue); + + fn(val, 0); }); query._handlePacket(PACKET); @@ -142,4 +146,6 @@ test(function _handlePacket() { assert.strictEqual(typeCast(Query.FIELD_TYPE_FLOAT, '2.8'), 2.8); assert.strictEqual(typeCast(Query.FIELD_TYPE_DOUBLE, '2.8'), 2.8); assert.strictEqual(typeCast(Query.FIELD_TYPE_NEWDECIMAL, '2.8'), 2.8); + + assert.strictEqual(typeCast(Query.FIELD_TYPE_DATE, null), null); }); From 22adb45c76ea49a0d5e4a40bdc4775ea88bbe18f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sat, 30 Oct 2010 11:04:58 +0200 Subject: [PATCH 16/19] Make sure to catch all stream errors on connect It seems like some stream errors may occur sync, so one has to attach an error listener to the stream before executing `connect`. I'm not sure if this is how things should behave, will clarify with Ryan. --- lib/mysql/client.js | 2 +- test/simple/test-client.js | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/mysql/client.js b/lib/mysql/client.js index fd0bd1416..d2459134e 100644 --- a/lib/mysql/client.js +++ b/lib/mysql/client.js @@ -48,7 +48,6 @@ Client.prototype.connect = function(cb) { var connection = self._connection = new Stream(), parser = self._parser = new Parser(); - connection.connect(self.port, self.host); connection .on('error', function(err) { if (err.errno & (netBinding.ECONNREFUSED | netBinding.ENOTFOUND)) { @@ -77,6 +76,7 @@ Client.prototype.connect = function(cb) { self.connected = false; self._prequeue(connect); }); + connection.connect(self.port, self.host); parser .on('packet', function(packet) { diff --git a/test/simple/test-client.js b/test/simple/test-client.js index 102c12eea..ca5cbee45 100644 --- a/test/simple/test-client.js +++ b/test/simple/test-client.js @@ -74,17 +74,17 @@ test(function connect() { gently.expect(StreamStub, 'new', function() { CONNECTION = this; - gently.expect(CONNECTION, 'connect', function(port, host) { - assert.equal(port, client.port); - assert.equal(host, client.host); - }); - var events = ['error', 'data', 'end']; gently.expect(CONNECTION, 'on', events.length, function(event, fn) { assert.equal(event, events.shift()); onConnection[event] = fn; return this; }); + + gently.expect(CONNECTION, 'connect', function(port, host) { + assert.equal(port, client.port); + assert.equal(host, client.host); + }); }); gently.expect(ParserStub, 'new', function() { From 86a38e515eb355fade487538bd20e8d8cdbbc62b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sat, 30 Oct 2010 11:23:25 +0200 Subject: [PATCH 17/19] Do not ignore connection errors when no callback provided Couldn't come up with a good unit test for this, need better testing gear soon. --- lib/mysql/client.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/mysql/client.js b/lib/mysql/client.js index d2459134e..4d7580e48 100644 --- a/lib/mysql/client.js +++ b/lib/mysql/client.js @@ -53,8 +53,8 @@ Client.prototype.connect = function(cb) { if (err.errno & (netBinding.ECONNREFUSED | netBinding.ENOTFOUND)) { if (cb) { cb(err); + return; } - return; } self.emit('error', err); From 2461915748fcf819e004d1dd1606bb1853fdf57d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sat, 30 Oct 2010 15:17:05 +0200 Subject: [PATCH 18/19] Properly handle initial error packets Those packets can happen in situations where mysql is refusing connections due to the max_connections setting. --- Makefile | 8 ++- lib/mysql/parser.js | 15 +++++ test/simple/test-parser.js | 19 +++++- .../dangerous/test-client-max-connections.js | 58 +++++++++++++++++++ 4 files changed, 97 insertions(+), 3 deletions(-) create mode 100644 test/system/dangerous/test-client-max-connections.js diff --git a/Makefile b/Makefile index 2ea8b48d1..a3cf21c21 100644 --- a/Makefile +++ b/Makefile @@ -2,9 +2,13 @@ test-simple: @find test/simple/test-*.js | xargs -n 1 -t node test-system: @find test/system/test-*.js | xargs -n 1 -t node -test: test-simple test-system -test-all: test +test-system-slow: @find test/system/slow/test-*.js | xargs -n 1 -t node +# Dangerous tests potentially effect the MySql server settings, don't run these in production! +test-system-dangerous: + @find test/system/dangerous/test-*.js | xargs -n 1 -t node +test: test-simple test-system +test-all: test test-system-slow test-system-dangerous benchmark-node-mysql: @find benchmark/node-mysql/*.js | xargs -n 1 -t node benchmark-php: diff --git a/lib/mysql/parser.js b/lib/mysql/parser.js index 87bddf428..b737209d9 100644 --- a/lib/mysql/parser.js +++ b/lib/mysql/parser.js @@ -121,6 +121,14 @@ Parser.prototype.write = function(buffer) { // GREETING_PACKET case Parser.GREETING_PROTOCOL_VERSION: + // Nice undocumented MySql gem, the initial greeting can be an error + // packet. Happens for too many connections errors. + if (c === 0xff) { + packet.type = Parser.ERROR_PACKET; + advance(Parser.ERROR_NUMBER); + break; + } + // 1 byte packet.type = Parser.GREETING_PACKET; packet.protocolVersion = c; @@ -245,6 +253,13 @@ Parser.prototype.write = function(buffer) { packet.errorNumber += POWS[packet.index] * c; if (packet.index == 1) { + if (!this.greeted) { + // Turns out error packets are confirming to the 4.0 protocol when + // not greeted yet. Oh MySql, you are such a thing of beauty ... + advance(Parser.ERROR_MESSAGE); + break; + } + advance(); } break; diff --git a/test/simple/test-parser.js b/test/simple/test-parser.js index e2e7f4eb6..9e95eecb6 100644 --- a/test/simple/test-parser.js +++ b/test/simple/test-parser.js @@ -45,12 +45,29 @@ test(function write() { ); })(); - (function testPacketSize() { + (function testPacketNumber() { parser.write(new Buffer([42])); assert.strictEqual(packet.number, 42); assert.equal(parser.state, Parser.GREETING_PROTOCOL_VERSION); })(); + (function testGreetingErrorPacket() { + parser.write(new Buffer([0xff])); + assert.equal(packet.type, Parser.ERROR_PACKET); + assert.equal(parser.state, Parser.ERROR_NUMBER); + + parser.write(new Buffer([5, 2])); + assert.equal(packet.errorNumber, Math.pow(256, 0) * 5 + Math.pow(256, 1) * 2); + + parser.write(new Buffer('Hello World')); + assert.equal(packet.errorMessage, 'Hello World'); + + // Reset back to previous state + packet.type = Parser.GREETING_PACKET; + packet.received = 0; + parser.state = Parser.GREETING_PROTOCOL_VERSION; + })(); + (function testGreetingPacket() { parser.write(new Buffer([15])); assert.equal(packet.type, Parser.GREETING_PACKET); diff --git a/test/system/dangerous/test-client-max-connections.js b/test/system/dangerous/test-client-max-connections.js new file mode 100644 index 000000000..45e537d5a --- /dev/null +++ b/test/system/dangerous/test-client-max-connections.js @@ -0,0 +1,58 @@ +require('../../common'); +var Client = require('mysql').Client, + mainClient = Client(TEST_CONFIG), + originalMaxConnections; + + +function setMaxConnectionsToOne() { + mainClient.connect(); + // First we figure out the current max_connections value, so we can restore that after the test + mainClient.query('SHOW VARIABLES WHERE Variable_name = ?', ['max_connections'], function(err, results) { + if (err) throw err; + + originalMaxConnections = parseInt(results[0].Value); + if (originalMaxConnections === 1) { + console.log( + 'MySql already had max_connections set to 1. '+ + 'This probably happened because of a mal-function in this test, so re-setting to the MySql default of 100. '+ + 'If you had a higher value configured, you need to manually fix this now.' + ); + originalMaxConnections = 100; + } + + // Now we set max connections to 1, then we continue with our test + mainClient.query('SET GLOBAL max_connections = ?', [1], function() { + connectTwoClients(); + }); + }); +}; + +function connectTwoClients() { + var client1 = Client(TEST_CONFIG); + client1.connect(function(err) { + if (err) { + // There should be no error for the first connection, but if there is one + // anyway, let's try to at least restore the server config before throwing + restoreMaxConnections(function() { + throw err; + }); + return; + } + + var client2 = Client(TEST_CONFIG); + client2.connect(function(err) { + assert.strictEqual(err.number, Client.ERROR_CON_COUNT_ERROR); + + client1.end(); + restoreMaxConnections(); + }); + }); +} + +function restoreMaxConnections(cb) { + mainClient.query('SET GLOBAL max_connections = ?', [originalMaxConnections], cb); + mainClient.end(); +} + +setMaxConnectionsToOne(); + From 80cdfe90c8020f9b751106ce3667b8bdd52ba05a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20Geisend=C3=B6rfer?= Date: Sat, 30 Oct 2010 15:24:42 +0200 Subject: [PATCH 19/19] Bump version Also not executing all tests in the config since a new class of tests were introduced that are potentially effecting server configuration. --- package.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index b70e41410..3150ad4d8 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name" : "mysql" -, "version": "0.7.0" +, "version": "0.8.0" , "devDependencies": {"gently": ">=0.8.0"} , "main" : "./lib/mysql" -, "scripts" : { "test" : "make test-all" } +, "scripts" : { "test" : "make test" } }