mirror of
https://github.com/donl/slouch.git
synced 2026-05-31 06:12:20 -06:00
* doc(readme): clean up reasons * doc(motto) * test(db-and-doc): more coverage * test(create-or-update-ignore-conflict) * test(upsert) * test(ignore-missing) * test(post-and-ignore-conflict) * test(get-merge-put) * refactor(all): rename post and put * test(get-merge-create-or-update) * test(get-merge-update-ignore-conflict) * test(get-merge-upsert) * test(get-modify-upsert) * refactor(doc): redundant code * test(destroy-ignore-conflict) * test(get-and-destroy) * test(mark-as-destroyed) * test(set-destroyed) * refactor(attachment) * test(doc): 100% coverage * test(attachment): create with base 64 * test(attachment): clean up binary code * test(attachment): get * test(attachment): destroy * test(system): is couchdb 1 * test(system): get * test(system): reset * test(updates) * test(updates) * test(all): unique DB names * test(system): reactivate tests * test(user): add role * test(user): downsert role * feat(stream-iterator): indefinite * test(user): 100% coverage * test(request-class) * test(request-class): 100% coverage * test(config) * test(config): more coverage * test(config): more coverage * test(config): 100% coverage * test(all): 100% coverage * refactor(beautify) * test(coverage): enforce 100% * test(system): fix race condition * test(user): shortcut for browser * test(updates): test continuous stream in phantomjs * test(updates): test continuous stream in phantomjs * test(continuous): mock for phantomjs * test(system): abort iterators * test(system): fake abort
60 lines
1.4 KiB
JavaScript
60 lines
1.4 KiB
JavaScript
'use strict';
|
|
|
|
var request = require('../../scripts/request'),
|
|
sporks = require('sporks'),
|
|
Promise = require('sporks/scripts/promise'),
|
|
Backoff = require('backoff-promise');
|
|
|
|
describe('request', function () {
|
|
|
|
// Save so that it can be restored after mocking
|
|
var requestRequest = request._request,
|
|
requestNewBackoff = request._newBackoff;
|
|
|
|
afterEach(function () {
|
|
// Restore after mocking
|
|
request._request = requestRequest;
|
|
request._newBackoff = requestNewBackoff;
|
|
});
|
|
|
|
it('should handle ENOTFOUND errors', function () {
|
|
// Shorten the backoff as in a browser we just a "Failed to Fetch" error which triggers a retry
|
|
request._newBackoff = function () {
|
|
return new Backoff(1);
|
|
};
|
|
|
|
return sporks.shouldThrow(function () {
|
|
return request.request({
|
|
url: 'http://somethingbad.example.com'
|
|
});
|
|
});
|
|
});
|
|
|
|
it('should handle ECONNREFUSED errors', function () {
|
|
|
|
var n = 0;
|
|
|
|
// Shorten the backoff
|
|
request._newBackoff = function () {
|
|
return new Backoff(10);
|
|
};
|
|
|
|
request._request = function () {
|
|
if (++n === 3) {
|
|
// Simulate success after several failures
|
|
return Promise.resolve();
|
|
} else {
|
|
return requestRequest.apply(this, arguments);
|
|
}
|
|
};
|
|
|
|
return request.request({
|
|
url: 'http://127.0.0.1:1234'
|
|
}).then(function () {
|
|
n.should.eql(3);
|
|
});
|
|
});
|
|
|
|
// TODO: test handling of all_dbs_active errors
|
|
|
|
});
|