Its not a node thing, it's how your application and supertest works. since your just pass the app to supertest and never calls listen in your test yourself, supertest does it for you and binds your server on random port. in your /test action you do a get request against another action and assume the right PORT in environment. but this port is different from the port supertest uses for the testrun. this is why your http.get fails. its the wrong port.
how you can fix this? the dirty variant is to determine the currently used port as supertest does here
https://github.com/visionmedia/supertest/blob/master/lib/test.js#L57-L62but the better solution is to not to http.get yourselfes actions. Unless you have verry unusual infrastructural considerations, its just inefficient and, as you can see, errorprone. if your ap is a single mashine thing, then just call the function, you passed as action:
load('application');
function getTest(cb) {
var obj = {success: true, data: 'blah'};
if(cb) return cb(null,obj)
else return send(obj);
}
action('getTest',getTest);
action(function show(data) {
var http = require('http');
var options = {
path: '/getTest',
port: process.env.PORT // without this, http fails because default port is 80
};
getTest( function(err, res) {
//do your thing
});
});
if you want to loadballance this, then use load ballancers, cluster or apache/nginx etc.
so far my opinion.