mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
Test cleanup
This commit is contained in:
parent
f12eb0a6fd
commit
132861f43f
@ -34,7 +34,8 @@ suite.test('emits notify message', function (done) {
|
||||
|
||||
suite.test('emits notice message', function (done) {
|
||||
if (helper.args.native) {
|
||||
return console.error('need to get notice message working on native')
|
||||
console.error('need to get notice message working on native')
|
||||
return done()
|
||||
}
|
||||
//TODO this doesn't work on all versions of postgres
|
||||
var client = helper.client();
|
||||
|
||||
@ -1,7 +1,9 @@
|
||||
var helper = require('./test-helper');
|
||||
var Query = helper.pg.Query;
|
||||
|
||||
test("named prepared statement", function() {
|
||||
var suite = new helper.Suite()
|
||||
|
||||
;(function() {
|
||||
|
||||
var client = helper.client();
|
||||
client.on('drain', client.end.bind(client));
|
||||
@ -9,7 +11,7 @@ test("named prepared statement", function() {
|
||||
var queryName = "user by age and like name";
|
||||
var parseCount = 0;
|
||||
|
||||
test("first named prepared statement", function() {
|
||||
suite.test("first named prepared statement", function(done) {
|
||||
var query = client.query(new Query({
|
||||
text: 'select name from person where age <= $1 and name LIKE $2',
|
||||
values: [20, 'Bri%'],
|
||||
@ -20,11 +22,10 @@ test("named prepared statement", function() {
|
||||
assert.equal(row.name, 'Brian');
|
||||
});
|
||||
|
||||
assert.emits(query, 'end', function() {
|
||||
});
|
||||
query.on('end', () => done())
|
||||
});
|
||||
|
||||
test("second named prepared statement with same name & text", function() {
|
||||
suite.test("second named prepared statement with same name & text", function(done) {
|
||||
var cachedQuery = client.query(new Query({
|
||||
text: 'select name from person where age <= $1 and name LIKE $2',
|
||||
name: queryName,
|
||||
@ -35,11 +36,10 @@ test("named prepared statement", function() {
|
||||
assert.equal(row.name, 'Aaron');
|
||||
});
|
||||
|
||||
assert.emits(cachedQuery, 'end', function() {
|
||||
});
|
||||
cachedQuery.on('end', () => done())
|
||||
});
|
||||
|
||||
test("with same name, but without query text", function() {
|
||||
suite.test("with same name, but without query text", function(done) {
|
||||
var q = client.query(new Query({
|
||||
name: queryName,
|
||||
values: [30, '%n%']
|
||||
@ -54,23 +54,19 @@ test("named prepared statement", function() {
|
||||
});
|
||||
});
|
||||
|
||||
assert.emits(q, 'end', function() { });
|
||||
q.on('end', () => done())
|
||||
});
|
||||
});
|
||||
})();
|
||||
|
||||
test("prepared statements on different clients", function() {
|
||||
;(function() {
|
||||
var statementName = "differ";
|
||||
var statement1 = "select count(*)::int4 as count from person";
|
||||
var statement2 = "select count(*)::int4 as count from person where age < $1";
|
||||
|
||||
var client1Finished = false;
|
||||
var client2Finished = false;
|
||||
|
||||
var client1 = helper.client();
|
||||
|
||||
var client2 = helper.client();
|
||||
|
||||
test("client 1 execution", function() {
|
||||
suite.test("client 1 execution", function(done) {
|
||||
|
||||
var query = client1.query({
|
||||
name: statementName,
|
||||
@ -78,83 +74,72 @@ test("prepared statements on different clients", function() {
|
||||
}, (err, res) => {
|
||||
assert(!err);
|
||||
assert.equal(res.rows[0].count, 26);
|
||||
if(client2Finished) {
|
||||
client1.end();
|
||||
client2.end();
|
||||
} else {
|
||||
client1Finished = true;
|
||||
}
|
||||
done()
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
test('client 2 execution', function() {
|
||||
suite.test('client 2 execution', function(done) {
|
||||
var query = client2.query(new Query({
|
||||
name: statementName,
|
||||
text: statement2,
|
||||
values: [11]
|
||||
}));
|
||||
|
||||
test('gets right data', function() {
|
||||
assert.emits(query, 'row', function(row) {
|
||||
assert.equal(row.count, 1);
|
||||
});
|
||||
assert.emits(query, 'row', function(row) {
|
||||
assert.equal(row.count, 1);
|
||||
});
|
||||
|
||||
assert.emits(query, 'end', function() {
|
||||
if(client1Finished) {
|
||||
client1.end();
|
||||
client2.end();
|
||||
} else {
|
||||
client2Finished = true;
|
||||
}
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
suite.test('clean up clients', () => {
|
||||
return client1.end().then(() => client2.end())
|
||||
});
|
||||
|
||||
test('prepared statement', function() {
|
||||
})();
|
||||
|
||||
;(function() {
|
||||
var client = helper.client();
|
||||
client.on('drain', client.end.bind(client));
|
||||
client.query('CREATE TEMP TABLE zoom(name varchar(100));');
|
||||
client.query("INSERT INTO zoom (name) VALUES ('zed')");
|
||||
client.query("INSERT INTO zoom (name) VALUES ('postgres')");
|
||||
client.query("INSERT INTO zoom (name) VALUES ('node postgres')");
|
||||
|
||||
var checkForResults = function(q) {
|
||||
test('row callback fires for each result', function() {
|
||||
assert.emits(q, 'row', function(row) {
|
||||
assert.equal(row.name, 'node postgres');
|
||||
var checkForResults = function (q) {
|
||||
assert.emits(q, 'row', function (row) {
|
||||
assert.equal(row.name, 'node postgres');
|
||||
|
||||
assert.emits(q, 'row', function(row) {
|
||||
assert.equal(row.name, 'postgres');
|
||||
assert.emits(q, 'row', function (row) {
|
||||
assert.equal(row.name, 'postgres');
|
||||
|
||||
assert.emits(q, 'row', function(row) {
|
||||
assert.equal(row.name, 'zed');
|
||||
})
|
||||
});
|
||||
})
|
||||
assert.emits(q, 'row', function (row) {
|
||||
assert.equal(row.name, 'zed');
|
||||
})
|
||||
});
|
||||
})
|
||||
};
|
||||
|
||||
test('with small row count', function() {
|
||||
suite.test('with small row count', function (done) {
|
||||
var query = client.query(new Query({
|
||||
name: 'get names',
|
||||
text: "SELECT name FROM zoom ORDER BY name",
|
||||
rows: 1
|
||||
}));
|
||||
}, done));
|
||||
|
||||
checkForResults(query);
|
||||
|
||||
})
|
||||
|
||||
test('with large row count', function() {
|
||||
suite.test('with large row count', function (done) {
|
||||
var query = client.query(new Query({
|
||||
name: 'get names',
|
||||
text: 'SELECT name FROM zoom ORDER BY name',
|
||||
rows: 1000
|
||||
}))
|
||||
}, done))
|
||||
checkForResults(query);
|
||||
})
|
||||
|
||||
})
|
||||
suite.test('cleanup', () => client.end())
|
||||
})()
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user