I'm attempting to use tape to test an API built with restify. The issue I'm having is that the tests don't complete until some "timeout" or something occurs. The test suite just hangs. Here's a simple test I'm using:
var test = require('tape');
var restify = require('restify');
var client = restify.createJsonClient({url: 'http://localhost:9000'});
test('GET /events/foo is 401 w/o auth', function(t) {
client.get('/events/foo', function(err, req, res, obj) {
t.equal(res.statusCode, 401);
t.end();
});
});
What am I missing or doing wrong?
Turns out the problem is because restify clients use keepalive by default. It can be disabled by setting agent: false
upon construction or calling client.close
when finished.