Skip to content

Commit

Permalink
Improves failure tests
Browse files Browse the repository at this point in the history
  • Loading branch information
godu committed Mar 25, 2016
1 parent 29561a4 commit 62b1ddc
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 48 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
"test": "npm run lint && npm run nyc",
"lint": "eslint .",
"ava": "RUNNING_UNIT_TESTS=true ava",
"nyc": "RUNNING_UNIT_TESTS=true nyc --reporter=lcov ava",
"nyc": "RUNNING_UNIT_TESTS=true nyc ava",
"nyc:lcov": "npm run nyc -- --reporter=lcov",
"coveralls": "nyc report --reporter=text-lcov | coveralls"
},
"repository": {
Expand Down
51 changes: 42 additions & 9 deletions src/test/reconnect.js → src/test/failure.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ var _ = require('lodash/fp');
var Promise = require('bluebird');
var httpProxy = require('http-proxy');
var createEtcdDriver = require('../etcd-driver');
var createSquirrel = require('../');
var generateCwd = require('./helpers/generate-cwd');
var retry = require('./helpers/retry');

var PORT = 42379;
test.beforeEach('create proxy', function(t) {
Expand All @@ -15,8 +17,8 @@ test.beforeEach('create proxy', function(t) {
listen: function(cb) {
proxy.listen(port, cb);
},
close: function() {
proxy.close();
close: function(cb) {
proxy.close(cb);
},
host: 'http://localhost:' + port
};
Expand All @@ -26,13 +28,17 @@ test.afterEach('close proxy', function(t) {
t.context.proxy.close();
});

test('should resync', function(t) {
test('should emit resync', function(t) {
var cwd = generateCwd();

var driver = createEtcdDriver({
cwd: cwd
});

var squirrel = createSquirrel({
cwd: cwd
});

return Promise.fromCallback(function(cb) {
driver.watch({
resync: function(err) {
Expand All @@ -43,10 +49,14 @@ test('should resync', function(t) {
Promise.all(_.map(function(value) {
return driver.set('/foo', value.toString());
}, _.range(0, 1200)));
}).then(function() {
return retry(squirrel, '/foo', function(node) {
return node.value === '1199';
});
});
});

test('should reconnect', function(t) {
test('should emit reconnect', function(t) {
var cwd = generateCwd();

return Promise.fromCallback(function(cb) {
Expand All @@ -57,12 +67,35 @@ test('should reconnect', function(t) {
hosts: t.context.proxy.host
});

return Promise.fromCallback(function(cb) {
driver.watch({
reconnect: cb
});
var squirrel = createSquirrel({
cwd: cwd,
hosts: t.context.proxy.host
});

t.context.proxy.close();
var backup = createEtcdDriver({
cwd: cwd
});

return Promise.all([
Promise.fromCallback(function(cb) {
driver.watch({
reconnect: function(err) {
cb();
}
});
}),
retry(squirrel, '/foo', function(node) {
return node.value === 'yolo';
}),
new Promise(function(resolve, reject) {
t.context.proxy.close(function() {
backup.set('/foo', 'yolo').then(resolve, reject);
});
}).then(function() {
setTimeout(function() {
t.context.proxy.listen();
}, 10);
})
]);
});
});
File renamed without changes.
11 changes: 5 additions & 6 deletions src/test/accessors.js → src/test/indexes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
var path = require('path');
var test = require('ava');
var generateCwd = require('./helpers/generate-cwd');

var createSquirrel = require('..');

test('should find by name', function(t) {
var squirrel = createSquirrel({
cwd: generateCwd(),
fallback: path.join(__dirname, 'fixtures/accessors.json'),
fallback: path.join(__dirname, 'fixtures/indexes.json'),
fetch: false,
indexes: ['name']
});
Expand All @@ -30,7 +29,7 @@ test('should find by name', function(t) {
test('should find by host', function(t) {
var squirrel = createSquirrel({
cwd: generateCwd(),
fallback: path.join(__dirname, 'fixtures/accessors.json'),
fallback: path.join(__dirname, 'fixtures/indexes.json'),
fetch: false,
indexes: ['host']
});
Expand All @@ -51,7 +50,7 @@ test('should find by host', function(t) {
test('should find by meta.foo', function(t) {
var squirrel = createSquirrel({
cwd: generateCwd(),
fallback: path.join(__dirname, 'fixtures/accessors.json'),
fallback: path.join(__dirname, 'fixtures/indexes.json'),
fetch: false,
indexes: ['meta.foo']
});
Expand All @@ -72,7 +71,7 @@ test('should find by meta.foo', function(t) {
test('should get all names', function(t) {
var squirrel = createSquirrel({
cwd: generateCwd(),
fallback: path.join(__dirname, 'fixtures/accessors.json'),
fallback: path.join(__dirname, 'fixtures/indexes.json'),
fetch: false,
indexes: ['name']
});
Expand All @@ -95,7 +94,7 @@ test('should get all names', function(t) {
test('should get all meta.foo', function(t) {
var squirrel = createSquirrel({
cwd: generateCwd(),
fallback: path.join(__dirname, 'fixtures/accessors.json'),
fallback: path.join(__dirname, 'fixtures/indexes.json'),
fetch: false,
indexes: ['meta.foo']
});
Expand Down
32 changes: 0 additions & 32 deletions src/util/test.js

This file was deleted.

0 comments on commit 62b1ddc

Please sign in to comment.