Skip to content
This repository has been archived by the owner on Jun 11, 2024. It is now read-only.

Refactor /peers endpoint to use swagger runner interface - Closes #925 #944

Merged
merged 13 commits into from
Nov 9, 2017

Conversation

nazarhussain
Copy link
Contributor

Closes: #925
Parent: #899

@karmacoma karmacoma changed the title Swagger baed /peers endpoint - Closes #925 Swagger based /peers endpoint - Closes #925 Nov 7, 2017
@karmacoma karmacoma requested review from MaciejBaj and Isabello and removed request for MaciejBaj November 8, 2017 19:50
};

// Remove filters with null values
filters = _.pickBy(filters, function (v, k) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

k is unused

Copy link
Contributor Author

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.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

return !(v === undefined || v === null);
});

modules.peers.shared.getPeers(filters, function (err, data) {
Copy link
Contributor

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?

Copy link
Contributor Author

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.

#949

});
}
} else {
console.log('not a swagger operation, will not validate response');
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Capital letter please

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

wsPort:
name: wsPort
in: query
description: wsPort for the node or delegate
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Web socket port ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

version:
name: version
in: query
description: Version of the lisk
Copy link
Contributor

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

Copy link
Contributor Author

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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable duplicated with wsServer

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done. #950

@@ -64,4 +64,4 @@ var wsServer = {
}
};

module.exports = wsServer;
module.exports = wsServer;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Empty line missing

Copy link
Contributor Author

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');
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

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();
Copy link
Contributor

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.

Copy link
Contributor Author

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.

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 () {
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

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);
Copy link
Contributor

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.

Copy link
Contributor Author

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');
Copy link
Contributor

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');
Copy link
Contributor

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.

}

/**
* Start the socket server instance. It will start the server as well an instance of the client.
Copy link
Contributor

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@@ -35,7 +35,7 @@ describe('GET /node', function () {
});

it('should return a result containing version = "0.0.0a"', function () {
Copy link
Contributor

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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

casing here.

@karmacoma karmacoma merged commit 5cf2aa5 into 1.0.0 Nov 9, 2017
@karmacoma karmacoma deleted the 925-swagger-peers branch November 9, 2017 17:41
@nazarhussain nazarhussain restored the 925-swagger-peers branch November 10, 2017 09:23
@karmacoma karmacoma deleted the 925-swagger-peers branch November 14, 2017 20:47
@karmacoma karmacoma changed the title Swagger based /peers endpoint - Closes #925 Refactor /peers endpoint to use swagger runner interface - Closes #925 Nov 15, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants