mirror of
https://github.com/brianc/node-postgres.git
synced 2026-01-18 15:55:05 +00:00
add tests that checks error reporting for incorrect copy to/copy from usage. add tests for fixed bug in native copy from implementation
This commit is contained in:
parent
7ca21acb25
commit
583d059947
@ -95,4 +95,66 @@ test('COPY TO, queue queries', function () {
|
||||
});
|
||||
});
|
||||
});
|
||||
test("COPY TO incorrect usage with large data", function () {
|
||||
//when many data is loaded from database (and it takes a lot of time)
|
||||
//there are chance, that query will be canceled before it ends
|
||||
//but if there are not so much data, cancel message may be
|
||||
//send after copy query ends
|
||||
//so we need to test both situations
|
||||
pg.connect(helper.config, function (error, client) {
|
||||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error));
|
||||
//intentionally incorrect usage of copy.
|
||||
//this has to report error in standart way, instead of just throwing exception
|
||||
client.query(
|
||||
"COPY (SELECT GENERATE_SERIES(1, 10000000)) TO STDOUT WITH CSV",
|
||||
assert.calls(function (error) {
|
||||
assert.ok(error, "error should be reported when sending copy to query with query method");
|
||||
client.query("SELECT 1", assert.calls(function (error, result) {
|
||||
assert.isNull(error, "incorrect copy usage should not break connection");
|
||||
assert.ok(result, "incorrect copy usage should not break connection");
|
||||
pg.end(helper.config);
|
||||
}));
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
test("COPY TO incorrect usage with small data", function () {
|
||||
pg.connect(helper.config, function (error, client) {
|
||||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error));
|
||||
//intentionally incorrect usage of copy.
|
||||
//this has to report error in standart way, instead of just throwing exception
|
||||
client.query(
|
||||
"COPY (SELECT GENERATE_SERIES(1, 1)) TO STDOUT WITH CSV",
|
||||
assert.calls(function (error) {
|
||||
assert.ok(error, "error should be reported when sending copy to query with query method");
|
||||
client.query("SELECT 1", assert.calls(function (error, result) {
|
||||
assert.isNull(error, "incorrect copy usage should not break connection");
|
||||
assert.ok(result, "incorrect copy usage should not break connection");
|
||||
pg.end(helper.config);
|
||||
}));
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
test("COPY FROM incorrect usage", function () {
|
||||
pg.connect(helper.config, function (error, client) {
|
||||
assert.equal(error, null, "Failed to connect: " + helper.sys.inspect(error));
|
||||
prepareTable(client, function () {
|
||||
//intentionally incorrect usage of copy.
|
||||
//this has to report error in standart way, instead of just throwing exception
|
||||
client.query(
|
||||
"COPY copy_test from STDIN WITH CSV",
|
||||
assert.calls(function (error) {
|
||||
assert.ok(error, "error should be reported when sending copy to query with query method");
|
||||
client.query("SELECT 1", assert.calls(function (error, result) {
|
||||
assert.isNull(error, "incorrect copy usage should not break connection");
|
||||
assert.ok(result, "incorrect copy usage should not break connection");
|
||||
pg.end(helper.config);
|
||||
}));
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
@ -20,6 +20,10 @@ test('COPY FROM events check', function () {
|
||||
test('COPY TO events check', function () {
|
||||
var con = new Client(helper.config),
|
||||
stdoutStream = con.copyTo('COPY person TO STDOUT');
|
||||
assert.emits(con, 'copyOutResponse',
|
||||
function () {},
|
||||
"backend should emit copyOutResponse on copyOutResponse message from server"
|
||||
);
|
||||
assert.emits(con, 'copyData',
|
||||
function () {
|
||||
},
|
||||
|
||||
23
test/native/copyto-largedata-tests.js
Normal file
23
test/native/copyto-largedata-tests.js
Normal file
@ -0,0 +1,23 @@
|
||||
var helper = require(__dirname+"/../test-helper");
|
||||
var Client = require(__dirname + "/../../lib/native");
|
||||
test("COPY TO large amount of data from postgres", function () {
|
||||
//there were a bug in native implementation of COPY TO:
|
||||
//if there were too much data (if we face situation
|
||||
//when data is not ready while calling PQgetCopyData);
|
||||
//while loop in Connection::HandleIOEvent becomes infinite
|
||||
//in such way hanging node, consumes 100% cpu, and making connection unusable
|
||||
var con = new Client(helper.config),
|
||||
rowCount = 100000,
|
||||
stdoutStream = con.copyTo('COPY (select generate_series(1, ' + rowCount + ')) TO STDOUT');
|
||||
con.connect();
|
||||
stdoutStream.on('data', function () {
|
||||
rowCount --;
|
||||
});
|
||||
stdoutStream.on('end', function () {
|
||||
assert.equal(rowCount, 1, "copy to should load exactly requested number of rows" + rowCount);
|
||||
con.query("SELECT 1", assert.calls(function (error, result) {
|
||||
assert.ok(!error && result, "loading large amount of data by copy to should not break connection");
|
||||
con.end();
|
||||
}));
|
||||
});
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user