Permalink
Browse files

cleanup, bumping generic-pool version

  • Loading branch information...
BryanDonovan committed Dec 11, 2012
1 parent 55f6fc9 commit 6d62db7d1acc49e18cede97853b9b6d0e94d3286
Showing with 72 additions and 17 deletions.
  1. +3 −0 History.md
  2. +5 −5 lib/easy_client.js
  3. +6 −6 lib/easy_pool.js
  4. +2 −2 package.json
  5. +10 −1 test/easy_mysql.unit.js
  6. +46 −3 test/easy_mysql_stress.unit.js
View
@@ -18,3 +18,6 @@
- 0.6.4
Adding compatibility with node-mysql 0.9.1 (to be deprecated) and 2.0.0-alpha.
+
+- 0.6.5
+ Cleanup, bumping generic-pool version to 2.0.2.
View
@@ -19,7 +19,7 @@ function EasyClient(client, pool) {
* @returns {object} - The result returned by node-mysql.
*/
EasyClient.prototype.query = function (sql, query_params, cb) {
- return this.client.query(sql, query_params, cb);
+ this.client.query(sql, query_params, cb);
};
/**
@@ -40,10 +40,10 @@ EasyClient.prototype.end = function () {
function get_client_from_pool(pool, cb) {
pool.acquire(function (err, client) {
if (err) {
- return cb(err, null);
+ cb(err, null);
} else if (!client) {
// What should we do here? Maybe throw the error?
- return cb(new Error("Client not acquired"), null);
+ cb(new Error("Client not acquired"), null);
} else {
cb(null, new EasyClient(client, pool));
}
@@ -58,10 +58,10 @@ function get_client_from_pool(pool, cb) {
*/
EasyClient.fetch = function (settings, cb) {
if (settings.pool) {
- return get_client_from_pool(settings.pool, cb);
+ get_client_from_pool(settings.pool, cb);
} else if (settings.use_easy_pool) {
var pool = easy_pool.fetch(settings);
- return get_client_from_pool(pool, cb);
+ get_client_from_pool(pool, cb);
} else {
var client;
if (mysql.hasOwnProperty('createConnection')) {
View
@@ -11,9 +11,9 @@ var pool = {
/** @ignore */
create: function (settings) {
return pool_module.Pool({
- name : 'mysql_' + settings.database,
+ name: 'mysql_' + settings.database,
- create : function (callback) {
+ create: function (callback) {
var client;
if (mysql.hasOwnProperty(conn_method)) {
client = mysql[conn_method](settings);
@@ -25,15 +25,15 @@ var pool = {
callback(null, client);
},
- destroy : function (client) {
+ destroy: function (client) {
client.end();
},
- max : settings.pool_size || 10,
+ max: settings.pool_size || 10,
- idleTimeoutMillis : settings.idle_timeout || 5000,
+ idleTimeoutMillis: settings.idle_timeout || 5000,
- log : settings.log || false
+ log: settings.log || false
});
}
View
@@ -1,7 +1,7 @@
{
"name" : "easy-mysql",
"description" : "Light MySQL query wrapper with connection pooling.",
- "version" : "0.6.4",
+ "version" : "0.6.5",
"author" : "MOG, Inc.",
"contributors": [
{ "name": "Bryan Donovan" }
@@ -12,7 +12,7 @@
"url": "git://github.com:Mog-Inc/easy-mysql.git"
},
"dependencies": {
- "generic-pool" : "1.0.6",
+ "generic-pool" : "2.0.2",
"mysql" : ">=0.9.1"
},
"devDependencies": {
View
@@ -9,14 +9,23 @@ var setup_db = common.setup_db;
describe('EasyMySQL', function () {
var easy_mysql;
- beforeEach(function (done) {
+ before(function (done) {
setup_db(function (err, result) {
assert.ifError(err);
easy_mysql = EasyMySQL.connect(settings.db1);
done();
});
});
+ beforeEach(function(done) {
+ easy_mysql.execute("truncate widgets", function(err, result) {
+ assert.ifError(err);
+ setTimeout(function() {
+ done();
+ }, 10);
+ });
+ });
+
var execute_funcs = ['execute', 'query'];
execute_funcs.forEach(function (meth) {
@@ -10,10 +10,27 @@ var setup_db = common.setup_db;
describe('EasyMySQL stress tests', function () {
var easy_mysql;
- beforeEach(function (done) {
- setup_db(function (err, result) {
+ before(function (done) {
+ //easy_mysql = EasyMySQL.connect_with_easy_pool(settings.db1);
+ easy_mysql = EasyMySQL.connect(settings.db1);
+
+ var table_sql = "create table widgets( " +
+ "id int auto_increment primary key, " +
+ "name varchar(25)) ";
+
+ easy_mysql.execute('drop table if exists widgets', function(err, result) {
+ assert.ifError(err);
+
+ easy_mysql.execute(table_sql, function (err, result) {
+ assert.ifError(err);
+ done();
+ });
+ });
+ });
+
+ beforeEach(function(done) {
+ easy_mysql.execute('truncate widgets', function(err, result) {
assert.ifError(err);
- easy_mysql = EasyMySQL.connect(settings.db1);
done();
});
});
@@ -44,5 +61,31 @@ describe('EasyMySQL stress tests', function () {
done();
});
});
+
+ it('lets us insert and get results multiple times, again', function (done) {
+ this.timeout(10000);
+ var qty = 50;
+ var test_runs = [];
+ for (var i = 0; i < qty; i++) {
+ test_runs.push(i);
+ }
+
+ async.forEachSeries(test_runs, function (test_run, async_cb) {
+ var name = common.random_string();
+ var sql = "insert into widgets(name) values (?)";
+ easy_mysql.execute(sql, [name], function (err, result) {
+ if (err) { return async_cb(err); }
+
+ sql = "select * from widgets where name = ?";
+ easy_mysql.get_one(sql, [name], function (err, result) {
+ assert.ok(result, "Expected result when querying for name " + name);
+ async_cb(err, result);
+ });
+ });
+ }, function (err) {
+ assert.ifError(err);
+ done();
+ });
+ });
});
});

0 comments on commit 6d62db7

Please sign in to comment.