many tests

This commit is contained in:
Spencer Alger
2013-12-03 19:01:04 -07:00
parent 2ddde47972
commit 4e5f08a29c
19 changed files with 1011 additions and 201 deletions

View File

@ -3,6 +3,14 @@ var Host = require('../../src/lib/host');
var sinon = require('sinon');
var _ = require('lodash');
var stubs = [];
afterEach(function () {
var stub;
while (stub = stubs.pop()) {
stub.restore();
}
});
describe('Connection Abstract', function () {
var host = new Host('localhost:9200');
@ -75,6 +83,7 @@ describe('Connection Abstract', function () {
it('sets a timeout when set to dead, and removed when alive', function () {
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
stubs.push(clock);
var conn = new ConnectionAbstract(host);
var start = _.size(clock.timeouts);
@ -103,6 +112,7 @@ describe('Connection Abstract', function () {
it('should ping the connection after the deadTimeout, and set the status to "alive" on pong', function (done) {
var conn = new ConnectionAbstract(host);
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
stubs.push(clock);
// schedules the resuscitate
conn.setStatus('dead');
@ -128,6 +138,7 @@ describe('Connection Abstract', function () {
it('should ping the connection after the deadTimeout, and set the status to "dead" on error', function (done) {
var conn = new ConnectionAbstract(host);
var clock = sinon.useFakeTimers('setTimeout', 'clearTimeout');
stubs.push(clock);
// schedules the resuscitate
conn.setStatus('dead');
@ -142,7 +153,6 @@ describe('Connection Abstract', function () {
// will be called after the ping calls back
conn.setStatus = function (status) {
status.should.eql('dead');
clock.restore();
done();
};