Skip to content
This repository has been archived by the owner on Mar 8, 2023. It is now read-only.

Commit

Permalink
test: extend retry, timeout & call tests
Browse files Browse the repository at this point in the history
  • Loading branch information
skenqbx committed Apr 23, 2015
1 parent e8b5e1d commit 74e5eb2
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 4 deletions.
3 changes: 2 additions & 1 deletion test/test-1-https.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ suite('https', function() {

rail.call({
proto: 'https',
port: common.port
port: common.port,
agent: null
}, function(response) {
response.on('readable', function() {
response.read();
Expand Down
15 changes: 15 additions & 0 deletions test/test-http-retry.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ suite('http:retry', function() {
});


test('configure', function() {
var options = {
retry: {}
};
rail.plugins.retry._configure(options);
assert.deepEqual(options, {retry: {interval: 20, limit: 3}});

options = {
retry: false
};
rail.plugins.retry._configure(options);
assert.deepEqual(options, {retry: {limit: 0}});
});


test('call', function(done) {
var retries = 0;

Expand Down
36 changes: 33 additions & 3 deletions test/test-http-timeout.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,57 @@ suite('http:timeout', function() {
suiteSetup(function(done) {
rail = new RAIL();
rail.use('timeout', {
response: 50
response: 20,
socket: 20
});

server = http.createServer(listener);
server.listen(common.port, done);
});


test('call', function(done) {
test('repsonse timeout', function(done) {
onrequest = function(request, response) {
response.end('pong');
};

var call = rail.call({
proto: 'http',
host: 'github.com',
port: 55555
port: 55555,
timeout: {
socket: 0
}
}).on('timeout', function(type) {
assert.strictEqual(type, 'response');
call.abort();
}).on('error', function(err) {
assert(err);
assert.strictEqual(err.message, 'socket hang up');
assert.strictEqual(err.reason, 'user');
done();
}).end();
});


test('socket timeout', function(done) {
onrequest = function(request, response) {
response.end('pong');
};

var call = rail.call({
proto: 'http',
host: 'github.com',
port: 55555,
timeout: {
response: 0
}
}).on('timeout', function(type) {
assert.strictEqual(type, 'socket');
call.abort();
}).on('error', function(err) {
assert(err);
assert.strictEqual(err.message, 'socket hang up');
assert.strictEqual(err.reason, 'user');
done();
}).end();
Expand Down
63 changes: 63 additions & 0 deletions test/test-public-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,67 @@ suite('public-api', function() {
}
}, function() {});
});


test('call.__intercept "interceptor should be a function"', function() {
var client = rail();
var call = client.call();

assert.throws(function() {
call.__intercept('response');
}, TypeError, 'interceptor should be a function');
});


test('call.abort "Not connected"', function(done) {
var client = rail();
var call = client.call();
assert(call.__request());

call.once('error', function(err) {
assert(err);
assert(err.message, 'Not connected');
done();
});

call.abort();
call.abort();
call.end();
});


test('call.__request "No configuration available"', function(done) {
var client = rail();
var call = client.call();

call.once('error', function(err) {
assert(err);
assert(err.message, 'No configuration available');
done();
});

++call._pointer;
call.__request();
});

test('call._urlToOptions', function() {
var client = rail();
var call = client.call();

var options = call._urlToOptions({
request: {
method: 'POST'
}
}, 'http://github.com');

assert.deepEqual(options, {
proto: 'http',
request: {
method: 'POST',
host: 'github.com',
path: '/',
port: null
}
});
});
});

0 comments on commit 74e5eb2

Please sign in to comment.