From e19235838da0aff961c8f0bfbe12baf0c3c04391 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Tue, 18 Mar 2014 13:19:07 +0100 Subject: [PATCH] Add unit test for callback on early postgresql disconnect Test adapted by that provided by Jess Sheneberger in #534 --- .../client/callback-on-early-disconnect.js | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 test/unit/client/callback-on-early-disconnect.js diff --git a/test/unit/client/callback-on-early-disconnect.js b/test/unit/client/callback-on-early-disconnect.js new file mode 100644 index 0000000..edf5748 --- /dev/null +++ b/test/unit/client/callback-on-early-disconnect.js @@ -0,0 +1,22 @@ +var helper = require(__dirname + '/test-helper'); +var net = require('net'); +var pg = require('../../..//lib/index.js'); + +var server = net.createServer(function(c) { + console.log('server connected'); + c.destroy(); + console.log('server socket destroyed.'); + server.close(function() { console.log('server closed'); }); +}); + +server.listen(7777, function() { + console.log('server listening'); + var client = new pg.Client('postgres://localhost:7777'); + console.log('client connecting'); + client.connect(assert.calls(function(err) { + if (err) console.log("Error on connect: "+err); + else console.log('client connected'); + assert(err); + })); + +});