1 var common = require('../common');
2 var assert = require('assert');
3 var test = common.fastOrSlow.slow();
5 test.before(function() {
6 this.client = common.createClient();
9 test.after(function(done) {
10 var connected = this.client.connected;
11 this.client.end(function(err) {
13 ? assert.equal(err, null)
14 : assert.notEqual(err, null);
20 test('Client tries to connect automatically', function(done) {
21 this.client.query('SELECT 1', function(err, results) {
22 assert.deepEqual(results, [{1: 1}]);
27 test('Connection errors are delegated to callback', function(done) {
28 // Port number outside of range -> triggers connection error
29 this.client.port = 999999999;
32 this.client.query('SELECT 1', function(err) {
37 this.client.query('SELECT 2', function(err) {
41 assert.deepEqual(callbacks, [1, 2]);
46 test('Bad credentials', function(done) {
47 this.client.password = 'thispassworddoesnotreallywork';
50 this.client.query('SELECT 1', function(err) {
55 this.client.query('SELECT 2', function(err) {
59 assert.deepEqual(callbacks, [1, 2]);
64 test('Reconnecting a closed client works', function(done) {
66 this.client.query('SELECT 1', function() {
70 this.client.end(function() {
74 this.client.query('SELECT 1', function(err) {
75 assert.deepEqual(cbs, [1, 2]);
80 test('Reconnect on timeout', {timeout: 2000}, function(done) {
81 // Not sure if we need all 3 of these, but they do the trick
82 this.client.query('SET interactive_timeout = 1');
83 this.client.query('SET wait_timeout = 1');
84 this.client.query('SET net_read_timeout = 1');
87 this.client._socket.on('end', function() {
88 assert.equal(self.client.connected, false);
90 self.client.query('SELECT 1', function(err) {