Skip to content

Commit

Permalink
Merge pull request #43 from snyk/fix/connection-status
Browse files Browse the repository at this point in the history
fix: dedicated connection-status endpoint
  • Loading branch information
gjvis authored Jun 9, 2017
2 parents 74c0020 + 8da71e4 commit dc6eec0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
3 changes: 1 addition & 2 deletions lib/server/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ module.exports = ({ config = {}, port = null, filters = {} }) => {
config,
});

// before the `app.all('/broker/:id/*'` route
app.get('/broker/:id', (req, res) => {
app.get('/connection-status/:id', (req, res) => {
const id = req.params.id;

if (connections.has(id)) {
Expand Down
16 changes: 8 additions & 8 deletions test/functional/healthcheck.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ test('proxy requests originating from behind the broker client', t => {
t.plan(6);

const serverHealth = `http://localhost:${serverPort}/healthcheck`;
const serverClientHealth = `http://localhost:${serverPort}/` +
`broker/${BROKER_TOKEN}`;
const connectionStatus = `http://localhost:${serverPort}/` +
`connection-status/${BROKER_TOKEN}`;
const clientHealth = `http://localhost:${clientPort}/healthcheck`;
t.test('server healthcheck', t => {
request({url: serverHealth, json: true }, (err, res) => {
Expand All @@ -60,8 +60,8 @@ test('proxy requests originating from behind the broker client', t => {
});
});

t.test('serve client-health with connected client', t => {
request({url: serverClientHealth, json: true }, (err, res) => {
t.test('check connection-status with connected client', t => {
request({url: connectionStatus, json: true }, (err, res) => {
if (err) { return t.threw(err); }

t.equal(res.statusCode, 200, '200 statusCode');
Expand All @@ -70,10 +70,10 @@ test('proxy requests originating from behind the broker client', t => {
});
});

t.test('server client-health after client disconnected', t => {
t.test('check connection-status after client disconnected', t => {
client.close();
setTimeout(() => {
request({url: serverClientHealth, json: true }, (err, res) => {
request({url: connectionStatus, json: true }, (err, res) => {
if (err) { return t.threw(err); }

t.equal(res.statusCode, 404, '404 statusCode');
Expand All @@ -82,10 +82,10 @@ test('proxy requests originating from behind the broker client', t => {
}, 100);
});

t.test('server client-health after client re-connected', t => {
t.test('check connection-status after client re-connected', t => {
client = app.main({ port: clientPort });
setTimeout(() => {
request({url: serverClientHealth, json: true }, (err, res) => {
request({url: connectionStatus, json: true }, (err, res) => {
if (err) { return t.threw(err); }

t.equal(res.statusCode, 200, '200 statusCode');
Expand Down

0 comments on commit dc6eec0

Please sign in to comment.