<commit_before>var helper = require(__dirname + '/test-helper');
var Connection = require(__dirname + '/../../../lib/connection');
var Client = require(__dirname + '/../../../lib/client');

test('emits end when not in query', function() {
  var stream = new (require('events').EventEmitter)();
  stream.write = function() {
    //NOOP
  }
  var client = new Client({connection: new Connection({stream: stream})});
  client.connect(assert.calls(function() {
    client.query('SELECT NOW()', assert.calls(function(err, result) {
      assert(err);
    }));
  }));
  assert.emits(client, 'end');
  client.connection.emit('connect');
  process.nextTick(function() {
    client.connection.emit('readyForQuery');
    assert.equal(client.queryQueue.length, 0);
    assert(client.activeQuery, 'client should have issued query');
    process.nextTick(function() {
      stream.emit('end');
    });
  });
});<commit_msg>Have stream emit 'close' rather than 'end' for sake of testing<commit_after>var helper = require(__dirname + '/test-helper');
var Connection = require(__dirname + '/../../../lib/connection');
var Client = require(__dirname + '/../../../lib/client');

test('emits end when not in query', function() {
  var stream = new (require('events').EventEmitter)();
  stream.write = function() {
    //NOOP
  }
  var client = new Client({connection: new Connection({stream: stream})});
  client.connect(assert.calls(function() {
    client.query('SELECT NOW()', assert.calls(function(err, result) {
      assert(err);
    }));
  }));
  assert.emits(client, 'end');
  client.connection.emit('connect');
  process.nextTick(function() {
    client.connection.emit('readyForQuery');
    assert.equal(client.queryQueue.length, 0);
    assert(client.activeQuery, 'client should have issued query');
    process.nextTick(function() {
      stream.emit('close');
    });
  });
});
{'fraction_non_alphanumeric': 0.1913415285943346, 'fraction_numerical': 0.0010689470871191875, 'mean_word_length': 3.9655172413793105, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4042461', 'n_tokens_mistral': 543, 'n_tokens_neox': 548, 'n_words': 118}