cleanup & fix failing tests to allow for green merge of pull #228
This commit is contained in:
parent
0c487fc078
commit
1c43930ba1
@ -166,8 +166,9 @@ p.cancel = function(client, query) {
|
||||
con.cancel(client.processID, client.secretKey);
|
||||
});
|
||||
}
|
||||
else if (client.queryQueue.indexOf(query) != -1)
|
||||
else if (client.queryQueue.indexOf(query) != -1) {
|
||||
client.queryQueue.splice(client.queryQueue.indexOf(query), 1);
|
||||
}
|
||||
};
|
||||
|
||||
p._pulseQueryQueue = function() {
|
||||
|
17
lib/query.js
17
lib/query.js
@ -40,7 +40,18 @@ util.inherits(Query, EventEmitter);
|
||||
var p = Query.prototype;
|
||||
|
||||
p.requiresPreparation = function() {
|
||||
return (this.values || 0).length > 0 || this.name || this.rows || this.binary;
|
||||
//named queries must always be prepared
|
||||
if(this.name) return true;
|
||||
//always prepare if there are max number of rows expected per
|
||||
//portal execution
|
||||
if(this.rows) return true;
|
||||
//don't prepare empty text queries
|
||||
if(!this.text) return false;
|
||||
//binary should be prepared to specify results should be in binary
|
||||
//unless there are no parameters
|
||||
if(this.binary && !this.values) return false;
|
||||
//prepare if there are values
|
||||
return (this.values || 0).length > 0;
|
||||
};
|
||||
|
||||
|
||||
@ -139,7 +150,9 @@ p.prepare = function(connection) {
|
||||
name: self.name,
|
||||
types: self.types
|
||||
}, true);
|
||||
connection.parsedStatements[this.name] = true;
|
||||
if(this.name) {
|
||||
connection.parsedStatements[this.name] = true;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO is there some better way to prepare values for the database?
|
||||
|
@ -5,42 +5,42 @@ test("cancellation of a query", function() {
|
||||
|
||||
var client = helper.client();
|
||||
|
||||
var qry = client.query("select name from person order by name");
|
||||
var qry = "select name from person order by name";
|
||||
|
||||
client.on('drain', client.end.bind(client));
|
||||
|
||||
var rows1 = 0, rows2 = 0, rows3 = 0, rows4 = 0;
|
||||
var rows1 = 0, rows2 = 0, rows3 = 0, rows4 = 0;
|
||||
|
||||
var query1 = client.query(qry);
|
||||
query1.on('row', function(row) {
|
||||
rows1++;
|
||||
});
|
||||
var query2 = client.query(qry);
|
||||
query2.on('row', function(row) {
|
||||
rows2++;
|
||||
});
|
||||
var query3 = client.query(qry);
|
||||
query3.on('row', function(row) {
|
||||
rows3++;
|
||||
});
|
||||
var query4 = client.query(qry);
|
||||
query4.on('row', function(row) {
|
||||
rows4++;
|
||||
});
|
||||
var query1 = client.query(qry);
|
||||
query1.on('row', function(row) {
|
||||
rows1++;
|
||||
});
|
||||
var query2 = client.query(qry);
|
||||
query2.on('row', function(row) {
|
||||
rows2++;
|
||||
});
|
||||
var query3 = client.query(qry);
|
||||
query3.on('row', function(row) {
|
||||
rows3++;
|
||||
});
|
||||
var query4 = client.query(qry);
|
||||
query4.on('row', function(row) {
|
||||
rows4++;
|
||||
});
|
||||
|
||||
helper.pg.cancel(helper.config, client, query1);
|
||||
helper.pg.cancel(helper.config, client, query2);
|
||||
helper.pg.cancel(helper.config, client, query4);
|
||||
helper.pg.cancel(helper.config, client, query1);
|
||||
helper.pg.cancel(helper.config, client, query2);
|
||||
helper.pg.cancel(helper.config, client, query4);
|
||||
|
||||
setTimeout(function() {
|
||||
assert.equal(rows1, 0);
|
||||
assert.equal(rows2, 0);
|
||||
assert.equal(rows4, 0);
|
||||
}, 2000);
|
||||
setTimeout(function() {
|
||||
assert.equal(rows1, 0);
|
||||
assert.equal(rows2, 0);
|
||||
assert.equal(rows4, 0);
|
||||
}, 2000);
|
||||
|
||||
assert.emits(query3, 'end', function() {
|
||||
test("returned right number of rows", function() {
|
||||
assert.equal(rows3, 26);
|
||||
});
|
||||
});
|
||||
test("returned right number of rows", function() {
|
||||
assert.equal(rows3, 26);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -5,11 +5,11 @@ test("empty query message handling", function() {
|
||||
assert.emits(client, 'drain', function() {
|
||||
client.end();
|
||||
});
|
||||
client.query({text: "", binary: false});
|
||||
client.query({text: ""});
|
||||
});
|
||||
|
||||
test('callback supported', assert.calls(function() {
|
||||
client.query({text: "", binary: false}, function(err, result) {
|
||||
client.query("", function(err, result) {
|
||||
assert.isNull(err);
|
||||
assert.empty(result.rows);
|
||||
})
|
||||
|
@ -38,7 +38,7 @@ test("simple query interface", function() {
|
||||
|
||||
test("multiple simple queries", function() {
|
||||
var client = helper.client();
|
||||
client.query({ text: "create temp table bang(id serial, name varchar(5));insert into bang(name) VALUES('boom');", binary: false })
|
||||
client.query({ text: "create temp table bang(id serial, name varchar(5));insert into bang(name) VALUES('boom');"})
|
||||
client.query("insert into bang(name) VALUES ('yes');");
|
||||
var query = client.query("select name from bang");
|
||||
assert.emits(query, 'row', function(row) {
|
||||
@ -52,9 +52,9 @@ test("multiple simple queries", function() {
|
||||
|
||||
test("multiple select statements", function() {
|
||||
var client = helper.client();
|
||||
client.query({text: "create temp table boom(age integer); insert into boom(age) values(1); insert into boom(age) values(2); insert into boom(age) values(3)", binary: false});
|
||||
client.query({text: "create temp table bang(name varchar(5)); insert into bang(name) values('zoom');", binary: false});
|
||||
var result = client.query({text: "select age from boom where age < 2; select name from bang", binary: false});
|
||||
client.query("create temp table boom(age integer); insert into boom(age) values(1); insert into boom(age) values(2); insert into boom(age) values(3)");
|
||||
client.query({text: "create temp table bang(name varchar(5)); insert into bang(name) values('zoom');"});
|
||||
var result = client.query({text: "select age from boom where age < 2; select name from bang"});
|
||||
assert.emits(result, 'row', function(row) {
|
||||
assert.strictEqual(row['age'], 1);
|
||||
assert.emits(result, 'row', function(row) {
|
||||
|
@ -28,7 +28,7 @@ assert.same = function(actual, expected) {
|
||||
assert.emits = function(item, eventName, callback, message) {
|
||||
var called = false;
|
||||
var id = setTimeout(function() {
|
||||
test("Should have called " + eventName, function() {
|
||||
test("Should have called '" + eventName + "' event", function() {
|
||||
assert.ok(called, message || "Expected '" + eventName + "' to be called.")
|
||||
});
|
||||
},5000);
|
||||
|
Loading…
Reference in New Issue
Block a user