test refactoring

This commit is contained in:
Brian Carlson 2010-12-14 19:23:01 -06:00
parent af997d914b
commit fb463923d8
5 changed files with 55 additions and 33 deletions

View File

@ -51,4 +51,3 @@ test("multiple select statements", function() {
}); });
client.on('drain', client.end.bind(client)); client.on('drain', client.end.bind(client));
}); });

View File

@ -14,5 +14,6 @@ module.exports = {
return client; return client;
}, },
connectionString: helper.connectionString, connectionString: helper.connectionString,
Sink: helper.Sink Sink: helper.Sink,
pg: helper.pg
}; };

View File

@ -1,9 +1,9 @@
var helper = require(__dirname + '/test-helper'); var helper = require(__dirname + '/test-helper');
var sink;
var client = helper.client(); var connectionString = helper.connectionString();
client.on('drain', client.end.bind(client));
var testForTypeCoercion = function(type){ var testForTypeCoercion = function(type){
helper.pg.connect(connectionString, function(err, client) {
assert.isNull(err)
client.query("create temp table test_type(col " + type.name + ")"); client.query("create temp table test_type(col " + type.name + ")");
test("Coerces " + type.name, function() { test("Coerces " + type.name, function() {
@ -28,10 +28,12 @@ var testForTypeCoercion = function(type){
name: 'delete values', name: 'delete values',
text: 'delete from test_type' text: 'delete from test_type'
}); });
sink.add();
}); });
client.query('drop table test_type'); client.query('drop table test_type');
}); });
})
}; };
var types = [{ var types = [{
@ -76,9 +78,18 @@ var types = [{
values: ['13:12:12.321', null] values: ['13:12:12.321', null]
}]; }];
var valueCount = 0;
types.forEach(function(type) {
valueCount += type.values.length;
})
sink = new helper.Sink(valueCount, function() {
helper.pg.end();
})
types.forEach(testForTypeCoercion); types.forEach(testForTypeCoercion);
test("timestampz round trip", function() { test("timestampz round trip", function() {
var now = new Date(); var now = new Date();
var client = helper.client(); var client = helper.client();
client.on('error', function(err) { client.on('error', function(err) {
@ -112,6 +123,7 @@ test("timestampz round trip", function() {
}); });
}); });
client.on('drain', client.end.bind(client)); client.on('drain', client.end.bind(client));
}); });

View File

@ -11,10 +11,19 @@ var testPoolSize = function(max) {
test("can pool " + max + " times", function() { test("can pool " + max + " times", function() {
for(var i = 0; i < max; i++) { for(var i = 0; i < max; i++) {
helper.pg.poolSize = 10; helper.pg.poolSize = 10;
test("connection #" + i + " executes", function() {
helper.pg.connect(conString, function(err, client) { helper.pg.connect(conString, function(err, client) {
assert.isNull(err); assert.isNull(err);
client.query("select * from NOW()", function() { client.query("select * from person", function(err, result) {
sink.add(); assert.length(result.rows, 26)
})
client.query("select count(*) as c from person", function(err, result) {
assert.equal(result.rows[0].c, 26)
})
var query = client.query("SELECT * FROM NOW()")
query.on('end',function() {
sink.add()
})
}) })
}) })
} }

View File

@ -173,6 +173,7 @@ var Sink = function(expected, timeout, callback) {
module.exports = { module.exports = {
args: args, args: args,
Sink: Sink, Sink: Sink,
pg: require('index'),
connectionString: function() { connectionString: function() {
return "pg"+(count++)+"://"+args.user+":"+args.password+"@"+args.host+":"+args.port+"/"+args.database; return "pg"+(count++)+"://"+args.user+":"+args.password+"@"+args.host+":"+args.port+"/"+args.database;
} }