2013-01-18 20:29:37 +08:00
|
|
|
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');
|
|
|
|
stdoutStream.on('data', function () {
|
2013-01-19 04:11:16 +08:00
|
|
|
rowCount--;
|
2013-01-18 20:29:37 +08:00
|
|
|
});
|
|
|
|
stdoutStream.on('end', function () {
|
2013-01-19 04:11:16 +08:00
|
|
|
assert.equal(rowCount, 0, "copy to should load exactly requested number of rows");
|
2013-01-18 20:29:37 +08:00
|
|
|
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();
|
|
|
|
}));
|
|
|
|
});
|
2013-01-19 04:11:16 +08:00
|
|
|
con.connect();
|
2013-01-18 20:29:37 +08:00
|
|
|
});
|