-
Notifications
You must be signed in to change notification settings - Fork 457
Refactor /peers endpoint to use swagger runner interface - Closes #925 #944
Conversation
c8acb5a
to
a701508
Compare
3ee3094
to
a944492
Compare
api/controllers/peers.js
Outdated
}; | ||
|
||
// Remove filters with null values | ||
filters = _.pickBy(filters, function (v, k) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k is unused
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's the signature of the method, while literately over key/value pair. But I only need value here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know, that's why the suggestion to remove it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
api/controllers/peers.js
Outdated
return !(v === undefined || v === null); | ||
}); | ||
|
||
modules.peers.shared.getPeers(filters, function (err, data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What if err will be received here? Don't we want to return INTERNAL_SERVER_ERROR in this case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had introduced error handling structure in other PR, when will be merged, will updated these endpoints to use same pattern.
}); | ||
} | ||
} else { | ||
console.log('not a swagger operation, will not validate response'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about using logger here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Two reasons left here. Can't find any way to pass our application scope logger down to individual pipe definition. And secondly this condition is never going to meet, as all our endpoints will have swagger based operation defined in yml. So I didn't invest more time to invent a way to pass our variables to pipe definition.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't allow console logs in production, so this will never be seen anyways. ESLINT might get mad as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
modules/peers.js
Outdated
/** | ||
* Utility method to get peers | ||
* | ||
* @param {object} parameters - Object of all parameters |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Capital letter please
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
schema/swagger.yml
Outdated
wsPort: | ||
name: wsPort | ||
in: query | ||
description: wsPort for the node or delegate |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Web socket port ...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
schema/swagger.yml
Outdated
version: | ||
name: version | ||
in: query | ||
description: Version of the lisk |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lisk version run by node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
var WAMPServer = require('wamp-socket-cluster/WAMPServer'); | ||
var testConfig = require('../config.json'); | ||
|
||
var necessaryRPCEndpoints = { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Variable duplicated with wsServer
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since later we will refactor and remove wsServer
file completely and move to wsServerMaster
. So didn't introduced a new dependency here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, please log the issue then.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done. #950
test/common/wsServer.js
Outdated
@@ -64,4 +64,4 @@ var wsServer = { | |||
} | |||
}; | |||
|
|||
module.exports = wsServer; | |||
module.exports = wsServer; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Empty line missing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
'use strict'; | ||
|
||
var ChildProcess = require('child_process'); | ||
var path = require('path'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
WS server running on separate process covers functionality of the same process wsServer - I think the logic should be reused and wsServer file removed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The dependent tests are complex and have redundant use of wsServer
. Already spent more than hour with you to pass ws-functional tests with new process. I used wsServerMaster
only where appropriate right now. Refactoring all existing usage, may be out of scope for this PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Another PR can do that refactoring.
expect(code).equal(failureCodes.INVALID_HEADERS); | ||
expect(description).contain('Missing required property'); | ||
done(); | ||
}); | ||
}}).start(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in the first part of the test we are using new approach relying on WSClient
with the handler (disconnect) passed into to verify if the WS connection succeeds or fails. In the with valid headers
section, we are using existing approach using functions connect
and then expectConnect
.
Please choose one and apply in both sections.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Had already spent hour with you. Unless we resolve the socket-hangup issue its not feasible to move those complex test cases. Once we have connection id on client side, all tests will be refactored well. Using a good approach where possible for now, is a good approach. Please suggest.
test/functional/http/get/peers.js
Outdated
node.expect(res.body).to.have.property('peers').that.is.an('array'); | ||
node.expect(res.body.peers.length).to.be.at.most(limit); | ||
done(); | ||
it('using sort = "version:asc" should be ok', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Change should be ok
to should return results in ascending / descending
order.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
test/functional/http/get/peers.js
Outdated
it('using sort = "version:desc" should be ok', function () { | ||
return peersEndpoint.makeRequest({sort: 'version:desc'}, 200) | ||
.then(function (res) { | ||
_.orderBy(_.clone(res.body.peers), ['version'], ['desc']).should.be.eql(res.body.peers); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the rest of files to test a proper sort order we are using construction with: _(res.body.peers).map('version').sort().value()
with optional reverse()
.
Please apply it to the file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
}); | ||
} | ||
} else { | ||
console.log('not a swagger operation, will not validate response'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't allow console logs in production, so this will never be seen anyways. ESLINT might get mad as well.
'use strict'; | ||
|
||
var ChildProcess = require('child_process'); | ||
var path = require('path'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. Another PR can do that refactoring.
test/common/wsServerMaster.js
Outdated
} | ||
|
||
/** | ||
* Start the socket server instance. It will start the server as well an instance of the client. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Start the socket server master instance. It will start the server and an instance of the client.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
test/functional/http/get/node.js
Outdated
@@ -35,7 +35,7 @@ describe('GET /node', function () { | |||
}); | |||
|
|||
it('should return a result containing version = "0.0.0a"', function () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should say 0.0.1 if this is where we are going with the config file.
@@ -12,6 +12,7 @@ var scClient = require('socketcluster-client'); | |||
var testConfig = require('../../config.json'); | |||
var ws = require('../../common/wsCommunication'); | |||
var wsServer = require('../../common/wsServer'); | |||
var WSClient = require('../../common/wsClient'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
casing here.
6b0ae37
to
970d570
Compare
Closes: #925
Parent: #899