From 291e25711640ff075e81e8cea8e638768e283f48 Mon Sep 17 00:00:00 2001 From: jeromew Date: Fri, 15 Mar 2019 15:15:45 +0000 Subject: [PATCH] Add test for copy-to pg client re-use --- test/copy-to.js | 34 +++++++++++++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/test/copy-to.js b/test/copy-to.js index 07cf297..d49eea9 100644 --- a/test/copy-to.js +++ b/test/copy-to.js @@ -22,7 +22,6 @@ var testConstruction = function() { var stream = copy(txt, {highWaterMark: 10}) assert.equal(stream._readableState.highWaterMark, 10, 'Client should have been set with a correct highWaterMark.') } - testConstruction() var testComparators = function() { @@ -118,4 +117,37 @@ var testNoticeResponse = function() { } testNoticeResponse(); +var testClientReuse = function() { + var c = client(); + var limit = 100000; + var countMax = 10; + var countA = countMax; + var countB = 0; + var runStream = function(num, callback) { + var sql = "COPY (SELECT * FROM generate_series(0,"+limit+")) TO STDOUT" + var stream = c.query(copy(sql)) + stream.on('error', callback) + stream.pipe(concat(function(buf) { + var res = buf.toString('utf8'); + var exp = _.range(0, limit+1).join('\n') + '\n' + assert.equal(res, exp, 'clientReuse: sent & received buffer should be equal') + countB++; + callback(); + })) + } + + var rs = function(err) { + assert.equal(err, null, err) + countA--; + if (countA) { + runStream(countB, rs) + } else { + assert.equal(countB, countMax, 'clientReuse: there should be countMax queries on the same client') + c.end() + } + }; + runStream(countB, rs); + +} +testClientReuse();